From bbea5db2ee82e014c5b8c2592b6b97f16310f42f Mon Sep 17 00:00:00 2001 From: Ken Schiano Date: Sat, 21 Nov 2026 20:38:46 -0500 Subject: [PATCH 1/2] Publish the site as a container on the cluster instead of the pages branch Every push to main builds the page into an nginx image and pushes it to harbor.kenschiano.net/home/threshing-atlas; Argo CD Image Updater rolls the deployment (kubefiles web/threshing-atlas) at https://threshingatlas.kenschiano.net. forge.yaml now names that address. Co-Authored-By: Claude Opus 5.5 --- .dockerignore | 7 +++++++ .gitea/workflows/image.yml | 30 ++++++++++++++++++++++++++++++ .gitea/workflows/pages.yml | 37 ------------------------------------- Dockerfile | 13 +++++++++++++ data/croissant.json | 2 +- deploy/nginx.conf | 20 ++++++++++++++++++++ forge.yaml | 6 +++--- 7 files changed, 74 insertions(+), 41 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/image.yml delete mode 100644 .gitea/workflows/pages.yml create mode 100644 Dockerfile create mode 100644 deploy/nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..23f4e7c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.gitea +.github +dist +node_modules +**/__pycache__ +tests diff --git a/.gitea/workflows/image.yml b/.gitea/workflows/image.yml new file mode 100644 index 0000000..c4c0e5c --- /dev/null +++ b/.gitea/workflows/image.yml @@ -0,0 +1,30 @@ +# The published Atlas page. Every push to main (every merged pull request, and the data bot's daily commits) builds +# the site into a container image and pushes it to Harbor. Argo CD Image Updater watches the `latest` digest and +# rolls the deployment in kubefiles (web/threshing-atlas), serving https://threshingatlas.kenschiano.net. +# +# Secrets: HARBOR_USERNAME and HARBOR_PASSWORD, a Harbor robot account with push access to the `home` project. +name: Publish the site (container image) +on: + push: + branches: [main] + workflow_dispatch: +concurrency: + group: image + cancel-in-progress: true +env: + IMAGE: harbor.kenschiano.net/home/threshing-atlas +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build and push + env: + HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }} + HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }} + run: | + echo "$HARBOR_PASSWORD" | docker login harbor.kenschiano.net -u "$HARBOR_USERNAME" --password-stdin + docker build -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA::8}" . + docker push "$IMAGE:latest" + docker push "$IMAGE:${GITHUB_SHA::8}" + echo "pushed $IMAGE:latest (${GITHUB_SHA::8})" diff --git a/.gitea/workflows/pages.yml b/.gitea/workflows/pages.yml deleted file mode 100644 index 4e05a40..0000000 --- a/.gitea/workflows/pages.yml +++ /dev/null @@ -1,37 +0,0 @@ -# The published Atlas page. Every push to main builds the static site (npm run build -> dist/) and force-pushes it -# as the single commit of the `pages` branch. Ken's server serves that branch as plain files (a web server whose -# folder is kept in step with the branch: a git-sync sidecar, or `git pull` on a timer). The repository is public, -# so his server needs no token. Only the build output is on `pages`, never the raw data. -# -# Secrets: ATLAS_BOT_TOKEN (as in update-sources.yml), to push the branch. -name: Publish the site (pages branch) -on: - push: - branches: [main] - workflow_dispatch: -concurrency: - group: pages - cancel-in-progress: true -jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 20 - - run: npm run build - - name: Push dist/ as the pages branch - env: - ATLAS_BOT_TOKEN: ${{ secrets.ATLAS_BOT_TOKEN }} - run: | - cd dist - git init -q -b pages - git config user.name "Atlas data bot" - git config user.email "atlas-bot@noreply.localhost" - git add -A - git commit -q -m "site built from ${GITHUB_SHA::8}" - GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.https://git.kenschiano.net/.extraheader" \ - GIT_CONFIG_VALUE_0="AUTHORIZATION: token $ATLAS_BOT_TOKEN" \ - git push -q -f "https://git.kenschiano.net/${GITHUB_REPOSITORY}.git" pages - echo "pages branch updated from ${GITHUB_SHA::8}" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6fee316 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +# The published Atlas page as a container: build the static site (npm run build -> dist/), then serve it with an +# unprivileged nginx on port 8080. .gitea/workflows/image.yml builds this on every push to main and pushes it to +# harbor.kenschiano.net/home/threshing-atlas:latest; Argo CD Image Updater rolls the deployment (kubefiles, +# web/threshing-atlas) when that digest changes. +FROM node:22-alpine AS build +WORKDIR /src +COPY . . +RUN node site/build.js /site + +FROM nginxinc/nginx-unprivileged:1.28-alpine +COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=build /site /usr/share/nginx/html +EXPOSE 8080 diff --git a/data/croissant.json b/data/croissant.json index 140368a..adfd37f 100644 --- a/data/croissant.json +++ b/data/croissant.json @@ -46,7 +46,7 @@ "conformsTo": "http://mlcommons.org/croissant/1.0", "name": "Threshing Atlas", "description": "Community-logged runs of the Dragonkind \"threshing\" (the dragon-bonding game based on Fourth Wing), coded into one record per run: every choice, what the game rolled, and how the run ended. Also the route model built from them, the statistics shown on the Threshing Atlas page, and the route graph shared with a DragonKind bot.", - "url": "https://git.kenschiano.net/DragonKind/threshing-atlas", + "url": "https://threshingatlas.kenschiano.net", "sameAs": "https://git.kenschiano.net/DragonKind/threshing-atlas", "license": "https://creativecommons.org/licenses/by/4.0/", "creator": { diff --git a/deploy/nginx.conf b/deploy/nginx.conf new file mode 100644 index 0000000..954f614 --- /dev/null +++ b/deploy/nginx.conf @@ -0,0 +1,20 @@ +# The Atlas is plain static files. The data changes daily, so browsers revalidate rather than cache blindly. +server { + listen 8080; + root /usr/share/nginx/html; + index index.html; + charset utf-8; + + types { + text/plain yaml py csv; + } + include /etc/nginx/mime.types; + + gzip on; + gzip_types text/plain text/css application/javascript application/json text/csv; + + add_header Cache-Control "no-cache"; + + location = /healthz { access_log off; return 200 "ok\n"; } + location / { try_files $uri $uri/ =404; } +} diff --git a/forge.yaml b/forge.yaml index 0c1ec52..c1f137c 100644 --- a/forge.yaml +++ b/forge.yaml @@ -13,9 +13,9 @@ branch: main # public, limited (only people signed in to this server) or private: who can open the links below visibility: limited -# the published page: Ken's server serves the `pages` branch (.gitea/workflows/pages.yml). Set this to its address -# once it is up (then `python -m collection build`): the page's links and the dataset metadata use it. -site: null +# the published page: a container on Ken's cluster (.gitea/workflows/image.yml, kubefiles web/threshing-atlas). Its address +# (after a change, `python -m collection build`): the page's links and the dataset metadata use it. +site: https://threshingatlas.kenschiano.net # other copies of the repository (informational) mirrors: From b9d692a91cb06c3554a18f109f567a8e85e47ca8 Mon Sep 17 00:00:00 2001 From: Ken Schiano Date: Sat, 21 Nov 2026 20:49:45 -0500 Subject: [PATCH 2/2] Build the site image on Red Hat's hardened images Node build on hi/nodejs:22-builder, the nginx config checked with `nginx -t` on hi/nginx:latest-builder, served by the distroless hi/nginx runtime (UID 65532, no shell). nginx keeps temp files in /tmp so the pod can run with a read-only root filesystem; adds nosniff/referrer headers and hides the nginx version. Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 23 +++++++++++++++++------ deploy/nginx.conf | 28 ++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6fee316..82c2bb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,24 @@ -# The published Atlas page as a container: build the static site (npm run build -> dist/), then serve it with an -# unprivileged nginx on port 8080. .gitea/workflows/image.yml builds this on every push to main and pushes it to -# harbor.kenschiano.net/home/threshing-atlas:latest; Argo CD Image Updater rolls the deployment (kubefiles, -# web/threshing-atlas) when that digest changes. -FROM node:22-alpine AS build +# The published Atlas page as a container, on Red Hat's hardened images: build the static site with Node, check +# the nginx config with the nginx builder (it has a shell), then serve with the distroless nginx runtime (no shell +# or package manager, UID 65532, port 8080). .gitea/workflows/image.yml builds this on every push to main and +# pushes it to harbor.kenschiano.net/home/threshing-atlas:latest; Argo CD Image Updater rolls the deployment +# (kubefiles, web/threshing-atlas) when that digest changes. +ARG NODE_TAG=22 +ARG NGINX_TAG=latest + +FROM registry.access.redhat.com/hi/nodejs:${NODE_TAG}-builder AS build +# Only /site leaves this stage, so build as root +USER root WORKDIR /src COPY . . RUN node site/build.js /site -FROM nginxinc/nginx-unprivileged:1.28-alpine +# Fail the build on a bad config, since the runtime image can't run `nginx -t` for us +FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG}-builder AS nginx-check COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf +RUN nginx -t -e /dev/stderr + +FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG} +COPY --from=nginx-check /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf COPY --from=build /site /usr/share/nginx/html EXPOSE 8080 diff --git a/deploy/nginx.conf b/deploy/nginx.conf index 954f614..2aaed44 100644 --- a/deploy/nginx.conf +++ b/deploy/nginx.conf @@ -1,20 +1,36 @@ # The Atlas is plain static files. The data changes daily, so browsers revalidate rather than cache blindly. +# Replaces the image's conf.d/default.conf (it listens on 8080 and runs as UID 65532). + +# Temp files under /tmp (an emptyDir in the pod), so the root filesystem can be read-only +client_body_temp_path /tmp/client_body; +proxy_temp_path /tmp/proxy; +fastcgi_temp_path /tmp/fastcgi; +uwsgi_temp_path /tmp/uwsgi; +scgi_temp_path /tmp/scgi; + server { listen 8080; root /usr/share/nginx/html; index index.html; charset utf-8; + server_tokens off; - types { - text/plain yaml py csv; - } + # The image logs to files under /var/log/nginx; send access logs to the pod log instead + access_log /dev/stdout main; + + # Show the page's data and source files as text (in server context this replaces the inherited types) include /etc/nginx/mime.types; + types { + text/plain yaml py; + } gzip on; - gzip_types text/plain text/css application/javascript application/json text/csv; + gzip_types text/plain text/css text/csv text/javascript application/javascript application/json; - add_header Cache-Control "no-cache"; + add_header Cache-Control "no-cache" always; + add_header X-Content-Type-Options "nosniff" always; + add_header Referrer-Policy "strict-origin-when-cross-origin" always; - location = /healthz { access_log off; return 200 "ok\n"; } + location = /healthz { access_log off; default_type text/plain; return 200 "ok\n"; } location / { try_files $uri $uri/ =404; } }