Merge #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Deploy Pipeline # The name of the workflow | |
on: | |
pull_request: | |
types: | |
- closed | |
workflow_dispatch: | |
env: | |
BRANCH: ${{ vars.BRANCH_DEPLOYMENT }} | |
PROJECT_SSH_FOLDER: ${{ vars.SSH_FOLDER }} | |
REGISTRY: ghcr.io | |
PROD_NAME: ${{ vars.PROD_NAME }} | |
LABEL_SERVER: backend | |
LABEL_CLIENT: frontend-client | |
LABEL_ADMIN: frontend-admin | |
jobs: | |
deploy: | |
name: 'Publish Application' | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Run deploy on SSH' | |
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == ${{ env.BRANCH }} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ vars.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
port: ${{ vars.SSH_PORT }} | |
script: | | |
echo ${{ secrets.SSH_PASSWORD }} | sudo -S aa-remove-unknown | |
cd ${{ env.PROJECT_SSH_FOLDER }} | |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | |
if [[ "${{ contains(github.event.pull_request.labels.*.name, env.LABEL_SERVER) }}" == "true" ]]; then | |
docker rm $(docker stop $(docker ps -a -q --filter ancestor=${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PROD_NAME }}-server:latest )) | |
docker rmi ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PROD_NAME }}-server:latest | |
fi | |
if [[ "${{ contains(github.event.pull_request.labels.*.name, env.LABEL_CLIENT) }}" == "true" ]]; then | |
docker rm $(docker stop $(docker ps -a -q --filter ancestor=${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PROD_NAME }}-client:latest )) | |
docker rmi ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PROD_NAME }}-client:latest | |
fi | |
if [[ "${{ contains(github.event.pull_request.labels.*.name, env.LABEL_ADMIN) }}" == "true" ]]; then | |
docker rm $(docker stop $(docker ps -a -q --filter ancestor=${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PROD_NAME }}-admin:latest )) | |
docker rmi ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PROD_NAME }}-admin:latest | |
fi | |
docker compose -f docker-compose.prod-ci.yml -p ${{ env.PROD_NAME }} pull | |
docker compose -f docker-compose.prod-ci.yml -p ${{ env.PROD_NAME }} up -d |