Skip to content

Commit 73c6060

Browse files
committed
build: cd wip
1 parent 787a5a5 commit 73c6060

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

.github/workflows/cd.yml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ on:
55
push:
66
branches:
77
- 'main'
8+
- 'staging'
89
tags:
910
- 'v*'
1011
pull_request:
1112
branches:
1213
- 'main'
14+
- 'staging'
1315

1416
jobs:
1517
build:
@@ -50,21 +52,41 @@ jobs:
5052

5153
deploy:
5254
runs-on: ubuntu-latest
55+
permissions:
56+
contents: read
57+
packages: read
5358
needs: build
54-
if: github.ref == 'refs/heads/main'
59+
strategy:
60+
matrix:
61+
include:
62+
- environment: staging
63+
branch: staging
64+
target_path: "~/staging.mapdb.cncnet.org"
65+
compose_file: "docker-compose.prod.yml"
66+
nginx_conf: "docker/nginx.prod.conf"
67+
# disabled for now
68+
# - environment: production
69+
# branch: main
70+
# target_path: "~/prod2.mapdb.cncnet.org"
71+
# compose_file: "docker-compose.prod.yml"
72+
# nginx_conf: "docker/nginx.prod.conf"
5573

5674
steps:
75+
- name: "Exit if not matching branch"
76+
if: github.ref != format('refs/heads/{0}', matrix.branch)
77+
run: echo "Not target branch for this deployment. Skipping..." && exit 0
78+
5779
- name: Checkout repository
5880
uses: actions/checkout@v4
5981

60-
- name: Copy docker-compose file over ssh
82+
- name: Copy docker-compose and nginx config over ssh
6183
uses: appleboy/[email protected]
6284
with:
6385
host: ${{ secrets.SSH_HOST }}
6486
username: ${{ secrets.SSH_USER }}
6587
key: ${{ secrets.SSH_PRIVATE_KEY }}
66-
source: "docker-compose.prod.yml"
67-
target: "~/staging.mapdb.cncnet.org"
88+
source: "${{ matrix.compose_file }},${{ matrix.nginx_conf }}"
89+
target: "${{ matrix.target_path }}"
6890

6991
- name: SSH into server and deploy
7092
uses: appleboy/[email protected]
@@ -73,8 +95,8 @@ jobs:
7395
username: ${{ secrets.SSH_USER }}
7496
key: ${{ secrets.SSH_PRIVATE_KEY }}
7597
script: |
76-
cd ~/staging.mapdb.cncnet.org
98+
cd ${{ matrix.target_path }}
7799
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
78-
docker compose -f docker-compose.prod.yml pull
79-
docker compose -f docker-compose.prod.yml down
80-
docker compose -f docker-compose.prod.yml up -d
100+
docker compose -f ${{ matrix.compose_file }} pull
101+
docker compose -f ${{ matrix.compose_file }} down
102+
docker compose -f ${{ matrix.compose_file }} up -d

docker/nginx.prod.conf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
user nginx;
2+
worker_processes 4;
3+
pid /var/run/nginx.pid;
4+
5+
events {
6+
worker_connections 1024;
7+
}
8+
9+
http {
10+
server {
11+
listen 80;
12+
13+
# Serve static files: js, static images, etc.
14+
location /static/ {
15+
alias /usr/share/nginx/html/static/; # The nginx container's mounted volume.
16+
expires 30d;
17+
add_header Cache-Control public;
18+
}
19+
20+
# Serve user uploaded files
21+
location /silo/ {
22+
alias /usr/share/nginx/html/silo/; # The container's mounted volume.
23+
}
24+
25+
# Proxy requests to the Django app running in gunicorn
26+
location / {
27+
proxy_pass http://django:8000; # The Django app is exposed on the `django` container on port 8000
28+
proxy_set_header Host $host;
29+
proxy_set_header X-Real-IP $remote_addr;
30+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31+
proxy_set_header X-Forwarded-Proto $scheme;
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)