From a3193fb40d5ce944f6a405482b78fef471b97173 Mon Sep 17 00:00:00 2001 From: djg Date: Mon, 21 Sep 2026 22:25:39 +0000 Subject: [PATCH] ci: switch to Docker image build and kubectl rollout --- .forgejo/workflows/deploy.yml | 23 +++++++++++++++++------ Dockerfile | 11 +++++++++++ nginx.conf | 28 ++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 6c2160f..fdf6b7d 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -10,10 +10,21 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Build site - run: python3 build.py - - - name: Deploy to nginx docroot + - name: Build image run: | - rsync -av --delete site/ /home/opc/zai-home-base/sites/bestdadjokes/ - echo "Deployed at $(date)" + docker build \ + -t git.ch4t.buzz/djg/bestdadjokes:${{ github.sha }} \ + -t git.ch4t.buzz/djg/bestdadjokes:latest \ + . + + - name: Push to registry + run: | + docker push git.ch4t.buzz/djg/bestdadjokes:${{ github.sha }} + docker push git.ch4t.buzz/djg/bestdadjokes:latest + + - name: Roll out to k8s + run: | + kubectl set image deployment/static-bdj \ + nginx=git.ch4t.buzz/djg/bestdadjokes:${{ github.sha }} \ + -n default + kubectl rollout status deployment/static-bdj -n default --timeout=120s diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8884fa4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# Build: run build.py to generate the static site +FROM python:3.11-slim AS builder +WORKDIR /app +COPY . . +RUN python3 build.py + +# Serve: bake the built site into nginx:alpine +FROM nginx:alpine +COPY --from=builder /app/site/ /usr/share/nginx/html/ +COPY nginx.conf /etc/nginx/nginx.conf +EXPOSE 80 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..22f3212 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,28 @@ +worker_processes 1; +error_log /dev/stderr warn; +pid /tmp/nginx.pid; +events { worker_connections 1024; } +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log /dev/stdout; + sendfile on; + gzip on; + gzip_types text/plain text/css application/javascript application/json application/xml image/svg+xml; + gzip_min_length 1024; + server { + listen 80; + root /usr/share/nginx/html; + index index.html; + error_page 404 /404.html; + add_header X-Content-Type-Options nosniff always; + add_header Referrer-Policy strict-origin-when-cross-origin always; + location ~* \.(css|js|svg|png|jpg|ico|woff2?)$ { + expires 7d; + add_header Cache-Control "public"; + } + location / { + try_files $uri $uri/ $uri/index.html =404; + } + } +}