Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Publish a Docker image for each release

Guido Boykeba2db05b1cba
diff --git a/.env.docker.example b/.env.docker.example
index 328743f..5626e46 100644
--- a/.env.docker.example
+++ b/.env.docker.example
@@ -40,6 +40,14 @@ SMTP_PASSWORD=
# --- Optional ---------------------------------------------------------------
+# The release image to run. compose.yml of each release tag names its own
+# version, so leave this unset and update by checking out the next tag. Set it
+# to run another release with these files, for example the previous one.
+# LALABASE_VERSION=
+
+# Building the image from the checkout instead of pulling it (compose.build.yml):
+# COMPOSE_FILE=compose.yml:compose.build.yml
+
# Trying it on your own computer without a certificate: set
# LALABASE_HOST=localhost:3000
# LALABASE_FORCE_SSL=false
diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml
new file mode 100644
index 0000000..496d52f
--- /dev/null
+++ b/.github/workflows/docker-release.yml
@@ -0,0 +1,178 @@
+# Release images: builds ghcr.io/lalabase/lalabase for each published
+# release, for linux/amd64 and linux/arm64, checks each with
+# script/docker_check and pushes it. compose.yml of the release tag pulls
+# exactly this image: script/release writes the version into it.
+#
+# Each architecture builds on a runner of its own kind: native extensions and
+# the tree-sitter grammars do not carry over between them (Dockerfile), and an
+# emulated build takes far longer. An image is pushed only after it booted, so
+# a release never names an image that does not start. The publish job joins
+# both architectures under the version, moves `latest` only for the newest
+# release, attests where the image was built (`gh attestation verify`) and
+# adds the image to the release notes.
+#
+# A pull request that changes the image or this file builds and checks both
+# architectures and pushes nothing: docker.yml builds amd64 only. By hand
+# (workflow_dispatch) for a release tag on main, for example one published
+# before this workflow existed.
+name: Docker release
+
+on:
+ release:
+ types: [published]
+ pull_request:
+ paths:
+ - 'Dockerfile'
+ - '.dockerignore'
+ - 'script/docker_check'
+ - '.github/workflows/docker-release.yml'
+ workflow_dispatch:
+ inputs:
+ tag:
+ description: 'Release tag on main, e.g. 2026.10.1'
+ required: true
+
+permissions: {}
+
+concurrency:
+ group: docker-release-${{ github.event.release.tag_name || inputs.tag || github.event.pull_request.number }}
+ cancel-in-progress: false
+
+env:
+ IMAGE: ghcr.io/lalabase/lalabase
+ TAG: ${{ github.event.release.tag_name || inputs.tag }}
+ # A pull request builds and checks; only a release (or a run by hand) pushes.
+ PUSH: ${{ github.event_name != 'pull_request' }}
+
+jobs:
+ build:
+ strategy:
+ matrix:
+ include:
+ - arch: amd64
+ runner: ubuntu-24.04
+ - arch: arm64
+ runner: ubuntu-24.04-arm
+ runs-on: ${{ matrix.runner }}
+ timeout-minutes: 45
+ permissions:
+ contents: read
+ packages: write
+ env:
+ ARCH: ${{ matrix.arch }}
+ HOST: lalabase-ci.test:3000
+
+ steps:
+ # The checkout is this workflow's commit: the release tag, or main for a
+ # run by hand. compose.yml and script/docker_check come from it; the
+ # image is built from the tag (src/).
+ - uses: actions/checkout@v7
+ with:
+ fetch-depth: 0
+
+ # The version scheme of Lalabase::Release::VERSION. The tag lands in
+ # shell commands and image names, so nothing else passes.
+ - name: Release tag on main
+ if: env.PUSH == 'true'
+ run: |
+ [[ "$TAG" =~ ^[0-9]{4}\.([1-9]|1[0-2])\.[0-9]+$ ]] || { echo "::error::Not a release tag: $TAG"; exit 1; }
+ git merge-base --is-ancestor "refs/tags/$TAG" origin/main || { echo "::error::$TAG is not on main"; exit 1; }
+ echo "LALABASE_VERSION=$TAG" >> "$GITHUB_ENV"
+ git worktree add --detach src "refs/tags/$TAG"
+
+ - name: Pull request source
+ if: env.PUSH != 'true'
+ run: |
+ echo "LALABASE_VERSION=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_ENV"
+ git worktree add --detach src HEAD
+
+ - name: Build
+ run: |
+ docker build \
+ --label org.opencontainers.image.source=https://github.com/lalabase/lalabase \
+ --label org.opencontainers.image.title=Lalabase \
+ --label org.opencontainers.image.licenses=AGPL-3.0-only \
+ --label org.opencontainers.image.version="$LALABASE_VERSION" \
+ --label org.opencontainers.image.revision="$(git -C src rev-parse HEAD)" \
+ --tag "$IMAGE:$LALABASE_VERSION" \
+ src
+
+ - name: Boot and check the install
+ run: script/docker_check
+
+ - name: Log in to the registry
+ if: env.PUSH == 'true'
+ uses: docker/login-action@v4
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ # One tag per architecture, for the publish job to join. They stay in
+ # the registry; compose.yml pulls the version itself.
+ - name: Push
+ if: env.PUSH == 'true'
+ run: |
+ docker tag "$IMAGE:$TAG" "$IMAGE:$TAG-$ARCH"
+ docker push --quiet "$IMAGE:$TAG-$ARCH"
+
+ publish:
+ needs: build
+ if: github.event_name != 'pull_request'
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ permissions:
+ contents: write # the release notes
+ packages: write
+ id-token: write # the attestation
+ attestations: write
+ env:
+ GH_TOKEN: ${{ github.token }}
+ GH_REPO: ${{ github.repository }}
+
+ steps:
+ - uses: docker/setup-buildx-action@v4
+
+ - uses: docker/login-action@v4
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ # `latest` only for the newest release: a run by hand for an older tag
+ # must not move it back.
+ - name: One tag for both architectures
+ id: manifest
+ run: |
+ tags=(--tag "$IMAGE:$TAG")
+ newest=$(gh api "repos/$GH_REPO/releases/latest" --jq .tag_name)
+ if [ "$newest" = "$TAG" ]; then tags+=(--tag "$IMAGE:latest"); fi
+ docker buildx imagetools create "${tags[@]}" "$IMAGE:$TAG-amd64" "$IMAGE:$TAG-arm64"
+ digest=$(docker buildx imagetools inspect "$IMAGE:$TAG" --format '{{json .Manifest}}' | jq -r .digest)
+ [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "::error::No digest for $IMAGE:$TAG: $digest"; exit 1; }
+ echo "digest=$digest" >> "$GITHUB_OUTPUT"
+
+ - uses: actions/attest-build-provenance@v4
+ with:
+ subject-name: ${{ env.IMAGE }}
+ subject-digest: ${{ steps.manifest.outputs.digest }}
+ push-to-registry: true
+
+ # Appended last, so a second run replaces what the first one wrote.
+ - name: The image in the release notes
+ env:
+ DIGEST: ${{ steps.manifest.outputs.digest }}
+ run: |
+ gh release view "$TAG" --json body --jq .body | awk '/^### Docker image$/ { exit } { print }' > notes.md
+ cat >> notes.md <<EOF
+
+ ### Docker image
+
+ \`\`\`
+ docker pull $IMAGE:$TAG
+ \`\`\`
+
+ For linux/amd64 and linux/arm64, digest \`$DIGEST\`. Check where it was built:
+ \`gh attestation verify oci://$IMAGE:$TAG --owner lalabase\`
+ EOF
+ gh release edit "$TAG" --notes-file notes.md
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 4ac9e79..a619660 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -1,4 +1,7 @@
-# Docker install check: builds the self-hosting image and boots compose.yml.
+# Docker install check: builds the self-hosting image from the checkout and
+# boots compose.yml with it (compose.build.yml, the way a self-hoster builds
+# their own). The checks are script/docker_check, which docker-release.yml
+# runs on each release image too.
#
# Our own servers do not run the image (they deploy with Capistrano), so
# nothing else would notice when it stops building or booting: a new native
@@ -18,6 +21,8 @@ on:
- 'Dockerfile'
- '.dockerignore'
- 'compose.yml'
+ - 'compose.build.yml'
+ - 'script/docker_check'
- '.env.docker.example'
- 'Gemfile'
- 'Gemfile.lock'
@@ -41,84 +46,15 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
- # A host that is not localhost: the health check in compose.yml calls /up
- # on localhost, so it passes only through the /up exemptions from the host
- # check and the https redirect. The pages are asked for with this host.
env:
HOST: lalabase-ci.test:3000
+ COMPOSE_FILE: compose.yml:compose.build.yml
steps:
- uses: actions/checkout@v4
- # The .env a self-hoster would write without a certificate: fresh
- # secrets, plain http, no Caddy. Plus the DATABASE_URL line the guide
- # for installs without Docker shows: compose.yml must win over it.
- - name: Write .env from the example
- run: |
- cp .env.docker.example .env
- sed -i \
- -e "s/^LALABASE_HOST=.*/LALABASE_HOST=${HOST}/" \
- -e '/^COMPOSE_PROFILES=/d' \
- .env
- {
- echo "LALABASE_FORCE_SSL=false"
- echo "SECRET_KEY_BASE=$(openssl rand -hex 64)"
- echo "ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=$(openssl rand -hex 32)"
- echo "ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=$(openssl rand -hex 32)"
- echo "ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=$(openssl rand -hex 32)"
- echo "POSTGRES_PASSWORD=$(openssl rand -hex 24)"
- echo "DATABASE_URL=postgres://lalabase:wrong@db:5432/lalabase_production"
- } >> .env
-
- name: Build the image
run: docker compose build
- - name: Start the stack
- run: docker compose up -d --wait --wait-timeout 300
-
- - name: Health check, a page that needs the database, a foreign host
- run: |
- curl -fsS -o /dev/null http://localhost:3000/up
- curl -fsS -o /dev/null -H "Host: ${HOST}" http://localhost:3000/users/sign_in
- code=$(curl -s -o /dev/null -w '%{http_code}' -H 'Host: evil.example' http://localhost:3000/users/sign_in)
- test "$code" = "403" || { echo "::error::A foreign host got $code instead of 403"; exit 1; }
-
- - name: The data lands in the database the backups dump
- run: |
- docker compose exec -T db psql -U lalabase -d lalabase -tAc \
- "SELECT 1 FROM information_schema.tables WHERE table_name = 'schema_migrations'" | grep -qx 1
-
- # The compiled CSS carries its font URLs with the asset host burnt in.
- # A self-hosted instance must not load anything from our host. grep
- # exits 1 for "no match"; 0 is a match and 2 a failed search, both red.
- - name: No asset names our host
- run: |
- rc=0
- docker compose exec -T web grep -rl 'lalabase.com' public/assets || rc=$?
- if [ "$rc" -ne 1 ]; then
- echo "::error::grep exited $rc: assets name lalabase.com (0) or could not be searched (2)"
- exit 1
- fi
-
- - name: First admin
- run: |
- docker compose exec -T \
- -e LALABASE_ADMIN_PASSWORD=ci-check-password-123 \
- web bin/rails lalabase:setup
-
- # The worker stays up: Solid Queue exits at boot when the pool is
- # smaller than its threads, and compose would just keep restarting it.
- - name: Worker is running
- run: |
- sleep 10
- test "$(docker compose ps worker --format '{{.State}}')" = "running"
- docker compose logs worker | grep -q 'Started Worker'
-
- - name: Logs
- if: failure()
- run: docker compose logs --no-color --tail 200
-
- - name: Stop
- if: always()
- run: docker compose down -v
+ - name: Boot and check the install
+ run: script/docker_check
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8efd713..3dc11eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,26 @@ starts (`db:prepare lalabase:data_backfills`). Without Docker, run
## [Unreleased]
+### Added
+
+- A Docker image for each release, `ghcr.io/lalabase/lalabase:<version>`, for linux/amd64
+ and linux/arm64. It boots and passes the install check before it is pushed, and carries a
+ signed record of where it was built (`gh attestation verify oci://ghcr.io/lalabase/lalabase:<version> --owner lalabase`).
+ `compose.yml` of a release pulls the image of that release instead of building it, and
+ `compose.build.yml` still builds the image from the checkout (#PR_NUMBER).
+
+### Fixed
+
+- Building the image yourself no longer fails on the first `up --build` with Docker 29:
+ only the web service builds, and the worker runs the image it built (#PR_NUMBER).
+
+### Upgrade notes
+
+- `compose.yml` no longer builds the image: it pulls `ghcr.io/lalabase/lalabase` in the
+ version of the release you checked out. Update with `git checkout <release>`, then
+ `docker compose pull && docker compose up -d`. To keep building the image on your
+ server, add `COMPOSE_FILE=compose.yml:compose.build.yml` to `.env`.
+
## [2026.10.1] - 2026-10-21
<!-- drafted from d03168b613c25580924a59815580a512c0b95666 -->
diff --git a/CLAUDE.md b/CLAUDE.md
index 9dc35f2..a89dd5a 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -84,9 +84,15 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
27.09.2026 liefen die Regressions-Specs von #895 und #896 nirgends. Neue Specs zu Rechten,
Mandantengrenzen oder behobenen Lücken: Tag setzen **und** Pfad eintragen.
The full suite and full `erblint` still run locally (known drift, separate cleanup).
-* **Docker** (`Dockerfile`, `compose.yml`, `.env.docker.example`): for self-hosters only, our
- servers deploy with Capistrano and never run the image. `.github/workflows/docker.yml` builds it
- and boots the stack, only for PRs touching the image or `config/`. Every production setting that
+* **Docker** (`Dockerfile`, `compose.yml`, `compose.build.yml`, `.env.docker.example`): for
+ self-hosters only, our servers deploy with Capistrano and never run the image. Each published
+ release builds `ghcr.io/lalabase/lalabase:<version>` for amd64 and arm64
+ (`.github/workflows/docker-release.yml`), checks it with `script/docker_check` and only then
+ pushes it. `compose.yml` pulls the release in its `image:` line, which `script/release
+ prepare` writes and `publish` holds against the version (guard: `changelog_guard_spec.rb`);
+ never edit that line by hand. `.github/workflows/docker.yml` builds from the checkout
+ (`compose.build.yml`) and boots the stack, only for PRs touching the image or `config/`.
+ Every production setting that
names a host goes through `Lalabase::InstanceSettings`; without `LALABASE_HOST` it returns our
servers' values unchanged (pinned by `spec/config/instance_settings_spec.rb`).
⚠️ **The compiled CSS carries the asset host.** The image precompiles with `ASSET_HOST=` set
diff --git a/Dockerfile b/Dockerfile
index 32a08cc..7519263 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,8 +4,11 @@
# The image for running Lalabase yourself with Docker Compose (compose.yml).
# Our own servers do not use it: they deploy with Capistrano.
#
-# docker compose build
-# docker compose up -d
+# Each release publishes it as ghcr.io/lalabase/lalabase:<version>, for
+# linux/amd64 and linux/arm64 (.github/workflows/docker-release.yml), and
+# compose.yml pulls that. To build it from a checkout:
+#
+# docker compose -f compose.yml -f compose.build.yml up -d --build
#
# Build it on the architecture it runs on, or with buildx for that platform:
# native extensions do not carry over between arm64 and amd64.
diff --git a/README.md b/README.md
index 06b85ae..ea2bf5e 100644
--- a/README.md
+++ b/README.md
@@ -116,13 +116,15 @@ Docker Compose v2, and a domain pointing at it.
git clone https://github.com/lalabase/lalabase.git && cd lalabase
git checkout "$(git describe --tags --abbrev=0)" # the latest release, not main
cp .env.docker.example .env # fill in the values it asks for
-docker compose up -d --build
+docker compose up -d # pulls the image of that release
docker compose exec web bin/rails lalabase:setup
```
`compose.yml` starts the application, a job worker, PostgreSQL with pgvector, Valkey and Caddy,
which fetches a TLS certificate for `LALABASE_HOST`. If a proxy of your own terminates TLS, drop
-the `COMPOSE_PROFILES=tls` line. Build the image on the architecture it runs on.
+the `COMPOSE_PROFILES=tls` line. Each release has an image `ghcr.io/lalabase/lalabase:<version>`
+for linux/amd64 and linux/arm64, and the `compose.yml` of the release pulls it. To build the image
+from your checkout instead, use `compose.build.yml` (see its first lines).
The guide covers installation, configuration, AI keys, backups and updates, in English and
German: [lalabase.com/docs](https://lalabase.com/docs/en/self-hosting/getting-started/overview).
diff --git a/compose.build.yml b/compose.build.yml
new file mode 100644
index 0000000..d1a3b45
--- /dev/null
+++ b/compose.build.yml
@@ -0,0 +1,23 @@
+# Builds the image from this checkout instead of pulling the release image
+# that compose.yml names, for a change of your own.
+#
+# docker compose -f compose.yml -f compose.build.yml up -d --build
+#
+# Or put COMPOSE_FILE=compose.yml:compose.build.yml into .env, and every
+# docker compose command (build, up, exec) uses both files.
+#
+# Build on the architecture the server runs: native extensions do not carry
+# over between arm64 and amd64.
+#
+# Only web builds, and the worker runs the image web built. With both
+# building the same image, the first `up --build` failed on Docker 29: the
+# two exports collide and one reports that the image already exists.
+
+services:
+ web:
+ build: .
+ image: lalabase:local
+
+ worker:
+ image: lalabase:local
+ pull_policy: never
diff --git a/compose.yml b/compose.yml
index 4c113bb..00f9e70 100644
--- a/compose.yml
+++ b/compose.yml
@@ -1,9 +1,18 @@
# Lalabase with Docker Compose, for running it yourself.
#
# cp .env.docker.example .env # then fill in the values it asks for
-# docker compose up -d --build
+# docker compose up -d
# docker compose exec web bin/rails lalabase:setup
#
+# The application runs the image of this file's release, built for
+# linux/amd64 and linux/arm64 when the release was published
+# (.github/workflows/docker-release.yml). Check out a release tag, not main:
+# the version below is the one script/release wrote for that tag. Updating
+# means checking out the next tag, reading its upgrade notes, then
+# `docker compose pull && docker compose up -d`. LALABASE_VERSION in .env
+# overrides the version, for example to go back to the previous release.
+# To build the image from your checkout instead, see compose.build.yml.
+#
# Services: web (Puma), worker (Solid Queue), db (PostgreSQL with pgvector),
# redis (Action Cable and the cache; Valkey, a BSD-licensed Redis fork) and
# caddy (TLS with an automatic certificate). Caddy only starts with the "tls"
@@ -14,8 +23,7 @@
# Caddy's certificates. `docker compose down -v` deletes all of them.
x-app: &app
- build: .
- image: lalabase:local
+ image: ghcr.io/lalabase/lalabase:${LALABASE_VERSION:-2026.10.1}
restart: unless-stopped
env_file: .env
environment: &app-env
diff --git a/lib/lalabase/release.rb b/lib/lalabase/release.rb
index 3dd6d67..00a0e94 100644
--- a/lib/lalabase/release.rb
+++ b/lib/lalabase/release.rb
@@ -40,6 +40,12 @@ module Lalabase
}.freeze
FIRST_RELEASE = 'First public release.'
UNSORTED = '### Unsorted (move or delete before publishing)'
+ # The image .github/workflows/docker-release.yml publishes for each release.
+ IMAGE = 'ghcr.io/lalabase/lalabase'
+ # The line of compose.yml that names the image of its release. prepare
+ # writes the version into it and publish holds it against the version, so
+ # a checked-out tag pulls the image built from that tag.
+ COMPOSE_IMAGE = /^(?<lead>\s*image: #{Regexp.escape(IMAGE)}:\$\{LALABASE_VERSION:-)(?<version>[^}]*)(?<tail>\})$/
module_function
@@ -74,6 +80,27 @@ module Lalabase
# The release notes as GitHub shows them: the section without HTML comments.
def notes(section) = section.gsub(/^<!--.*?-->\n*/m, '').strip
+ # The release compose.yml pulls, or nil unless it names the image exactly once.
+ def compose_version(text)
+ versions = text.to_s.to_enum(:scan, COMPOSE_IMAGE).map { Regexp.last_match[:version] }
+ versions.first if versions.one?
+ end
+
+ def with_compose_version(text, version)
+ count = text.to_s.scan(COMPOSE_IMAGE).size
+ raise ArgumentError, "compose.yml names #{IMAGE} #{count} times, not once" unless count == 1
+
+ text.sub(COMPOSE_IMAGE) { "#{Regexp.last_match[:lead]}#{version}#{Regexp.last_match[:tail]}" }
+ end
+
+ # A diff of compose.yml (`git diff -U0`) that changes nothing but the
+ # version of the release image: what prepare does, and nothing a
+ # self-hoster has to compare with their copy.
+ def version_only_diff?(diff)
+ changed = diff.to_s.lines.drop_while { |line| !line.start_with?('@@') }.grep(/\A[-+]/)
+ changed.any? && changed.all? { |line| COMPOSE_IMAGE.match?(line[1..].chomp) }
+ end
+
# Titles marked breaking ("feat(api)!: …"), as upgrade notes.
def breaking_changes(pull_requests)
pull_requests.filter_map do |pr|
diff --git a/script/docker_check b/script/docker_check
new file mode 100755
index 0000000..e878d00
--- /dev/null
+++ b/script/docker_check
@@ -0,0 +1,100 @@
+#!/usr/bin/env bash
+# Boots compose.yml with an image that is already there and checks the
+# install a self-hoster would get, then removes the stack and its volumes.
+# Run by both Docker workflows: docker.yml with the image it built from the
+# pull request (COMPOSE_FILE=compose.yml:compose.build.yml), docker-release.yml
+# with the release image before it pushes it (LALABASE_VERSION).
+#
+# HOST=lalabase-ci.test:3000 script/docker_check
+#
+# HOST is a host that is not localhost: the health check in compose.yml calls
+# /up on localhost, so it passes only through the /up exemptions from the
+# host check and the https redirect. The pages are asked for with this host.
+#
+# It writes .env and deletes the stack's volumes: for a CI runner, never for
+# a checkout with an instance of its own.
+
+set -euo pipefail
+
+: "${HOST:?Set HOST, e.g. lalabase-ci.test:3000}"
+cd "$(dirname "$0")/.."
+if [ -e .env ] && [ "${CI:-}" != "true" ]; then
+ echo "There is a .env here, and this check overwrites it and deletes the volumes. Run it on a CI runner." >&2
+ exit 1
+fi
+
+finish() {
+ status=$?
+ if [ "$status" -ne 0 ]; then
+ echo "::group::Logs"
+ docker compose logs --no-color --tail 200 || true
+ echo "::endgroup::"
+ fi
+ docker compose down -v || true
+ exit "$status"
+}
+trap finish EXIT
+
+# The .env a self-hoster would write without a certificate: fresh secrets,
+# plain http, no Caddy. Plus the DATABASE_URL line the guide for installs
+# without Docker shows: compose.yml must win over it.
+cp .env.docker.example .env
+sed -i.bak \
+ -e "s/^LALABASE_HOST=.*/LALABASE_HOST=${HOST}/" \
+ -e '/^COMPOSE_PROFILES=/d' \
+ .env
+rm -f .env.bak
+{
+ echo "LALABASE_FORCE_SSL=false"
+ echo "SECRET_KEY_BASE=$(openssl rand -hex 64)"
+ echo "ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=$(openssl rand -hex 32)"
+ echo "ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=$(openssl rand -hex 32)"
+ echo "ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=$(openssl rand -hex 32)"
+ echo "POSTGRES_PASSWORD=$(openssl rand -hex 24)"
+ echo "DATABASE_URL=postgres://lalabase:wrong@db:5432/lalabase_production"
+} >> .env
+
+# --pull never: the image under test is the one built in this run. A pull
+# would test whatever the registry holds under that name. The database and
+# Valkey come from their registries, so they are pulled first.
+docker compose pull --quiet db redis
+docker compose up -d --pull never --wait --wait-timeout 300
+
+echo "Health check, a page that needs the database, a foreign host"
+curl -fsS -o /dev/null http://localhost:3000/up
+curl -fsS -o /dev/null -H "Host: ${HOST}" http://localhost:3000/users/sign_in
+code=$(curl -s -o /dev/null -w '%{http_code}' -H 'Host: evil.example' http://localhost:3000/users/sign_in)
+test "$code" = "403" || { echo "::error::A foreign host got $code instead of 403"; exit 1; }
+
+echo "The data lands in the database the backups dump"
+found=$(docker compose exec -T db psql -U lalabase -d lalabase -tAc \
+ "SELECT 1 FROM information_schema.tables WHERE table_name = 'schema_migrations'")
+test "$found" = "1"
+
+# The compiled CSS carries its font URLs with the asset host burnt in. A
+# self-hosted instance must not load anything from our host. grep exits 1 for
+# "no match"; 0 is a match and 2 a failed search, both red.
+echo "No asset names our host"
+rc=0
+docker compose exec -T web grep -rl 'lalabase.com' public/assets || rc=$?
+if [ "$rc" -ne 1 ]; then
+ echo "::error::grep exited $rc: assets name lalabase.com (0) or could not be searched (2)"
+ exit 1
+fi
+
+echo "First admin"
+docker compose exec -T \
+ -e LALABASE_ADMIN_PASSWORD=ci-check-password-123 \
+ web bin/rails lalabase:setup
+
+# The worker stays up: Solid Queue exits at boot when the pool is smaller
+# than its threads, and compose would just keep restarting it.
+echo "Worker is running"
+sleep 10
+test "$(docker compose ps worker --format '{{.State}}')" = "running"
+# Not a pipe into grep -q: grep stops at the first match, and with pipefail
+# the cut-off logs command would turn a passing check red.
+grep -q 'Started Worker' <<<"$(docker compose logs worker)"
+
+echo "Docker check passed."
diff --git a/script/release b/script/release
index 6e0ea30..5c4a097 100755
--- a/script/release
+++ b/script/release
@@ -4,16 +4,21 @@
# Cuts a release of the core, in three steps:
#
# script/release draft print the next version and draft notes, change nothing
-# script/release prepare [VERSION] write the draft into CHANGELOG.md (then edit, PR, merge)
+# script/release prepare [VERSION] write the draft into CHANGELOG.md and the version into
+# compose.yml (then edit, PR, merge)
# script/release publish VERSION tag main and create the GitHub release from CHANGELOG.md
#
# draft changes nothing. prepare refuses a version that is already in
# CHANGELOG.md, and marks the section with the commit it was drafted from.
+# The GitHub release starts .github/workflows/docker-release.yml, which builds
+# the image that compose.yml of the tag pulls.
#
# publish runs on an up-to-date main and refuses while:
# - CHANGELOG.md is not in shape (Lalabase::Release.problems), or Unreleased has lines;
+# - compose.yml does not pull the image of this version;
# - a pull request merged since the mark is not named in the section as (#N);
-# a pull request into main that changed only CHANGELOG.md is exempt;
+# a pull request into main that changed only CHANGELOG.md (and the image
+# version in compose.yml) is exempt;
# - a commit on main's first-parent line is no pull request (a rebase merge, a
# direct push).
# --anyway skips the last two, after you read what they name.
@@ -36,12 +41,16 @@ require_relative '../lib/lalabase/release'
ROOT = File.expand_path('..', __dir__)
CHANGELOG = File.join(ROOT, 'CHANGELOG.md')
+COMPOSE = File.join(ROOT, 'compose.yml')
# The release date, in UTC like the application (no Rails here to ask).
TODAY = Time.now.utc.to_date
ENV_EXAMPLES = %w[.env.example .env.docker.example .env.production.example].freeze
+# compose.yml changes with every release (the image version prepare writes);
+# its hint is only for a change beyond that line, see upgrade_hints.
WATCHED = {
- 'Dockerfile' => 'The Dockerfile changed: rebuild the image.',
+ 'Dockerfile' => 'The Dockerfile changed: if you build the image yourself (compose.build.yml), rebuild it.',
'compose.yml' => 'compose.yml changed: compare it with your copy before `docker compose up -d`.',
+ 'compose.build.yml' => 'compose.build.yml changed: if you build the image yourself, compare it with your copy.',
'lib/lalabase/data_backfills.rb' => 'The data backfills changed; they run by themselves when the container starts ' \
'(without Docker: `bin/rails lalabase:data_backfills`).'
}.freeze
@@ -102,9 +111,19 @@ def upgrade_hints(tag)
hints = new_env_keys(tag).map { |key| "New environment variable `#{key}` (see the example files)." }
changed = sh('git', 'diff', '--name-only', "#{tag}..HEAD").split("\n")
+ changed.delete('compose.yml') if Lalabase::Release.version_only_diff?(sh('git', 'diff', '-U0', "#{tag}..HEAD", '--', 'compose.yml'))
hints + WATCHED.filter_map { |path, hint| hint if changed.include?(path) }
end
+# What prepare leaves for the notes pull request besides CHANGELOG.md: the
+# version of the release image in compose.yml. A commit (or pull request)
+# that changed nothing else needs no line in the notes.
+def notes_only?(from, to)
+ names = sh('git', 'diff', '--name-only', from, to).split("\n")
+ names.delete('compose.yml') if Lalabase::Release.version_only_diff?(sh('git', 'diff', '-U0', from, to, '--', 'compose.yml'))
+ names == ['CHANGELOG.md']
+end
+
def draft_block(version)
tag = last_release
prs = tag ? titles(merged_numbers("#{tag}..HEAD")) : []
@@ -134,9 +153,15 @@ def prepare(version)
changelog = File.read(CHANGELOG)
abort "CHANGELOG.md has a section for #{version} already: edit it, do not prepare it twice." if Lalabase::Release.section(changelog, version)
+ compose = begin
+ Lalabase::Release.with_compose_version(File.read(COMPOSE), version)
+ rescue ArgumentError => e
+ abort "#{e.message}: nothing was changed."
+ end
File.write(CHANGELOG, Lalabase::Release.insert(changelog, draft_block(version)))
- puts "CHANGELOG.md has a draft for #{version}. Edit it (drop what a self-hoster does not need,"
- puts 'write the upgrade notes), open a pull request, merge it, then:'
+ File.write(COMPOSE, compose)
+ puts "CHANGELOG.md has a draft for #{version}, and compose.yml pulls its image. Edit the draft"
+ puts '(drop what a self-hoster does not need, write the upgrade notes), open a pull request, merge it, then:'
puts " script/release publish #{version}"
end
@@ -158,7 +183,7 @@ def unaccounted(section)
number = Lalabase::Release.pull_request_numbers([subject]).first
next direct << "#{sha[0, 10]} #{subject}" unless number
- exempt << number if sh('git', 'diff', '--name-only', "#{sha}^", sha).split("\n") == ['CHANGELOG.md']
+ exempt << number if notes_only?("#{sha}^", sha)
end
[merged_numbers(range) - exempt - Lalabase::Release.mentioned_numbers(section), direct]
end
@@ -173,6 +198,11 @@ def check_publishable!(version, anyway:)
abort "CHANGELOG.md is not in shape:\n #{problems.join("\n ")}" unless problems.empty?
section = Lalabase::Release.section(changelog, version)
abort "CHANGELOG.md on main has no section for #{version}: run prepare and merge it first." if section.nil?
+ pulled = Lalabase::Release.compose_version(File.read(COMPOSE))
+ unless pulled == version
+ abort "compose.yml on main pulls #{pulled ? "the image of #{pulled}" : "no single #{Lalabase::Release::IMAGE}"}, " \
+ "not #{version}: a tag of it would install another release. prepare writes the version; merge that first."
+ end
reasons = []
reasons << 'Unreleased is not empty: move its lines into the release (a pull request) or wait with them.' unless Lalabase::Release.section_body(changelog, Lalabase::Release::UNRELEASED).empty?
missing, direct = anyway ? [[], []] : unaccounted(section)
@@ -218,6 +248,8 @@ def create_release(version, section)
stdin_data: Lalabase::Release.notes(section))
end
puts "Released #{version}: tag on origin, GitHub release created."
+ puts "The workflow Docker release now builds #{Lalabase::Release::IMAGE}:#{version} (gh run list --workflow docker-release.yml);"
+ puts 'it adds the image to the release notes once the image is pushed.'
end
def publish(version, anyway:)
diff --git a/spec/architecture/changelog_guard_spec.rb b/spec/architecture/changelog_guard_spec.rb
index 74c01d3..4d26cc7 100644
--- a/spec/architecture/changelog_guard_spec.rb
+++ b/spec/architecture/changelog_guard_spec.rb
@@ -58,6 +58,15 @@ RSpec.describe 'CHANGELOG.md', type: :model do
)
end
+ # compose.yml of a tag pulls the image built from that tag. prepare writes
+ # both files, publish holds the version against compose.yml; a hand edit of
+ # one of them shows here, before a release is cut from it.
+ it 'goes with a compose.yml that pulls the image of the newest release' do
+ newest = Rails.root.join('CHANGELOG.md').read.match(Lalabase::Release::VERSION_HEADING)[:version]
+
+ expect(Lalabase::Release.compose_version(Rails.root.join('compose.yml').read)).to eq(newest)
+ end
+
it 'accepts a release in the right shape' do
good = "# Changelog\n\n## [Unreleased]\n\n## [2026.11.0] - 2026-11-20\n\n### Upgrade notes\n\n- None.\n\n" \
"## [2026.10.0] - 2026-10-30\n\n### Upgrade notes\n\n- None.\n"
diff --git a/spec/lib/lalabase/release_script_spec.rb b/spec/lib/lalabase/release_script_spec.rb
index cf93d54..54212cc 100644
--- a/spec/lib/lalabase/release_script_spec.rb
+++ b/spec/lib/lalabase/release_script_spec.rb
@@ -90,6 +90,23 @@ RSpec.describe 'script/release' do
git('push', '-q', 'origin', 'main')
end
+ def compose_with(version, restart: 'unless-stopped')
+ "x-app: &app\n image: ghcr.io/lalabase/lalabase:${LALABASE_VERSION:-#{version}}\n restart: #{restart}\n"
+ end
+
+ def compose_file = File.join(work, 'compose.yml')
+
+ # A pull request that writes the given files (path => content), merged.
+ def pull_request_writing(number, title, files)
+ git('switch', '-q', '-c', "pr-#{number}")
+ files.each { |path, content| File.write(File.join(work, path), content) }
+ git('commit', '-q', '-am', title)
+ git('switch', '-q', 'main')
+ git('merge', '-q', '--no-ff', "pr-#{number}", '-m', "Merge pull request ##{number} from someone/pr-#{number}")
+ git('push', '-q', 'origin', 'main')
+ record_pull_request(number, title)
+ end
+
before do
FileUtils.mkdir_p([File.join(@tmp, 'bin'), state])
File.write(File.join(@tmp, 'bin/gh'), fake_gh)
@@ -104,6 +121,7 @@ RSpec.describe 'script/release' do
FileUtils.cp(File.join(root, 'script/release'), File.join(work, 'script/release'))
FileUtils.cp(File.join(root, 'lib/lalabase/release.rb'), File.join(work, 'lib/lalabase/release.rb'))
File.write(File.join(work, 'CHANGELOG.md'), "# Changelog\n\n## [Unreleased]\n")
+ File.write(File.join(work, 'compose.yml'), compose_with('2026.9.0'))
git('switch', '-q', '-c', 'main')
git('add', '-A')
git('commit', '-q', '-m', 'init')
@@ -205,6 +223,35 @@ RSpec.describe 'script/release' do
expect(out).to include('not newer than the last release 2026.9.0')
end
+ # A checked-out tag pulls the image built from it: compose.yml of the tag
+ # names its version, and prepare is what writes it.
+ it 'writes the version into compose.yml on prepare' do
+ merge_pull_request(5, 'feat: one task')
+
+ out, ok = release('prepare', '2026.10.0')
+
+ expect(ok).to be(true), out
+ expect(File.read(compose_file)).to eq(compose_with('2026.10.0'))
+ end
+
+ it 'refuses to prepare without the release image in compose.yml, and changes nothing' do
+ pull_request_writing(5, 'feat: build here', 'compose.yml' => "services:\n web:\n build: .\n")
+
+ out, ok = release('prepare', '2026.10.0')
+
+ expect(ok).to be(false)
+ expect(out).to include('names ghcr.io/lalabase/lalabase 0 times', 'nothing was changed')
+ expect(File.read(File.join(work, 'CHANGELOG.md'))).not_to include('2026.10.0')
+ end
+
+ it 'tells to compare compose.yml only for a change beyond the image version' do
+ pull_request_writing(5, 'chore: next image', 'compose.yml' => compose_with('2026.9.1'))
+ expect(release('draft').first).not_to include('compose.yml changed')
+
+ pull_request_writing(6, 'fix: restart', 'compose.yml' => compose_with('2026.9.1', restart: 'always'))
+ expect(release('draft').first).to include('compose.yml changed: compare it with your copy')
+ end
+
context 'when the notes are on main' do
before do
merge_pull_request(5, 'feat: one task')
@@ -216,6 +263,30 @@ RSpec.describe 'script/release' do
git('push', '-q', 'origin', 'main')
end
+ it 'refuses to publish while compose.yml pulls another release, before tagging anything' do
+ pull_request_writing(9, 'chore: back to the old image', 'compose.yml' => compose_with('2026.9.0'))
+
+ out, ok = release('publish', '2026.10.0', '--anyway')
+
+ expect(ok).to be(false)
+ expect(out).to include('compose.yml on main pulls the image of 2026.9.0, not 2026.10.0')
+ expect(git('tag', '--list', '2026.10.0').strip).to eq('')
+ end
+
+ # The notes pull request (#7) changed the image version too and needs no
+ # line. One that changes compose.yml beyond it is code and needs one.
+ it 'wants a line for a notes pull request that also changed compose.yml beyond the version' do
+ notes = File.read(File.join(work, 'CHANGELOG.md'))
+ pull_request_writing(9, 'docs: notes and a restart',
+ 'CHANGELOG.md' => notes.sub('- one task (#5)', "- one task (#5)\n- more"),
+ 'compose.yml' => compose_with('2026.10.0', restart: 'always'))
+
+ out, ok = release('publish', '2026.10.0')
+
+ expect(ok).to be(false)
+ expect(out).to include('not in the release notes: #9')
+ end
+
# A pull request merged between prepare and publish would be in no release (finding 2).
it 'stops when a pull request was merged after the notes, unless told --anyway' do
merge_pull_request(8, 'fix: late one')
diff --git a/spec/lib/lalabase/release_spec.rb b/spec/lib/lalabase/release_spec.rb
index aed0981..7e68b40 100644
--- a/spec/lib/lalabase/release_spec.rb
+++ b/spec/lib/lalabase/release_spec.rb
@@ -158,6 +158,54 @@ RSpec.describe Lalabase::Release do
end
end
+ describe 'the release image in compose.yml' do
+ let(:compose) do
+ "x-app: &app\n image: ghcr.io/lalabase/lalabase:${LALABASE_VERSION:-2026.10.1}\n restart: unless-stopped\n"
+ end
+
+ it 'reads the version compose.yml pulls' do
+ expect(described_class.compose_version(compose)).to eq('2026.10.1')
+ end
+
+ it 'reads nothing from a file without the image, with it twice, or with another image' do
+ expect(described_class.compose_version("services:\n web:\n build: .\n")).to be_nil
+ expect(described_class.compose_version(compose * 2)).to be_nil
+ expect(described_class.compose_version(compose.sub('lalabase/lalabase', 'someone/lalabase'))).to be_nil
+ end
+
+ it 'writes a new version into that one line and leaves the rest' do
+ result = described_class.with_compose_version(compose, '2026.11.0')
+
+ expect(result).to eq(compose.sub('2026.10.1', '2026.11.0'))
+ end
+
+ it 'refuses to write when the line is missing or there twice' do
+ expect { described_class.with_compose_version("services: {}\n", '2026.11.0') }.to raise_error(ArgumentError, /0 times/)
+ expect { described_class.with_compose_version(compose * 2, '2026.11.0') }.to raise_error(ArgumentError, /2 times/)
+ end
+
+ describe '.version_only_diff?' do
+ def diff(*lines) = "diff --git a/compose.yml b/compose.yml\n--- a/compose.yml\n+++ b/compose.yml\n@@ -2 +2 @@\n#{lines.join("\n")}\n"
+
+ let(:old_line) { '- image: ghcr.io/lalabase/lalabase:${LALABASE_VERSION:-2026.10.1}' }
+ let(:new_line) { '+ image: ghcr.io/lalabase/lalabase:${LALABASE_VERSION:-2026.11.0}' }
+
+ it 'is true for a diff that only moves the version, as prepare does' do
+ expect(described_class.version_only_diff?(diff(old_line, new_line))).to be(true)
+ end
+
+ it 'is false as soon as another line changes, or nothing changes' do
+ expect(described_class.version_only_diff?(diff(old_line, new_line, '+ pull_policy: always'))).to be(false)
+ expect(described_class.version_only_diff?(diff('- restart: always', '+ restart: unless-stopped'))).to be(false)
+ expect(described_class.version_only_diff?('')).to be(false)
+ end
+
+ it 'does not take the file names of the diff header for changed lines' do
+ expect(described_class.version_only_diff?(diff(new_line))).to be(true)
+ end
+ end
+ end
+
describe '.mentioned_numbers' do
it 'reads the pull requests a section names as (#N), and nothing else' do
expect(described_class.mentioned_numbers("- one (#5)\n- two (#12), see #7\n- one again (#5)")).to eq([5, 12])