HenniOKF
Documentation

Concept

The image

How the image arises from the standalone output, what is in it and how GitHub Actions builds and publishes it.

Structure

Everything about Docker lies under docker/. The build context is the root of the project, so every call names the Dockerfile with -f. The Dockerfile builds in two stages:

StageBaseWhat happens
buildnode:22npm ci, npm run build
runtimenode:22-slimtakes from the standalone output only what the server needs

What does not belong into the build context is listed in docker/Dockerfile.dockerignore: node_modules, .next, .git, .data*, test results, .env, .env.local, docker/.env and .claude. BuildKit reads a file with the name of the Dockerfile and the extension .dockerignore instead of a .dockerignore in the root.

The standalone output

next.config.mjs sets:

output: "standalone",
outputFileTracingExcludes: { "*": ["node_modules/@img/**", "node_modules/sharp/**"] },
serverExternalPackages: ["better-sqlite3"],
images: { unoptimized: true },
  • output: "standalone" bundles nearly everything into the server bundles under .next. Only a few modules stay, among them Next.js, React and better-sqlite3.
  • sharp belongs to Next.js but is never needed, because the image optimizer is off. It stays out.
  • better-sqlite3 is a native module. It is not bundled and is installed in the build stage for the platform of the image. A node_modules from your computer must therefore never go into the image.

The runtime stage copies server.js, package.json, node_modules and .next from .next/standalone, plus .next/static, public/ and docs/. The standalone output does not copy .next/static and public/; without them scripts, styles and images would be missing. docs/ is read at runtime by /docs and /docs-image.

In the container

WhatValue
usernode, UID 1000
root directoryHENNIOKF_ROOT=/henniokf, mounted, must belong to UID 1000
portPORT=3370, EXPOSE 3370
addressHOSTNAME=0.0.0.0
startnode server.js
versionHENNIOKF_COMMIT and HENNIOKF_BUILT_AT from the build arguments COMMIT and BUILT_AT

Docker sets HOSTNAME to the id of the container. Without HOSTNAME=0.0.0.0 the server would listen on one address only, and Traefik would not reach it.

The build arguments stand after all expensive steps, so a new commit does not invalidate the cache before them.

Building

docker/build.sh -t henniokf

docker/build.sh calls docker buildx build -f docker/Dockerfile from the root, gives the image commit and build time and passes every further argument on. If the working tree has uncommitted changes, the commit carries the suffix +dirty. For a VPS with amd64 from a computer with Apple silicon:

docker/build.sh --platform linux/amd64 -t ghcr.io/arpablo/henniokf:latest

Without the script it works too, but the image does not know its version:

docker build -f docker/Dockerfile -t henniokf .

The script checks nothing. Before a build for production run npm run check and npm run test:e2e.

Built on GitHub

The workflow "Image" (.github/workflows/image.yml) runs when "Check" was green on main, or by hand. In this order:

  1. Determine the version: short commit, build time, date.
  2. Log in to ghcr.io with the built-in GITHUB_TOKEN. No token of its own is needed.
  3. Build and load, not publish, for linux/amd64, with the cache of GitHub Actions.
  4. Start and answer: start the container with an empty root directory and ask GET /sign-in up to 60 times at two-second intervals. Only on 200 it goes on. Then the step checks that / answers 200 without signing in, because reading is public, that better-sqlite3 loads in the container, which the backup needs, and that docs/index.md lies in it.
  5. Publish with three tags:
TagMeaning
ghcr.io/arpablo/henniokf:latestthe newest green state of main
ghcr.io/arpablo/henniokf:<commit>a fixed state, for going back
ghcr.io/arpablo/henniokf:<date>the last state of a day

If the start test fails, nothing is published, and the VPS keeps the current image. In the template repository arpablo/HenniTemplateRepo step 5 is skipped by a condition; HenniOKF has another name and publishes.

The registry

A newly published package of a personal account is private. The label org.opencontainers.image.source links it to the repository. Only who logs in with a token (classic) with read:packages may pull it. After the open-source release the package is meant to become public; then that login falls away. Mind that, after the documentation of GitHub, a public package cannot be made private again.

What is in the image and what not

In the imageNot in the image
the built application under .nextthe source as such, the tests, context/, .github/
the few modules Next.js does not bundlethe rest of node_modules, also sharp
public/ and docs/.env.local and every secret
Node 22, commit and build timethe data of the instance; it lies in the mounted root directory

An image can be unpacked completely. Whoever may pull it can read what is in it.

Next: Compose locally.