Skip to content

Commit 714e0ae

Browse files
infra(develop): creates CI/CD pipeline for staging environment
- Adds a GitHub Actions workflow to automate the deployment of the staging environment whenever changes are pushed to the develop branch. - Updates the Makefile to include commands for deploying to staging. - Creates a new Docker Compose file for the staging environment and modifies the existing one to accommodate the new setup.
1 parent d26181a commit 714e0ae

5 files changed

Lines changed: 88 additions & 7 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Deploy Staging
2+
on:
3+
push:
4+
branches: [ "develop" ]
5+
6+
env:
7+
REGISTRY: ghcr.io
8+
IMAGE_NAME: ${{ github.repository_owner }}/syncdesk-api
9+
10+
jobs:
11+
build-and-push:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Log in to the Container registry
22+
uses: docker/login-action@v3
23+
with:
24+
registry: ${{ env.REGISTRY }}
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Build and push Docker image
29+
uses: docker/build-push-action@v5
30+
with:
31+
context: .
32+
file: deploy/Dockerfile
33+
push: true
34+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:staging
35+
36+
deploy:
37+
needs: build-and-push
38+
runs-on: ubuntu-latest
39+
permissions:
40+
contents: read
41+
packages: read
42+
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
47+
- name: Copy compose files to Droplet
48+
uses: appleboy/scp-action@v0.1.7
49+
with:
50+
host: ${{ secrets.DROPLET_HOST }}
51+
username: ${{ secrets.SSH_USERNAME }}
52+
key: ${{ secrets.SSH_PRIVATE_KEY }}
53+
target: /opt/syncdesk
54+
source: docker-compose.yaml,deploy/docker-compose.staging.yaml,deploy/prometheus,deploy/alertmanager,deploy/loki,deploy/promtail,deploy/grafana
55+
56+
- name: Deploy to Droplet
57+
uses: appleboy/ssh-action@v1.0.3
58+
with:
59+
host: ${{ secrets.DROPLET_HOST }}
60+
username: ${{ secrets.SSH_USERNAME }}
61+
key: ${{ secrets.SSH_PRIVATE_KEY }}
62+
script: |
63+
cd /opt/syncdesk
64+
docker compose -f docker-compose.yaml -f deploy/docker-compose.staging.yaml pull api
65+
docker compose -f docker-compose.yaml -f deploy/docker-compose.staging.yaml up -d --force-recreate

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
.PHONY: install run dev lint format typecheck test seed migrate makemigration pre-commit
1+
.PHONY: install run dev lint format typecheck test seed migrate makemigration pre-commit up down logs
2+
23

34
install:
45
poetry install
@@ -41,3 +42,12 @@ pre-commit:
4142
poetry run mypy app/
4243
poetry run bandit -c pyproject.toml -r app/
4344
poetry run pytest
45+
46+
up:
47+
docker compose up --build
48+
49+
down:
50+
docker compose down
51+
52+
logs:
53+
docker compose logs -f

deploy/docker-compose.staging.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
api:
3+
image: ghcr.io/titus-system/syncdesk-api:staging

docker-compose.override.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
api:
3+
build:
4+
context: .
5+
dockerfile: deploy/Dockerfile
6+
volumes:
7+
- .:/app
8+
environment:
9+
UVICORN_RELOAD: "true"

docker-compose.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,15 @@ services:
4141
start_period: 10s
4242

4343
api:
44-
build:
45-
context: .
46-
dockerfile: deploy/Dockerfile
4744
container_name: syncdesk_api
4845
restart: unless-stopped
4946
env_file:
5047
- .env
5148
environment:
5249
POSTGRES_HOST: db
5350
MONGO_HOST: mongo
54-
UVICORN_RELOAD: "true"
5551
ports:
5652
- "8000:8000"
57-
volumes:
58-
- .:/app
5953
depends_on:
6054
db:
6155
condition: service_healthy

0 commit comments

Comments
 (0)