Skip to content

Commit 60c83f9

Browse files
authored
Merge pull request #129 from Vauhtijuoksu/new-pipeline
Create a new pipeline to deploy to the k8s cluster
2 parents aeb9fe4 + 94e6249 commit 60c83f9

File tree

10 files changed

+197
-170
lines changed

10 files changed

+197
-170
lines changed

.github/workflows/azure-deployment.yml

Lines changed: 0 additions & 95 deletions
This file was deleted.

.github/workflows/docker.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

.github/workflows/gh-publish.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish and deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- trunk
7+
8+
jobs:
9+
build:
10+
permissions:
11+
contents: read
12+
packages: write
13+
id-token: write
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Docker build
18+
uses: docker/build-push-action@v6
19+
with:
20+
context: .
21+
file: Dockerfile.production
22+
load: true
23+
tags: vauhtijuoksu/cms:test
24+
25+
- name: Extract Docker metadata
26+
id: meta
27+
uses: docker/metadata-action@v3
28+
with:
29+
images: |
30+
name=ghcr.io/vauhtijuoksu/wwwauhtijuoksu-cms
31+
tags: |
32+
# sha for branch triggers
33+
type=ref,event=branch
34+
type=ref,event=branch,suffix=-{{sha}}
35+
type=ref,event=pr,suffix=-{{sha}}
36+
# semver only for version tags
37+
type=semver,pattern={{version}}
38+
39+
- name: Log in to GHCR
40+
if: github.event_name == 'push'
41+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
42+
43+
# This should use cached image and not actually trigger a new build
44+
- name: Build and push images
45+
uses: docker/build-push-action@v6
46+
with:
47+
context: .
48+
file: Dockerfile.production
49+
push: true
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}
52+
53+
- name: Login to to Tailscale
54+
uses: tailscale/github-action@v4.1.0
55+
with:
56+
oauth-client-id: ${{ vars.TS_OIDC_CLIENT_ID }}
57+
audience: ${{ vars.TS_OIDC_AUDIENCE }}
58+
tags: tag:gh-runner
59+
- name: Setup Kubectl
60+
uses: azure/setup-kubectl@v4
61+
- name: Setup kubeconfig
62+
run: |
63+
mkdir ~/.kube
64+
echo "${{ vars.KUBECONFIG }}" > ~/.kube/config
65+
kubectl get all
66+
- name: Extract main sha tag
67+
id: main_sha
68+
run: |
69+
# Find the line with `:main-...`
70+
full_line="$(echo '${{ steps.meta.outputs.tags }}' | grep ':main-pipeline-')"
71+
# Strip everything before the last :
72+
tag="${full_line##*:}"
73+
echo "tag=$tag" >> $GITHUB_OUTPUT
74+
- uses: azure/setup-helm@v3.5
75+
- run: |
76+
helm upgrade --install -n cms cms deployment/ -f deployment/prod-values.yaml --set image.tag=${{ steps.main_sha.outputs.tag }}

deployment/prod-values.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
database:
2+
address: postgres-rw.postgres.svc.cluster.local
3+
database: wwwauhtijuoksu-cms
4+
secret: vjcms-psql
5+
user: wwwauhtijuoksu-cms
6+
django:
7+
allowed_hosts: cms.dev.vauhtijuoksu.fi,www.vauhtijuoksu.fi,vauhtijuoksu.fi
8+
media_url: https://vjcms.blob.core.windows.net/media/
9+
static_url: https://cms-static.dev.vauhtijuoksu.fi/static/
10+
vj_api_url: http://vauhtijuoksu-api.vauhtijuoksu-api.svc.cluster.local:8080
11+
http:
12+
staticfiles_host: cms-static.dev.vauhtijuoksu.fi
13+
image:
14+
registry: ghcr.io/
15+
repository: vauhtijuoksu/wwwauhtijuoksu-cms

