Skip to content

Commit 42a5d71

Browse files
feat: deployment workflow
1 parent 7105c7a commit 42a5d71

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

.github/workflows/deploy.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Continuous Deployment Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
paths:
8+
- "backend/**"
9+
- ".github/workflows/deploy.yaml"
10+
11+
jobs:
12+
dockerhub:
13+
name: Publish Docker Image(s) to Dockerhub
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v3
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Login to Docker Hub
27+
uses: docker/login-action@v3
28+
with:
29+
username: ${{ secrets.DOCKERHUB_USERNAME }}
30+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
31+
32+
- name: Cache Docker layers for Maintos
33+
uses: actions/cache@v3
34+
with:
35+
path: /tmp/.buildx-cache-maintos-backend
36+
key: ${{ runner.os }}-buildx-maintos-backend-${{ github.sha }}
37+
restore-keys: |
38+
${{ runner.os }}-buildx-maintos-backend-
39+
40+
- name: Build & Push Maintos Backend
41+
uses: docker/build-push-action@v5
42+
with:
43+
context: ./backend/
44+
push: true
45+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/maintos-backend:latest
46+
cache-from: type=local,src=/tmp/.buildx-cache-maintos-backend
47+
cache-to: type=local,dest=/tmp/.buildx-cache-maintos-backend-new,mode=max
48+
49+
- name: Move Maintos cache
50+
run: |
51+
rm -rf /tmp/.buildx-cache-maintos-backend
52+
mv /tmp/.buildx-cache-maintos-backend-new /tmp/.buildx-cache-maintos-backend
53+
54+
push:
55+
name: Push Code Stage
56+
needs: dockerhub
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- name: Sync local repo with remote repo
61+
uses: appleboy/ssh-action@master
62+
env:
63+
PROJECT_DIR: ${{ secrets.PROJECT_DIR }}
64+
with:
65+
host: ${{ secrets.SSH_HOSTNAME }}
66+
username: ${{ secrets.SSH_USERNAME }}
67+
key: ${{ secrets.SSH_PRIVATE_KEY }}
68+
passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }}
69+
envs: PROJECT_DIR
70+
script_stop: true
71+
script: |
72+
cd "${PROJECT_DIR}/backend/"
73+
sudo git fetch origin
74+
sudo git reset --hard origin/main
75+
76+
pull:
77+
name: Pull Image Stage
78+
needs: push
79+
runs-on: ubuntu-latest
80+
81+
steps:
82+
- name: Pull the latest images(s)
83+
uses: appleboy/ssh-action@master
84+
env:
85+
PROJECT_DIR: ${{ secrets.PROJECT_DIR }}
86+
with:
87+
host: ${{ secrets.SSH_HOSTNAME }}
88+
username: ${{ secrets.SSH_USERNAME }}
89+
key: ${{ secrets.SSH_PRIVATE_KEY }}
90+
passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }}
91+
envs: PROJECT_DIR
92+
script_stop: true
93+
script: |
94+
cd "${PROJECT_DIR}/backend/"
95+
sudo docker compose pull
96+
97+
deploy:
98+
name: Deploy Stage
99+
needs: pull
100+
runs-on: ubuntu-latest
101+
102+
steps:
103+
- name: Deploy the latest build(s)
104+
uses: appleboy/ssh-action@master
105+
env:
106+
PROJECT_DIR: ${{ secrets.PROJECT_DIR }}
107+
with:
108+
host: ${{ secrets.SSH_HOSTNAME }}
109+
username: ${{ secrets.SSH_USERNAME }}
110+
key: ${{ secrets.SSH_PRIVATE_KEY }}
111+
passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }}
112+
envs: PROJECT_DIR
113+
script_stop: true
114+
script: |
115+
cd "${PROJECT_DIR}/backend/"
116+
sudo docker compose down
117+
sudo docker compose up -d

backend/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
2-
iqps-backend:
2+
maintos-backend:
33
image: metakgporg/maintos-backend
44
container_name: maintos-backend
55
build: .

backend/src/routing/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::env::EnvVars;
1616
mod handlers;
1717
mod middleware;
1818

19-
/// Returns the Axum router for IQPS
19+
/// Returns the Axum router for maintos
2020
pub fn get_router(env_vars: &EnvVars, docker: Arc<Docker>) -> axum::Router {
2121
let state = Arc::new(RouterState {
2222
env_vars: env_vars.clone(),

0 commit comments

Comments
 (0)