Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous Deployment Pipeline #21

Merged
merged 8 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Deploy on push

on:
push:
branches: ["main"]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: SSH & execute the deploy script
uses: appleboy/ssh-action@master
env:
SCRIPTS_DIR: ${{ secrets.SCRIPTS_DIR }}
with:
host: ${{ secrets.HOSTNAME }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
envs: SCRIPTS_DIR
script: eval "${SCRIPTS_DIR}/continuous-deployment.sh"
30 changes: 30 additions & 0 deletions backend/scripts/continuous-deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

## Change the directory to where the script resides
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
cd "$SCRIPT_DIR" >/dev/null 2>&1 ||
{ echo "[ERROR]: Failed to cd into 'scripts' directory" && exit 1; }

## Move to root direcotry of the project - iqps
proffapt marked this conversation as resolved.
Show resolved Hide resolved
cd ../../ >/dev/null 2>&1 ||
{ echo "[ERROR]: Failed to cd into 'iqps' directory" && exit 1; }

### Sync with remote repository
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; }

## Move to backend subdirectory
cd backend/ >/dev/null 2>&1 ||
{ echo "[ERROR]: Failed to cd into 'backend' directory" && exit 1; }

### Build Stage
sudo docker compose build ||
{ echo "[ERROR]: Build stage failed" && exit 1; }

### Deploy Stage
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; }