Skip to content

Commit d4fed88

Browse files
committedFeb 28, 2025
add prod deployment
1 parent 10636ce commit d4fed88

File tree

7 files changed

+170
-43
lines changed

7 files changed

+170
-43
lines changed
 

‎.github/workflows/build.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Build & Push Docker Image
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
environment:
8+
required: true
9+
type: string
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
environment: ${{ inputs.environment }}
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
19+
- name: Declare image's tag
20+
shell: bash
21+
run: |
22+
echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
23+
- name: Build
24+
uses: docker/build-push-action@v6
25+
with:
26+
context: .
27+
push: false
28+
tags: qmra:${{ env.sha_short }}
29+
load: true
30+
- name: Save
31+
run: docker save qmra > img.tar
32+
- name: Push
33+
uses: appleboy/scp-action@v0.1.7
34+
with:
35+
host: ${{ secrets.DEPLOY_HOST }}
36+
username: ${{ secrets.DEPLOY_USER }}
37+
key: ${{ secrets.DEPLOY_SERVER_SSH_KEY }}
38+
source: "img.tar"
39+
target: ${{ secrets.DEPLOY_PATH }}

‎.github/workflows/ci.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: CICD Pipeline
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
name: test app
12+
uses: ./.github/workflows/test.yaml
13+
build-dev:
14+
needs: test
15+
name: build-dev
16+
uses: ./.github/workflow/build.yaml
17+
with:
18+
environment: dev
19+
deploy-dev:
20+
needs: build-dev
21+
name: deploy-dev
22+
uses: ./.github/workflow/deploy.yaml
23+
with:
24+
environment: dev
25+
build-prod:
26+
needs: test
27+
name: build-prod
28+
uses: ./.github/workflow/build.yaml
29+
with:
30+
environment: prod
31+
deploy-prod:
32+
needs:
33+
- build-prod
34+
- deploy-dev
35+
name: deploy-prod
36+
uses: ./.github/workflow/deploy.yaml
37+
with:
38+
environment: prod

‎.github/workflows/deploy.yml

+7-42
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,16 @@
22
name: Deploy Django Application
33

44
on:
5-
push:
6-
branches:
7-
- main
5+
workflow_call:
6+
inputs:
7+
environment:
8+
required: true
9+
type: string
810
jobs:
9-
test:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v4
13-
- uses: actions/setup-python@v5
14-
with:
15-
python-version: '3.11'
16-
- name: Install dependencies
17-
run: pip install -r requirements.txt && pip install -r requirements.test.txt
18-
- name: Test
19-
run: python manage.py test
2011
deploy:
21-
needs: test
2212
runs-on: ubuntu-latest
23-
environment: dev
13+
environment: ${{ inputs.environment }}
2414
steps:
25-
- name: Checkout repository
26-
uses: actions/checkout@v2
27-
- name: Set up Docker Buildx
28-
uses: docker/setup-buildx-action@v3
29-
- name: Declare image's tag
30-
shell: bash
31-
run: |
32-
echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
33-
- name: Build
34-
uses: docker/build-push-action@v6
35-
with:
36-
context: .
37-
push: false
38-
tags: qmra:${{ env.sha_short }}
39-
load: true
40-
- name: Save
41-
run: docker save qmra > img.tar
42-
- name: Push
43-
uses: appleboy/scp-action@v0.1.7
44-
with:
45-
host: ${{ secrets.DEPLOY_HOST }}
46-
username: ${{ secrets.DEPLOY_USER }}
47-
key: ${{ secrets.DEPLOY_SERVER_SSH_KEY }}
48-
source: "img.tar"
49-
target: ${{ secrets.DEPLOY_PATH }}
5015
- name: Deploy
5116
uses: appleboy/ssh-action@v1.1.0
5217
with:
@@ -57,4 +22,4 @@ jobs:
5722
cd ${{ secrets.DEPLOY_PATH }} && git pull
5823
microk8s ctr image import img.tar && rm img.tar
5924
cd infra/helm
60-
microk8s helm upgrade qmra ./qmra -n qmra --set app_secret_key.value=${{ secrets.APP_SECRET_KEY }},image.tag=${{ env.sha_short }}
25+
microk8s helm upgrade -f ${{ inputs.environment }}.values.yaml qmra ./qmra -n qmra --set app_secret_key.value=${{ secrets.APP_SECRET_KEY }},image.tag=${{ env.sha_short }}

‎.github/workflows/test.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: Test Django Application
3+
4+
on:
5+
workflow_call:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: '3.11'
15+
- name: Install dependencies
16+
run: pip install -r requirements.txt && pip install -r requirements.test.txt
17+
- name: Test
18+
run: python manage.py test

‎infra/bootstrap-k8.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ adduser k8admin
66
usermod -aG sudo k8admin
77
su - k8admin
88

9-
sudo apt update && apt upgrade -y
9+
sudo apt update && sudo apt upgrade -y
1010

1111
# install microk8s
1212
sudo snap install microk8s --classic --channel=1.31
@@ -40,3 +40,13 @@ source .bash_aliases
4040
mk8 enable ingress cert-manager hostpath-storage metrics-server
4141
mk8 disable ha-cluster
4242
#observability dashboard hostpath-storage
43+
44+
# firewall settings:
45+
sudo ufw default deny incoming
46+
sudo ufw default allow outgoing
47+
sudo ufw allow ssh
48+
sudo ufw allow https
49+
#ufw allow http #necessary for certbot to obtain certificate
50+
sudo ufw enable
51+
# needed by mk8s hostpath-provisionner:
52+
sudo ufw default allow routed
File renamed without changes.

‎infra/helm/qmra/prod.values.yaml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Default values for app.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
5+
namespace: qmra
6+
domain: qmra.org
7+
monitoring_domain: monitoring.qmra.org
8+
replicaCount: 1
9+
10+
app_secret_key:
11+
secret_name: qmra-secret-key-secret
12+
value: Y21WaGJHeDVYM05sWTNKbGRGOTJZV3gxWlRFSwo=
13+
configmap_name: qmra-configmap
14+
15+
sqlite:
16+
mount_path: /var/lib/qmra/qmra.db
17+
hostpath: /var/lib/qmra/qmra.db
18+
19+
static:
20+
mount_path: /var/cache/qmra/static
21+
hostpath: /var/cache/qmra/static
22+
23+
image:
24+
repository: qmra
25+
tag: local
26+
pullPolicy: Never
27+
livenessProbe:
28+
httpGet:
29+
path: /health
30+
port: http
31+
readinessProbe:
32+
httpGet:
33+
path: /ready
34+
port: http
35+
resources:
36+
limits:
37+
cpu: 500m
38+
memory: 1Gi
39+
requests:
40+
cpu: 100m
41+
memory: 256Mi
42+
43+
ingress:
44+
tlsSecretName: tls-secret-key-ref
45+
46+
tls:
47+
acme_email: antoine.daurat@kompetenz-wasser.de
48+
49+
50+
podAnnotations:
51+
prometheus.io/scrape: "true"
52+
prometheus.io/path: /metrics
53+
prometheus.io/port: "8080"
54+
55+
56+
57+

0 commit comments

Comments
 (0)
Please sign in to comment.