Skip to content

Commit 0962c1c

Browse files
authored
Add Flux deployment and image publishing to registry (#232)
1 parent 4714366 commit 0962c1c

7 files changed

Lines changed: 159 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
branches: [main]
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
validate:
1114
name: Build
@@ -32,3 +35,42 @@ jobs:
3235

3336
- name: Run CI Tasks (Turbo)
3437
run: pnpm turbo validate:build
38+
39+
publish:
40+
name: Publish image
41+
runs-on: ubuntu-latest
42+
needs: validate
43+
if: github.event_name == 'push'
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v6
47+
48+
- name: Generate image tag
49+
id: image
50+
shell: bash
51+
run: |
52+
branch="$(printf '%s' "$GITHUB_REF_NAME" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//; s/-+/-/g')"
53+
if [ -z "$branch" ]; then
54+
branch="unknown"
55+
fi
56+
57+
short_sha="${GITHUB_SHA::7}"
58+
timestamp="$(date +%s)"
59+
60+
tag="${branch}-${short_sha}-${timestamp}"
61+
62+
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
63+
64+
- name: Login to Harbor
65+
uses: docker/login-action@v4
66+
with:
67+
registry: ${{ secrets.REGISTRY_URL }}
68+
username: ${{ secrets.REGISTRY_USERNAME }}
69+
password: ${{ secrets.REGISTRY_PASSWORD }}
70+
71+
- name: Build and push image
72+
uses: docker/build-push-action@v7
73+
with:
74+
context: .
75+
push: true
76+
tags: ${{ secrets.REGISTRY_URL }}/web/howto:${{ steps.image.outputs.tag }}

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ RUN pnpm --filter docs build
1717
FROM nginx:alpine AS runtime
1818

1919
COPY --from=builder /app/apps/docs/dist /usr/share/nginx/html
20-
COPY nginx.conf /etc/nginx/nginx.conf
20+
COPY deployment/nginx.conf /etc/nginx/nginx.conf
2121

22-
EXPOSE 80
22+
EXPOSE 8080

deploy/production/deployment.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: howto
5+
labels:
6+
app.kubernetes.io/name: howto
7+
app.kubernetes.io/part-of: howto
8+
spec:
9+
replicas: 2
10+
selector:
11+
matchLabels:
12+
app.kubernetes.io/name: howto
13+
template:
14+
metadata:
15+
labels:
16+
app.kubernetes.io/name: howto
17+
app.kubernetes.io/part-of: howto
18+
spec:
19+
imagePullSecrets:
20+
- name: harbor-regcred
21+
containers:
22+
- name: howto
23+
image: registry.timolia.systems/web/howto:main-0000000-1 # {"$imagepolicy": "web-live:howto"}
24+
imagePullPolicy: IfNotPresent
25+
ports:
26+
- name: http
27+
containerPort: 8080
28+
readinessProbe:
29+
httpGet:
30+
path: /
31+
port: http
32+
livenessProbe:
33+
httpGet:
34+
path: /
35+
port: http

deploy/production/httproute.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: howto
5+
labels:
6+
app.kubernetes.io/name: howto
7+
app.kubernetes.io/part-of: howto
8+
spec:
9+
hostnames:
10+
- howto.timolia.de
11+
parentRefs:
12+
- group: gateway.networking.k8s.io
13+
kind: Gateway
14+
name: timolia-gateway
15+
namespace: envoy-gateway-system
16+
rules:
17+
- backendRefs:
18+
- name: howto
19+
port: 80
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
namespace: web-live
4+
resources:
5+
- deployment.yaml
6+
- service.yaml
7+
- httproute.yaml

deploy/production/service.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: howto
5+
labels:
6+
app.kubernetes.io/name: howto
7+
app.kubernetes.io/part-of: howto
8+
spec:
9+
selector:
10+
app.kubernetes.io/name: howto
11+
ports:
12+
- name: http
13+
port: 80
14+
targetPort: http

deployment/nginx.conf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
worker_processes auto;
2+
3+
events {
4+
worker_connections 1024;
5+
}
6+
7+
http {
8+
server_tokens off;
9+
10+
server {
11+
listen 8080;
12+
server_name _;
13+
14+
root /usr/share/nginx/html;
15+
index index.html index.htm;
16+
include /etc/nginx/mime.types;
17+
18+
gzip on;
19+
gzip_vary on;
20+
gzip_min_length 1000;
21+
gzip_proxied expired no-cache no-store private auth;
22+
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
23+
24+
location /_astro/ {
25+
expires 1y;
26+
add_header Cache-Control "public, immutable";
27+
try_files $uri =404;
28+
}
29+
30+
error_page 404 /404.html;
31+
location = /404.html {
32+
root /usr/share/nginx/html;
33+
internal;
34+
}
35+
36+
location / {
37+
try_files $uri $uri/index.html =404;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)