deployment/templates/deployment.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ spec:
4747
envFrom:
4848
- configMapRef:
4949
name: django-env
50+
- secretRef:
51+
name: discord
5052
env:
5153
- name: POSTGRES_PASSWORD
5254
valueFrom:
@@ -66,6 +68,17 @@ spec:
6668
name: {{ .Values.storage.secret }}
6769
key: key
6870
optional: true
71+
- name: nginx
72+
image: nginx:stable
73+
ports:
74+
- name: nginx
75+
containerPort: 80
76+
protocol: TCP
77+
volumeMounts:
78+
- name: nginx-config
79+
mountPath: /etc/nginx/conf.d
80+
- name: django-static
81+
mountPath: /usr/share/nginx/html/static
6982
volumes:
7083
- name: django-static
7184
emptyDir: {}
@@ -74,3 +87,6 @@ spec:
7487
# TODO: Persistent media volume
7588
- name: django-media
7689
emptyDir: {}
90+
- name: nginx-config
91+
configMap:
92+
name: nginx-config

deployment/templates/ingress.yaml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,43 @@ kind: Ingress
33
metadata:
44
name: {{ .Chart.Name }}
55
annotations:
6-
kubernetes.io/ingress.class: nginx
7-
cert-manager.io/cluster-issuer: letsencrypt-prod
8-
nginx.ingress.kubernetes.io/rewrite-target: /$1
9-
nginx.ingress.kubernetes.io/use-regex: "true"
106
# To work on kind cluster
117
nginx.ingress.kubernetes.io/server-alias: localhost
128
spec:
139
tls:
1410
- hosts:
1511
- {{ .Values.http.host }}
16-
secretName: {{ .Values.http.host }}
12+
- www.vauhtijuoksu.fi
13+
- vauhtijuoksu.fi
14+
ingressClassName: traefik
1715
rules:
1816
- host: {{ .Values.http.host }}
1917
http:
2018
paths:
21-
- path: /(.*)
19+
- backend:
20+
service:
21+
name: {{ .Chart.Name }}
22+
port:
23+
name: http
24+
path: /
25+
pathType: Prefix
26+
- host: www.vauhtijuoksu.fi
27+
http:
28+
paths:
29+
- backend:
30+
service:
31+
name: {{ .Chart.Name }}
32+
port:
33+
name: http
34+
path: /
2235
pathType: Prefix
23-
backend:
36+
- host: vauhtijuoksu.fi
37+
http:
38+
paths:
39+
- backend:
2440
service:
2541
name: {{ .Chart.Name }}
2642
port:
27-
name: http
43+
name: http
44+
path: /
45+
pathType: Prefix

deployment/templates/nginx-cm.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: nginx-config
5+
data:
6+
default.conf: |
7+
server {
8+
listen 80;
9+
server_name _;
10+
11+
location ~* \.(eot|ttf|woff|woff2|otf)$ {
12+
add_header Access-Control-Allow-Origin "*";
13+
root /usr/share/nginx/html;
14+
expires 30d;
15+
add_header Cache-Control "public";
16+
access_log off;
17+
}
18+
19+
location /static/ {
20+
alias /usr/share/nginx/html/static/;
21+
expires 30d;
22+
add_header Cache-Control "public";
23+
access_log off;
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: {{ .Chart.Name }}-nginx
5+
annotations:
6+
# To work on kind cluster
7+
nginx.ingress.kubernetes.io/server-alias: localhost
8+
spec:
9+
tls:
10+
- hosts:
11+
- {{ .Values.http.staticfiles_host }}
12+
ingressClassName: traefik
13+
rules:
14+
- host: {{ .Values.http.staticfiles_host }}
15+
http:
16+
paths:
17+
- backend:
18+
service:
19+
name: {{ .Chart.Name }}-nginx
20+
port:
21+
name: http
22+
path: /
23+
pathType: Prefix

0 commit comments

Comments
 (0)