Skip to content

Split Tag Management into Events,Locations & Scheme_Plans for better … #5

Split Tag Management into Events,Locations & Scheme_Plans for better …

Split Tag Management into Events,Locations & Scheme_Plans for better … #5

#TEST123
name: Deploy Application For Production
on:
push:
branches:
- main
jobs:
create-deployment-artifacts:
name: Create deployment artifacts
runs-on: ubuntu-latest
outputs:
deployment-matrix: ${{ steps.export-deployment-matrix.outputs.deployment-matrix }}
steps:
- uses: actions/checkout@v3
- name: Configure PHP 8.1
uses: shivammathur/setup-php@master
with:
php-version: 8.1
extensions: mbstring, ctype, fileinfo, openssl, PDO, bcmath, json, tokenizer, xml
- name: Composer install
run: composer install --no-dev --no-interaction --prefer-dist
- name: Compile CSS and Javascript
run: |
npm install
npm run build
- name: Create deployment artifact
env:
GITHUB_SHA: ${{ github.sha }}
run: tar -czf "${GITHUB_SHA}".tar.gz --exclude=*.git --exclude=node_modules --exclude=tests *
- name: Store artifact for distribution
uses: actions/upload-artifact@v3
with:
name: app-build
path: ${{ github.sha }}.tar.gz
- name: Export deployment matrix
id: export-deployment-matrix
run: |
JSON="$(cat ./development-server-config.json)"
JSON="${JSON//'%'/'%25'}"
JSON="${JSON//$'\n'/'%0A'}"
JSON="${JSON//$'\r'/'%0D'}"
echo "::set-output name=deployment-matrix::$JSON"
prepare-release-on-servers:
name: "${{ matrix.server.name }}: Prepare release"
runs-on: ubuntu-latest
needs: create-deployment-artifacts
strategy:
matrix:
server: ${{ fromJson(needs.create-deployment-artifacts.outputs.deployment-matrix) }}
steps:
- uses: actions/download-artifact@v3
with:
name: app-build
- name: Upload
uses: appleboy/scp-action@master
with:
host: ${{ matrix.server.ip }}
username: ${{ matrix.server.username }}
key: ${{ secrets.BHAVIL_TEST_SERVER_SSH }}
port: ${{ matrix.server.port }}
source: ${{ github.sha }}.tar.gz
target: ${{ matrix.server.path }}/artifacts
- name: Extract archive and create directories
uses: appleboy/ssh-action@master
env:
GITHUB_SHA: ${{ github.sha }}
with:
host: ${{ matrix.server.ip }}
username: ${{ matrix.server.username }}
key: ${{ secrets.BHAVIL_TEST_SERVER_SSH }}
port: ${{ matrix.server.port }}
envs: GITHUB_SHA
script: |
sudo mkdir -p "${{ matrix.server.path }}/releases/${GITHUB_SHA}"
sudo chown -R ubuntu:ubuntu ${{ matrix.server.path }}/releases
sudo tar xzf ${{ matrix.server.path }}/artifacts/${GITHUB_SHA}.tar.gz -C "${{ matrix.server.path }}/releases/${GITHUB_SHA}"
sudo rm -rf ${{ matrix.server.path }}/releases/${GITHUB_SHA}/storage
sudo mkdir -p ${{ matrix.server.path }}/storage/{app,public,framework,logs}
sudo mkdir -p ${{ matrix.server.path }}/storage/framework/{cache,sessions,testing,views}
sudo chmod -R 0777 ${{ matrix.server.path }}/storage
sudo chown -R ubuntu:ubuntu ${{ matrix.server.path }}/storage
sudo chown -R www-data:www-data ${{ matrix.server.path }}/storage/framework
sudo chown -R www-data:www-data ${{ matrix.server.path }}/storage/framework
sudo chown -R www-data.www-data ${{ matrix.server.path }}/releases/${GITHUB_SHA}/bootstrap/cache
- name : Delete Artifacts
uses: geekyeggo/delete-artifact@v1
with:
name: app-build
failOnError: false
run-before-hooks:
name: "${{ matrix.server.name }}: Before hook"
runs-on: ubuntu-latest
needs: [ create-deployment-artifacts, prepare-release-on-servers ]
strategy:
matrix:
server: ${{ fromJson(needs.create-deployment-artifacts.outputs.deployment-matrix) }}
steps:
- name: Run before hooks
uses: appleboy/ssh-action@master
env:
GITHUB_SHA: ${{ github.sha }}
RELEASE_PATH: ${{ matrix.server.path }}/releases/${{ github.sha }}
ACTIVE_RELEASE_PATH: ${{ matrix.server.path }}/current
STORAGE_PATH: ${{ matrix.server.path }}/storage
BASE_PATH: ${{ matrix.server.path }}
with:
host: ${{ matrix.server.ip }}
username: ${{ matrix.server.username }}
key: ${{ secrets.BHAVIL_TEST_SERVER_SSH }}
port: ${{ matrix.server.port }}
envs: GITHUB_SHA,RELEASE_PATH,ACTIVE_RELEASE_PATH,STORAGE_PATH,BASE_PATH
script: |
${{ matrix.server.beforeHooks }}
activate-release:
name: "${{ matrix.server.name }}: Activate release"
runs-on: ubuntu-latest
needs: [ create-deployment-artifacts, prepare-release-on-servers, run-before-hooks ]
strategy:
matrix:
server: ${{ fromJson(needs.create-deployment-artifacts.outputs.deployment-matrix) }}
steps:
- name: Activate release
uses: appleboy/ssh-action@master
env:
GITHUB_SHA: ${{ github.sha }}
RELEASE_PATH: ${{ matrix.server.path }}/releases/${{ github.sha }}
ACTIVE_RELEASE_PATH: ${{ matrix.server.path }}/current
STORAGE_PATH: ${{ matrix.server.path }}/storage
BASE_PATH: ${{ matrix.server.path }}
LARAVEL_ENV: ${{ secrets.TESTING_ENV }}
with:
host: ${{ matrix.server.ip }}
username: ${{ matrix.server.username }}
key: ${{ secrets.BHAVIL_TEST_SERVER_SSH }}
port: ${{ matrix.server.port }}
envs: GITHUB_SHA,RELEASE_PATH,ACTIVE_RELEASE_PATH,STORAGE_PATH,BASE_PATH,ENV_PATH,LARAVEL_ENV
script: |
sudo printf "%s" "$LARAVEL_ENV" > "${BASE_PATH}/.env"
sudo ln -s -f ${BASE_PATH}/.env $RELEASE_PATH
sudo ln -s -f $STORAGE_PATH $RELEASE_PATH
sudo ln -s -n -f $RELEASE_PATH $ACTIVE_RELEASE_PATH
sudo service php8.1-fpm reload
sudo chown -R ubuntu:ubuntu $ACTIVE_RELEASE_PATH
cd ${ACTIVE_RELEASE_PATH}
sudo php artisan migrate --force
sudo php artisan cache:clear
sudo php artisan auth:clear-resets
sudo php artisan view:cache
sudo php artisan queue:restart
sudo php artisan optimize
sudo php artisan storage:link
sudo composer install --optimize-autoloader --no-dev
run-after-hooks:
name: "${{ matrix.server.name }}: After hook"
runs-on: ubuntu-latest
needs: [ create-deployment-artifacts, prepare-release-on-servers, run-before-hooks, activate-release ]
strategy:
matrix:
server: ${{ fromJson(needs.create-deployment-artifacts.outputs.deployment-matrix) }}
steps:
- name: Run after hooks
uses: appleboy/ssh-action@master
env:
GITHUB_SHA: ${{ github.sha }}
RELEASE_PATH: ${{ matrix.server.path }}/releases/${{ github.sha }}
ACTIVE_RELEASE_PATH: ${{ matrix.server.path }}/current
STORAGE_PATH: ${{ matrix.server.path }}/storage
BASE_PATH: ${{ matrix.server.path }}
with:
host: ${{ matrix.server.ip }}
username: ${{ matrix.server.username }}
key: ${{ secrets.BHAVIL_TEST_SERVER_SSH }}
port: ${{ matrix.server.port }}
envs: GITHUB_SHA,RELEASE_PATH,ACTIVE_RELEASE_PATH,STORAGE_PATH,BASE_PATH
script: |
${{ matrix.server.afterHooks }}
clean-up:
name: "${{ matrix.server.name }}: Clean up"
runs-on: ubuntu-latest
needs: [ create-deployment-artifacts, prepare-release-on-servers, run-before-hooks, activate-release, run-after-hooks ]
strategy:
matrix:
server: ${{ fromJson(needs.create-deployment-artifacts.outputs.deployment-matrix) }}
steps:
- name: Run after hooks
uses: appleboy/ssh-action@master
env:
RELEASES_PATH: ${{ matrix.server.path }}/releases
ARTIFACTS_PATH: ${{ matrix.server.path }}/artifacts
with:
host: ${{ matrix.server.ip }}
username: ${{ matrix.server.username }}
key: ${{ secrets.BHAVIL_TEST_SERVER_SSH }}
port: ${{ matrix.server.port }}
envs: RELEASES_PATH
script: |
cd $ARTIFACTS_PATH && sudo ls -t | tail -n +3 | xargs rm -rf
cd $RELEASES_PATH && sudo ls -t -1 | tail -n +3 | xargs rm -rf