Test runner: shared base image for acceptance containers, log installed apt packages
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
23fbc6f302
commit
d0e7cea117
9 files changed
+50
-10
No files matched your search
+1
-1
@@ -38,4 +38,4 @@ CODECRAFT_LOG_FORMAT=
|
|||||||
# Optional limits per environment and the image used when .factory/setup.json names none:
|
# Optional limits per environment and the image used when .factory/setup.json names none:
|
||||||
#RUNNER_MEMORY=2g
|
#RUNNER_MEMORY=2g
|
||||||
#RUNNER_CPUS=2
|
#RUNNER_CPUS=2
|
||||||
#RUNNER_DEFAULT_IMAGE=node:22-bookworm
|
#RUNNER_DEFAULT_IMAGE=git.familie-zink.org/zink/codecraft-testbase:latest
|
||||||
@@ -5,6 +5,11 @@ until 1.0, minor versions may contain breaking changes.
|
|||||||
|
|
||||||
## [v202611-00076] – 2026-11-20
|
## [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
|
### 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`).
|
- **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`).
|
||||||
|
|||||||
@@ -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`
|
inherits changes from an earlier one, and editing a listed source rebuilds it. `"cache": false`
|
||||||
disables caching; `DELETE /v1/cache/<project>` on the runner clears one project.
|
disables caching; `DELETE /v1/cache/<project>` 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
|
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
|
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
|
host. Without the runner, or without a `setup.json`, nothing changes. Note that the runner holds
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ services:
|
|||||||
RUNNER_FACTORY_DIR: /factory
|
RUNNER_FACTORY_DIR: /factory
|
||||||
RUNNER_MEMORY: ${RUNNER_MEMORY:-2g}
|
RUNNER_MEMORY: ${RUNNER_MEMORY:-2g}
|
||||||
RUNNER_CPUS: ${RUNNER_CPUS:-2}
|
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
|
HOME: /tmp
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
|||||||
+1
-1
@@ -71,7 +71,7 @@ services:
|
|||||||
RUNNER_FACTORY_DIR: /factory
|
RUNNER_FACTORY_DIR: /factory
|
||||||
RUNNER_MEMORY: ${RUNNER_MEMORY:-2g}
|
RUNNER_MEMORY: ${RUNNER_MEMORY:-2g}
|
||||||
RUNNER_CPUS: ${RUNNER_CPUS:-2}
|
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
|
HOME: /tmp
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -94,6 +94,10 @@ if (( image )); then
|
|||||||
run docker buildx build --builder "$BUILDER" --platform "$PLATFORMS" \
|
run docker buildx build --builder "$BUILDER" --platform "$PLATFORMS" \
|
||||||
--build-arg GIT_COMMIT="$(git rev-parse --short HEAD)" --build-arg CODECRAFT_VERSION="$version" \
|
--build-arg GIT_COMMIT="$(git rev-parse --short HEAD)" --build-arg CODECRAFT_VERSION="$version" \
|
||||||
"${tags[@]}" --push .
|
"${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
|
fi
|
||||||
|
|
||||||
step "Creating the Gitea release $tag"
|
step "Creating the Gitea release $tag"
|
||||||
|
|||||||
@@ -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
|
/// 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.
|
/// `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
|
const ENTRY_SCRIPT: &str = r#"cd /app
|
||||||
hit=0
|
hit=0
|
||||||
if [ -d /cache ]; then
|
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
|
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
|
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
|
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
|
if [ -n "$CC_INSTALL" ]; then sh -c "$CC_INSTALL" || exit 1; fi
|
||||||
echo "[runner] install took $(( $(date +%s) - t0 )) s"
|
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
|
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
|
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
|
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),
|
ports: (lo, hi),
|
||||||
memory: std::env::var("RUNNER_MEMORY").unwrap_or_else(|_| "2g".into()),
|
memory: std::env::var("RUNNER_MEMORY").unwrap_or_else(|_| "2g".into()),
|
||||||
cpus: std::env::var("RUNNER_CPUS").unwrap_or_else(|_| "2".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)),
|
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(),
|
me: std::env::var("RUNNER_SELF").or_else(|_| std::env::var("HOSTNAME")).unwrap_or_default(),
|
||||||
envs: Mutex::new(HashMap::new()),
|
envs: Mutex::new(HashMap::new()),
|
||||||
@@ -458,7 +462,7 @@ async fn create(r: &Arc<Runner>, id: &str, req: &StartReq, work: &Path) -> Resul
|
|||||||
r.envs.lock().unwrap().get_mut(id).unwrap().containers.push(cname);
|
r.envs.lock().unwrap().get_mut(id).unwrap().containers.push(cname);
|
||||||
}
|
}
|
||||||
let image = if req.dockerfile.is_empty() {
|
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 {
|
} else {
|
||||||
let tag = format!("cc-run-{id}");
|
let tag = format!("cc-run-{id}");
|
||||||
let df = work.join(&req.dockerfile);
|
let df = work.join(&req.dockerfile);
|
||||||
@@ -548,7 +552,7 @@ async fn create(r: &Arc<Runner>, id: &str, req: &StartReq, work: &Path) -> Resul
|
|||||||
tokio::time::sleep(Duration::from_millis(700)).await;
|
tokio::time::sleep(Duration::from_millis(700)).await;
|
||||||
}
|
}
|
||||||
// Report what the cache brought: seed hit/miss, install time, total time until the app answered.
|
// Report what the cache brought: seed hit/miss, install time, total time until the app answered.
|
||||||
let facts: Vec<String> = 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<String> = 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 took = began.elapsed().as_secs();
|
||||||
let cache = if cached { "on" } else { "off" };
|
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("; "));
|
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<Runner>, id: &str, req: &StartReq, work: &Path) -> Resul
|
|||||||
Ok(Started { id: id.to_string(), port })
|
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 {
|
async fn logs(container: &str) -> String {
|
||||||
match Command::new("docker").args(["logs", "--tail", "400", container]).output().await {
|
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)),
|
Ok(o) => format!("{}{}", String::from_utf8_lossy(&o.stdout), String::from_utf8_lossy(&o.stderr)),
|
||||||
|
|||||||
+2
-2
@@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
export const WHATS_NEW: Record<string, { en: string[]; de: string[] }> = {
|
export const WHATS_NEW: Record<string, { en: string[]; de: string[] }> = {
|
||||||
"202611-00076": {
|
"202611-00076": {
|
||||||
en: ["Factory test runner: logs how long an environment took to start and whether the cache seed was a hit"],
|
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: protokolliert, wie lange eine Umgebung zum Start brauchte und ob der Cache-Seed getroffen hat"],
|
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": {
|
"202611-00075": {
|
||||||
en: ["Factory: the lamp of a phase being prepared now differs in colour from the accent in every theme"],
|
en: ["Factory: the lamp of a phase being prepared now differs in colour from the accent in every theme"],
|
||||||
|
|||||||
Reference in new issue
Block a user