From ffb1f015873263d5385a6eeced7e9177cfcac2f6 Mon Sep 17 00:00:00 2001 From: proffapt Date: Thu, 13 Jun 2024 18:25:52 +0530 Subject: [PATCH] feat: deployment pipeline --- .github/workflows/deploy.yaml | 74 +++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..dd5181b --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,74 @@ +name: Continuous Deployment Pipeline + +on: + push: + branches: + - "main" + paths-ignore: + - "**.md" + - "LICENSE" + +jobs: + push: + name: Push Stage + runs-on: ubuntu-latest + + steps: + - name: Sync local repo with remote repo + uses: appleboy/ssh-action@master + env: + PROJECT_DIR: ${{ secrets.PROJECT_DIR }} + with: + host: ${{ secrets.SSH_HOSTNAME }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} + envs: PROJECT_DIR + script_stop: true + script: | + cd "${PROJECT_DIR}/" + sudo git fetch origin + sudo git reset --hard origin/main + + build: + name: Build Stage + needs: push + runs-on: ubuntu-latest + + steps: + - name: Build the latest container(s) + uses: appleboy/ssh-action@master + env: + PROJECT_DIR: ${{ secrets.PROJECT_DIR }} + with: + host: ${{ secrets.SSH_HOSTNAME }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} + envs: PROJECT_DIR + script_stop: true + script: | + cd "${PROJECT_DIR}/" + sudo docker compose build + + deploy: + name: Deploy Stage + needs: [push, build] + runs-on: ubuntu-latest + + steps: + - name: Deploy the latest build(s) + uses: appleboy/ssh-action@master + env: + PROJECT_DIR: ${{ secrets.PROJECT_DIR }} + with: + host: ${{ secrets.SSH_HOSTNAME }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} + envs: PROJECT_DIR + script_stop: true + script: | + cd "${PROJECT_DIR}/" + sudo docker compose down + sudo docker compose up -d