From affac4a2a0ed10ed480900f7e03d338b8ea013d4 Mon Sep 17 00:00:00 2001 From: Daniel Santillan Date: Mon, 21 Sep 2026 14:33:30 -0400 Subject: [PATCH] Add scripts/build-images.sh: build the two images and publish them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The images docker-compose.yml pulls are normally built by .gitea/workflows/docker-publish.yml, which needs a registered Actions runner and a PACKAGES_TOKEN secret. Neither exists on this instance's forge yet, so a host that pulls rather than builds has nothing to pull — and the two builds are easy to get wrong by hand: api builds from ./api, web from the repository root, because the web image compiles frontend/ inside its first stage. A wrong context produces an image that builds fine and then fails at runtime. One command now does both and pushes them: GITEA_TOKEN= ./scripts/build-images.sh TAG, REGISTRY, OWNER, PLATFORM, PUSH and API_TARGET (default vs coach) are all overridable, and the tags default to exactly what docker-compose.yml asks for. --- README.md | 8 +++- scripts/build-images.sh | 95 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100755 scripts/build-images.sh diff --git a/README.md b/README.md index c7a80b9..85b11e4 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,13 @@ the exercise media (~140 MB) once. The images are published to this fork's own registry by `.gitea/workflows/docker-publish.yml`: `git.dploy.lol/dsantillan/kuentagym-api` and `git.dploy.lol/dsantillan/kuentagym-web` (what `docker-compose.yml` pulls). Prefer building them yourself? Drop the `pull` step and run -`docker compose up -d --build` — you don't need Node or a build step locally either way. +`docker compose up -d --build` — you don't need Node or a build step locally either way. To build +them and publish them to that registry in one go (for a host that pulls rather than builds, and +for a forge whose Actions has no runner registered): + +```bash +GITEA_TOKEN= ./scripts/build-images.sh +``` > Want it reachable from your phone over the internet with passkeys? You'll need an HTTPS > domain — a two-line change in `.env`. See **[docs/SELF_HOSTING.md](docs/SELF_HOSTING.md)**. diff --git a/scripts/build-images.sh b/scripts/build-images.sh new file mode 100755 index 0000000..f0f3015 --- /dev/null +++ b/scripts/build-images.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +# +# Builds the two container images this project runs on — api and web — and (by default) pushes +# them to the registry `docker-compose.yml` pulls from, so a Dokploy/Portainer/compose deploy can +# pick them up without changing anything. +# +# ./scripts/build-images.sh # build + push :latest +# TAG=v1.4.0 ./scripts/build-images.sh # build + push a release tag +# PUSH=0 ./scripts/build-images.sh # build only (images stay local) +# API_TARGET=coach ./scripts/build-images.sh # the AI-Coach api image instead of the default +# +# Needs: docker with buildx available (any recent Docker), and for a push either a prior +# `docker login` or GITEA_TOKEN set to a token with the `write:package` scope. +# +# GITEA_TOKEN= ./scripts/build-images.sh +# +# Not to be confused with website/build-images.sh, which is unrelated: that one runs ffmpeg over +# the README screenshots. +# +# Why a script at all: the two images have different build contexts (api builds from ./api, web +# from the repository root because it compiles frontend/), and getting a context wrong produces an +# image that builds fine and then fails at runtime. `.gitea/workflows/docker-publish.yml` does the +# same two builds in CI — this is the same thing for the machine that is actually serving the app, +# for an instance whose forge has no Actions runner registered. +set -euo pipefail + +REGISTRY="${REGISTRY:-git.dploy.lol}" +OWNER="${OWNER:-dsantillan}" +TAG="${TAG:-latest}" +API_TARGET="${API_TARGET:-default}" +PUSH="${PUSH:-1}" +PLATFORM="${PLATFORM:-}" + +IMAGE_API="${REGISTRY}/${OWNER}/kuentagym-api" +IMAGE_WEB="${REGISTRY}/${OWNER}/kuentagym-web" + +# Run from the repository root whatever directory the script was called from. +cd "$(dirname "$0")/.." + +for tool in docker; do + command -v "$tool" >/dev/null || { echo "✗ $tool is not installed" >&2; exit 1; } +done +[ -f docker-compose.yml ] || { echo "✗ run this from a checkout of the repository" >&2; exit 1; } +echo "✓ docker $(docker version --format '{{.Server.Version}}' 2>/dev/null || echo '(server unreachable)')" + +# A push needs credentials. Logging in here rather than assuming saves the confusing +# "denied: requested access to the resource is denied" that a stale login produces. +if [ "$PUSH" = "1" ] && [ -n "${GITEA_TOKEN:-}" ]; then + echo "→ logging in to ${REGISTRY} as ${OWNER}" + printf '%s' "$GITEA_TOKEN" | docker login "$REGISTRY" -u "$OWNER" --password-stdin +fi + +# Shared by both builds. --platform is only passed when asked for: on a normal single-arch machine +# letting Docker build for the host is faster and cannot fail on a missing qemu binfmt. +build() { + local name="$1" context="$2" dockerfile="$3" image="$4"; shift 4 + echo + echo "→ building ${image}:${TAG} (context: ${context})" + # shellcheck disable=SC2086 + docker build \ + ${PLATFORM:+--platform "$PLATFORM"} \ + --file "$dockerfile" \ + --tag "${image}:${TAG}" \ + "$@" \ + "$context" + if [ "$PUSH" = "1" ]; then + echo "→ pushing ${image}:${TAG}" + docker push "${image}:${TAG}" + fi +} + +# The api image carries no AI runtime by default — the target every instance has always had. The +# coach target adds the provider SDKs and the sandboxed runtimes, and is a much larger image; see +# the Dockerfile and docs/AI_COACH.md. +build api ./api api/Dockerfile "$IMAGE_API" --target "$API_TARGET" + +# web compiles the React app inside the image (stage 1) and serves it from nginx (stage 2), which +# is why its context is the repository root: it needs frontend/ and api/coach/core/. +build web . web/Dockerfile "$IMAGE_WEB" + +echo +echo "✓ done — ${IMAGE_API}:${TAG}, ${IMAGE_WEB}:${TAG}" +if [ "$PUSH" = "1" ]; then + echo + echo "These are exactly what docker-compose.yml asks for, so a redeploy on the host that runs it" + echo "pulls them straight away:" + echo " docker compose pull && docker compose up -d" + echo "In Dokploy: redeploy the stack. Keep the ./data bind mount where it is — the profiles," + echo "workouts and weigh-ins live there." +else + echo + echo "PUSH=0: the images are local only. Either push them later with" + echo " TAG=${TAG} ./scripts/build-images.sh" + echo "or let compose build them in place: docker compose up -d --build" +fi