From d0e7cea11741fc02a38e12c44f40afde035c1bde Mon Sep 17 00:00:00 2001 From: Richard Zink Date: Fri, 20 Nov 2026 20:33:59 +0100 Subject: [PATCH] Test runner: shared base image for acceptance containers, log installed apt packages Co-Authored-By: Claude Sonnet 5.5 --- .env.example | 2 +- CHANGELOG.md | 5 +++++ README.md | 6 +++++- docker-compose.release.yml | 2 +- docker-compose.yml | 2 +- docker/testbase/Dockerfile | 14 ++++++++++++++ scripts/release.sh | 4 ++++ server/src/testrunner.rs | 21 +++++++++++++++++---- web/src/whatsnew.ts | 4 ++-- 9 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 docker/testbase/Dockerfile diff --git a/.env.example b/.env.example index 9e584db..034686c 100644 --- a/.env.example +++ b/.env.example @@ -38,4 +38,4 @@ CODECRAFT_LOG_FORMAT= # Optional limits per environment and the image used when .factory/setup.json names none: #RUNNER_MEMORY=2g #RUNNER_CPUS=2 -#RUNNER_DEFAULT_IMAGE=node:22-bookworm +#RUNNER_DEFAULT_IMAGE=git.familie-zink.org/zink/codecraft-testbase:latest diff --git a/CHANGELOG.md b/CHANGELOG.md index a0939e9..05beecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ until 1.0, minor versions may contain breaking changes. ## [v202611-00076] – 2026-11-20 +### Added + +- **Shared base image for acceptance containers** (`git.familie-zink.org/zink/codecraft-testbase`, built from `docker/testbase/Dockerfile` by the release script): Node 24, Python 3, gcc/g++/make/cmake, Chromium with Playwright and common tools (git, curl, e2fsprogs, xz, zsh, sudo, jq, …). It is the runner's default image (`RUNNER_DEFAULT_IMAGE`), so setups that installed these again and again start faster; plain `node:24-bookworm` is the fallback if it cannot be pulled. Projects with their own `image` or `dockerfile` are unchanged. +- The runner also logs the apt packages an environment's setup installed (`apt installed: …`), to see what the base image still lacks. + ### Changed - **Test runner: the cache is now visible.** The runner logs for every environment how long it took until the app answered, whether the seed was a hit or a miss, and how long `install` took (e.g. `test env abc (git-…-penguin31) ready after 42 s; cache on; seed 07be…: hit; install took 3 s`). diff --git a/README.md b/README.md index 26d28ca..609129c 100644 --- a/README.md +++ b/README.md @@ -391,7 +391,11 @@ directories, and copied into a fresh container only while that key matches – s inherits changes from an earlier one, and editing a listed source rebuilds it. `"cache": false` disables caching; `DELETE /v1/cache/` on the runner clears one project. -`image` defaults to `RUNNER_DEFAULT_IMAGE`; `"dockerfile": "path"` builds the image from the +`image` defaults to `RUNNER_DEFAULT_IMAGE`, by default the shared base image +`codecraft-testbase` (Node 24, Python 3, gcc/cmake, Chromium with Playwright and common tools; see +`docker/testbase/Dockerfile`; plain Node 24 is the fallback when it cannot be pulled). The runner logs +per environment the start time, the seed hit/miss and the apt packages the setup installed. +The image can be changed per project with `"image"`; `"dockerfile": "path"` builds the image from the repository instead; helper services are reachable by their name. Containers run without extra capabilities, with memory/CPU/process limits (`RUNNER_MEMORY`, `RUNNER_CPUS`), and cannot see the host. Without the runner, or without a `setup.json`, nothing changes. Note that the runner holds diff --git a/docker-compose.release.yml b/docker-compose.release.yml index 6640728..14eac63 100644 --- a/docker-compose.release.yml +++ b/docker-compose.release.yml @@ -75,7 +75,7 @@ services: RUNNER_FACTORY_DIR: /factory RUNNER_MEMORY: ${RUNNER_MEMORY:-2g} RUNNER_CPUS: ${RUNNER_CPUS:-2} - RUNNER_DEFAULT_IMAGE: ${RUNNER_DEFAULT_IMAGE:-node:22-bookworm} + RUNNER_DEFAULT_IMAGE: ${RUNNER_DEFAULT_IMAGE:-git.familie-zink.org/zink/codecraft-testbase:latest} HOME: /tmp volumes: - /var/run/docker.sock:/var/run/docker.sock diff --git a/docker-compose.yml b/docker-compose.yml index 5cc375a..2e60b03 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -71,7 +71,7 @@ services: RUNNER_FACTORY_DIR: /factory RUNNER_MEMORY: ${RUNNER_MEMORY:-2g} RUNNER_CPUS: ${RUNNER_CPUS:-2} - RUNNER_DEFAULT_IMAGE: ${RUNNER_DEFAULT_IMAGE:-node:22-bookworm} + RUNNER_DEFAULT_IMAGE: ${RUNNER_DEFAULT_IMAGE:-git.familie-zink.org/zink/codecraft-testbase:latest} HOME: /tmp volumes: - /var/run/docker.sock:/var/run/docker.sock diff --git a/docker/testbase/Dockerfile b/docker/testbase/Dockerfile new file mode 100644 index 0000000..a0c9355 --- /dev/null +++ b/docker/testbase/Dockerfile @@ -0,0 +1,14 @@ +# Base image of the factory's throw-away acceptance containers (used when .factory/setup.json names no image). +# Node 24, Python 3, a C/C++ toolchain, the Chromium that Playwright needs, and the small tools +# that acceptance setups installed again and again (see the runner log "apt installed: ..."). +FROM node:24-bookworm +ENV DEBIAN_FRONTEND=noninteractive PIP_BREAK_SYSTEM_PACKAGES=1 PLAYWRIGHT_BROWSERS_PATH=/ms-playwright +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential cmake pkg-config git curl wget ca-certificates unzip xz-utils zip \ + e2fsprogs util-linux zsh sudo nano procps iproute2 netcat-openbsd jq sqlite3 \ + python3 python3-pip python3-venv \ + && rm -rf /var/lib/apt/lists/* \ + && npm install -g playwright \ + && playwright install --with-deps chromium \ + && rm -rf /var/lib/apt/lists/* /root/.npm \ + && chmod -R a+rX /ms-playwright diff --git a/scripts/release.sh b/scripts/release.sh index 4aa4183..611af20 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -94,6 +94,10 @@ if (( image )); then run docker buildx build --builder "$BUILDER" --platform "$PLATFORMS" \ --build-arg GIT_COMMIT="$(git rev-parse --short HEAD)" --build-arg CODECRAFT_VERSION="$version" \ "${tags[@]}" --push . + # Base image of the factory's acceptance containers (cached layers: cheap unless the Dockerfile changed). + step "Building and pushing ${REGISTRY}-testbase for $PLATFORMS" + run docker buildx build --builder "$BUILDER" --platform "$PLATFORMS" \ + -t "${REGISTRY}-testbase:latest" -t "${REGISTRY}-testbase:$tag" --push docker/testbase fi step "Creating the Gitea release $tag" diff --git a/server/src/testrunner.rs b/server/src/testrunner.rs index cdabf9d..56fc1f1 100644 --- a/server/src/testrunner.rs +++ b/server/src/testrunner.rs @@ -34,6 +34,8 @@ const CACHE_LABEL: &str = "codecraft.testrunner.cache=1"; /// What every environment container runs: link the shared directories, restore a matching seed, run /// `install`, store a new seed (only after a successful install, so it is pristine), start the app. +const FALLBACK_IMAGE: &str = "node:24-bookworm"; + const ENTRY_SCRIPT: &str = r#"cd /app hit=0 if [ -d /cache ]; then @@ -42,9 +44,11 @@ if [ -d /cache ]; then if [ -n "$CC_SEED_KEY" ]; then for p in $CC_SEED_PATHS; do if [ -e "/cache/seed/$CC_SEED_KEY/$p" ]; then mkdir -p "$(dirname "$p")" && cp -a "/cache/seed/$CC_SEED_KEY/$p" "$p" && hit=1 && echo "[runner] restored $p from the cache"; fi; done; fi fi if [ -n "$CC_SEED_KEY" ]; then if [ "$hit" = 1 ]; then echo "[runner] seed $CC_SEED_KEY: hit"; else echo "[runner] seed $CC_SEED_KEY: miss"; fi; fi -t0=$(date +%s) +t0=$(date +%s); st=$(date -u '+%Y-%m-%d %H:%M:%S') if [ -n "$CC_INSTALL" ]; then sh -c "$CC_INSTALL" || exit 1; fi echo "[runner] install took $(( $(date +%s) - t0 )) s" +pk=$(awk -v s="$st" '$3=="install" && ($1" "$2)>=s {sub(/:.*/,"",$4); print $4}' /var/log/dpkg.log 2>/dev/null | sort -u | head -40 | tr '\n' ' ') +if [ -n "$pk" ]; then echo "[runner] apt installed: $pk"; fi if [ -d /cache ] && [ -n "$CC_SEED_KEY" ] && [ ! -d "/cache/seed/$CC_SEED_KEY" ]; then t="/cache/seed/.tmp-$$"; rm -rf "$t"; mkdir -p "$t"; ok=1 for p in $CC_SEED_PATHS; do if [ -e "$p" ]; then mkdir -p "$t/$(dirname "$p")" && cp -a "$p" "$t/$p" || ok=0; fi; done @@ -355,7 +359,7 @@ pub async fn serve() -> Result<()> { ports: (lo, hi), memory: std::env::var("RUNNER_MEMORY").unwrap_or_else(|_| "2g".into()), cpus: std::env::var("RUNNER_CPUS").unwrap_or_else(|_| "2".into()), - default_image: std::env::var("RUNNER_DEFAULT_IMAGE").unwrap_or_else(|_| "node:22-bookworm".into()), + default_image: std::env::var("RUNNER_DEFAULT_IMAGE").unwrap_or_else(|_| "git.familie-zink.org/zink/codecraft-testbase:latest".into()), max_age: Duration::from_secs(60 * std::env::var("RUNNER_MAX_MINUTES").ok().and_then(|s| s.parse().ok()).unwrap_or(90)), me: std::env::var("RUNNER_SELF").or_else(|_| std::env::var("HOSTNAME")).unwrap_or_default(), envs: Mutex::new(HashMap::new()), @@ -458,7 +462,7 @@ async fn create(r: &Arc, id: &str, req: &StartReq, work: &Path) -> Resul r.envs.lock().unwrap().get_mut(id).unwrap().containers.push(cname); } let image = if req.dockerfile.is_empty() { - if req.image.is_empty() { r.default_image.clone() } else { req.image.clone() } + if req.image.is_empty() { default_image_or_fallback(&r.default_image).await } else { req.image.clone() } } else { let tag = format!("cc-run-{id}"); let df = work.join(&req.dockerfile); @@ -548,7 +552,7 @@ async fn create(r: &Arc, id: &str, req: &StartReq, work: &Path) -> Resul tokio::time::sleep(Duration::from_millis(700)).await; } // Report what the cache brought: seed hit/miss, install time, total time until the app answered. - let facts: Vec = logs(&app).await.lines().filter(|l| l.starts_with("[runner] seed ") || l.starts_with("[runner] install took")).map(|l| l.trim_start_matches("[runner] ").to_string()).collect(); + let facts: Vec = logs(&app).await.lines().filter(|l| l.starts_with("[runner] seed ") || l.starts_with("[runner] install took") || l.starts_with("[runner] apt installed")).map(|l| l.trim_start_matches("[runner] ").to_string()).collect(); let took = began.elapsed().as_secs(); let cache = if cached { "on" } else { "off" }; tracing::info!("test env {id} ({}) ready after {took} s; cache {cache}{}{}", req.cache_id, if facts.is_empty() { "" } else { "; " }, facts.join("; ")); @@ -572,6 +576,15 @@ async fn create(r: &Arc, id: &str, req: &StartReq, work: &Path) -> Resul Ok(Started { id: id.to_string(), port }) } +/// The shared base image; when it can neither be found nor pulled, fall back to plain Node so runs still work. +async fn default_image_or_fallback(img: &str) -> String { + if docker(&["image", "inspect", img]).await.is_ok() || docker(&["pull", "-q", img]).await.is_ok() { + return img.to_string(); + } + tracing::warn!("test runner: base image {img} is not available, using {FALLBACK_IMAGE}"); + FALLBACK_IMAGE.to_string() +} + async fn logs(container: &str) -> String { match Command::new("docker").args(["logs", "--tail", "400", container]).output().await { Ok(o) => format!("{}{}", String::from_utf8_lossy(&o.stdout), String::from_utf8_lossy(&o.stderr)), diff --git a/web/src/whatsnew.ts b/web/src/whatsnew.ts index cd90d72..bf78ae9 100644 --- a/web/src/whatsnew.ts +++ b/web/src/whatsnew.ts @@ -4,8 +4,8 @@ */ export const WHATS_NEW: Record = { "202611-00076": { - en: ["Factory test runner: logs how long an environment took to start and whether the cache seed was a hit"], - de: ["Factory-Test-Runner: protokolliert, wie lange eine Umgebung zum Start brauchte und ob der Cache-Seed getroffen hat"], + en: ["Factory test runner: shared base image (Node 24, Python, gcc, Chromium/Playwright) for acceptance containers; logs start time, cache hits and installed packages"], + de: ["Factory-Test-Runner: gemeinsames Basis-Image (Node 24, Python, gcc, Chromium/Playwright) für Abnahme-Container; protokolliert Startzeit, Cache-Treffer und installierte Pakete"], }, "202611-00075": { en: ["Factory: the lamp of a phase being prepared now differs in colour from the accent in every theme"],