generated from metakgp/README.md
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continuous Deployment Pipeline (#21)
* feat: cd pipeline * fix: git and docker require sudo * feat: error handling; exhaustive logging * feat: private key passphrase * fix: iqps-go -> iqps * feat: better CD pipeline :) * feat: change name for the workflow * fix: error log typo Co-authored-by: Chirag Ghosh <[email protected]> --------- Co-authored-by: Chirag Ghosh <[email protected]>
- Loading branch information
1 parent
03c3166
commit e78f43c
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Continuous Deployment for backend | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
|
||
jobs: | ||
pull: | ||
name: Pull Stage | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Sync with remote repository | ||
uses: appleboy/ssh-action@master | ||
env: | ||
IQPS_DIR: ${{ secrets.IQPS_DIR }} | ||
with: | ||
host: ${{ secrets.HOSTNAME }} | ||
username: ${{ secrets.USERNAME }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
passphrase: ${{ secrets.PASSPHRASE }} | ||
envs: IQPS_DIR | ||
script: | | ||
cd "$IQPS_DIR" >/dev/null 2>&1 || { | ||
echo "[ERROR]: Failed to cd into 'iqps' directory" | ||
exit 1 | ||
} | ||
sudo git fetch origin || { | ||
echo "[ERROR]: Failed to fetch origin" | ||
exit 1 | ||
} | ||
sudo git reset --hard origin/main || { | ||
echo "[ERROR]: Failed to sync with remote repo" | ||
exit 1 | ||
} | ||
build: | ||
name: Build Stage | ||
needs: pull | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Build the latest docker container | ||
uses: appleboy/ssh-action@master | ||
env: | ||
IQPS_DIR: ${{ secrets.IQPS_DIR }} | ||
with: | ||
host: ${{ secrets.HOSTNAME }} | ||
username: ${{ secrets.USERNAME }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
passphrase: ${{ secrets.PASSPHRASE }} | ||
envs: IQPS_DIR | ||
script: | | ||
cd "${IQPS_DIR}/backend/" >/dev/null 2>&1 || { | ||
echo "[ERROR]: Failed to cd into 'backend' directory" | ||
exit 1 | ||
} | ||
sudo docker compose build || { | ||
echo "[ERROR]: Build stage failed" | ||
exit 1 | ||
} | ||
deploy: | ||
name: Deploy Stage | ||
needs: [pull, build] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Deploy the latest build | ||
uses: appleboy/ssh-action@master | ||
env: | ||
IQPS_DIR: ${{ secrets.IQPS_DIR }} | ||
with: | ||
host: ${{ secrets.HOSTNAME }} | ||
username: ${{ secrets.USERNAME }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
passphrase: ${{ secrets.PASSPHRASE }} | ||
envs: IQPS_DIR | ||
script: | | ||
cd "${IQPS_DIR}/backend/" >/dev/null 2>&1 || { | ||
echo "[ERROR]: Failed to cd into 'backend' directory" | ||
exit 1 | ||
} | ||
sudo docker compose down || { | ||
echo "[ERROR]: Failed to takedown the previous deployment" | ||
exit 1 | ||
} | ||
sudo docker compose up -d || { | ||
echo "[ERROR]: Failed to deploy the latest version" | ||
exit 1 | ||
} |