Files
Heimdall/skills/compose-disposable-recipe/SKILL.md
T
arnaud.dartois 636154572b
Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Complete remaining Heimdall features and acceptance
Merge pull request #138

Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-06 11:14:49 +01:00

7.6 KiB

name, description
name description
compose-disposable-recipe Build and acceptance-test Heimdall changes in a disposable Docker Compose stack, isolated from deployed data and configuration.

Disposable Compose acceptance

Use this skill for every Heimdall behavior, deployment, or operational change. Read the relevant project skill too; for first administrator setup, use first-admin-bootstrap.

Safety and isolation

  • Build from the current source with a unique Compose project name. Do not test against the production hostname, database, image volumes, secrets, or credentials.
  • Put generated .env and secret files under a temporary directory outside the repository. Use synthetic test identities and cryptographically random local passwords.
  • Use an unused loopback host port and Compose-managed volumes whose names include the unique project name. Do not join production or shared networks.
  • Give each locally built acceptance image a project-unique tag, for example heimdall:<project>-acceptance; do not build under latest, local, or a tag that existed before the recipe. Use a temporary Compose override to set the unique image tag while preserving the source build context. Record all generated tags before starting.
  • Never use broad Docker cleanup such as docker system prune, docker image prune, or docker rmi $(docker images -q). Remove only the test project with docker compose -p <unique-name> down --volumes --remove-orphans.
  • After teardown, check that the project has no containers, volumes, or networks. For every locally built image tag, run docker image rm <exact-recipe-tag> if it exists, then verify docker image inspect <exact-recipe-tag> fails. Remove the temporary Compose override/env/source files. Do not remove shared upstream base images (for example PostgreSQL, .NET SDK, or MediaMTX) or images owned by another recipe/project.
  • Put teardown and exact-tag image removal in the same cleanup trap so both success and failure paths clean up. Do not reuse another acceptance recipe's locally built image: build a uniquely tagged image for this recipe and remove it in this recipe's cleanup path.
  • A recipe is not complete until every local application image tag created by that recipe has been removed and verified absent. docker compose down does not remove images. Apply this even when the behavioral assertion fails; keep generated upstream/base images and unrelated project images untouched.
  • These requirements apply to every Docker-based acceptance recipe, including SDK-only test containers, third-party mocks, one-shot helpers, and failure/partial-build paths. Such recipes must explicitly state whether they build any local images. If they build none, leave upstream images intact and still verify cleanup of project containers, volumes, and networks. If they build any local image (Heimdall or helper), record its unique tag before build and remove/verify it absent in the same EXIT cleanup trap, even if Compose startup or the build fails.
  • Cleanup must preserve the recipe's original exit status, attempt teardown and removal of every recorded tag independently, and report cleanup failures rather than silently declaring acceptance complete. Never use --rmi all because it can remove shared or unrelated images.
  • Mandatory local image cleanup: before the first build, enumerate and record every recipe-owned image tag that may be created (application, SDK/test harness, mock, one-shot helper). Use a unique tag for each locally built image. The EXIT trap must remove each exact recorded tag after project teardown and verify it is absent, regardless of whether build, startup, assertions, or teardown failed. Do not count an image as shared merely because its Dockerfile uses a shared base; only remove recipe-built tags, and retain upstream images. If no image is built locally, explicitly say so and verify the project resources are gone. Never leave recipe-created local images behind.

Required cleanup trap pattern

Use one EXIT trap installed before the first build or Compose start. Record exact local tags in an array before building; leave the array empty when the recipe builds no images. Cleanup actions must be independent so a failed Compose teardown cannot skip image and temporary-file cleanup. Preserve the original status and return a failure if any cleanup verification fails:

cleanup() {
  status=$?
  trap - EXIT
  cleanup_failed=0
  docker compose -p "$project" --env-file "$env_file" -f "$compose_file" \
    down --volumes --remove-orphans || cleanup_failed=1
  # Query all three resource kinds by Compose project label; do not infer
  # absence from `compose down`'s exit code alone.
  containers=$(docker ps -aq --filter "label=com.docker.compose.project=$project") || cleanup_failed=1
  volumes=$(docker volume ls -q --filter "label=com.docker.compose.project=$project") || cleanup_failed=1
  networks=$(docker network ls -q --filter "label=com.docker.compose.project=$project") || cleanup_failed=1
  [[ -z "$containers" && -z "$volumes" && -z "$networks" ]] || cleanup_failed=1
  for tag in "${local_image_tags[@]}"; do
    docker image rm "$tag" >/dev/null 2>&1 || true
    docker image inspect "$tag" >/dev/null 2>&1 && cleanup_failed=1
  done
  rm -rf -- "$temp_dir" || cleanup_failed=1
  if (( cleanup_failed )); then
    printf 'Disposable recipe cleanup failed for project %s\\n' "$project" >&2
    status=1
  fi
  exit "$status"
}
trap cleanup EXIT

The label queries must succeed and return empty results for containers, volumes, and networks. Do not include upstream images in local_image_tags. Recipe records must state the project name, whether local images were built, exact tags and absence checks (or explicitly “none”), plus project-resource cleanup results. A Docker recipe that reports teardown without the image-tag check is incomplete.

Acceptance workflow

  1. Inspect the Compose file and interpolation requirements before starting it. Generate a temporary environment file with unique database/JWT secrets and a distinct loopback port.

  2. Generate a temporary Compose image override. For example:

    services:
      heimdall:
        image: heimdall:${ACCEPTANCE_PROJECT}-central
    

    Put ACCEPTANCE_PROJECT=<unique-name> in the temporary env file and include both Compose files in every command. This overrides only the image tag; the checked-in source build context is retained. Use similarly unique tags for any Agent or helper image built from this checkout.

  3. Start the minimal Central + PostgreSQL stack from source with docker compose -p <unique-name> --env-file <temp-env> -f docker/docker-compose.yml -f <temp-image-override> up -d --build.

  4. Wait for the Central health check and probe the changed behavior through its HTTP/API/UI boundary. Exercise both the expected success path and the relevant rejection/restart path.

  5. Capture only sanitized logs or response codes needed to explain a failure. Never print passwords, tokens, connection strings, or full environment files.

  6. Install an EXIT trap before the first build/start operation. The trap must preserve the test command's exit status, run docker compose ... down --volumes --remove-orphans, verify no project containers/volumes/networks remain, remove every recorded project-unique locally built image tag and verify each is absent, then delete temporary environment, secrets, override, and copied-source files. Attempt each cleanup action even if an earlier cleanup action fails; surface any cleanup failure. Retain shared upstream/base images. Do not use Compose --rmi all or broad prune commands.

If Docker access is unavailable, request the required local permission or explain the blocker; do not substitute a production deployment or claim the recipe passed.