agentsclimarketplace

Docker smoke test loop

Skill kjuhwa/skills-hub/skills/devops/docker-smoke-test-loop

Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.

Install
npx -y skills add kjuhwa/skills-hub --skill docker-smoke-test-loop

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Run a one-shot docker container, tail its logs for a readiness sentinel, then fire an integration test against the exposed port - with layered fallbacks when the CLI is unavailable.

SKILL.md

3.4 KB, as published. Nobody here has run it

Docker smoke-test loop

When to use

  • CI needs to verify a freshly built image actually boots and accepts connections.
  • You have a sentinel line your server prints on ready (e.g. CRAFT_SERVER_URL=...).
  • Want cleanup guaranteed even on failure.
  • Different CI environments have different tooling (sometimes no CLI, no node, no nc).

How it works

  1. Deterministic container name + token: CONTAINER_NAME="craft-smoke-$$" (PID of the script, avoids collisions when tests run in parallel), TOKEN="smoke-test-$(openssl rand -hex 16)".
  2. Cleanup trap before anything else:
    cleanup() { docker logs "$CONTAINER_NAME" 2>/dev/null || true; docker rm -f "$CONTAINER_NAME" 2>/dev/null || true; }
    trap cleanup EXIT
    
    Guarantees logs flush to CI output and container is removed even if the script exits abnormally. The || true swallows errors when the container never got created.
  3. Run the container detached: docker run -d --name ... -p PORT:9100 -e TOKEN ....
  4. Readiness loop polls two conditions each second:
    • Still running? docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" - if no, dump logs and exit 1 immediately.
    • Ready? docker logs "$CONTAINER_NAME" 2>&1 | grep -q "CRAFT_SERVER_URL=" - match the server's own stdout signal. Timeout defaults to 30s via SMOKE_TEST_TIMEOUT env.
  5. Layered test invocation:
    • If bun + apps/cli/src/index.ts exist, run the real CLI validator.
    • Else try a tiny node-based WebSocket ping: new WebSocket(url, { headers: { 'x-craft-token': TOKEN }}).
    • Else just nc -z 127.0.0.1 $PORT to confirm the port is listening.
    • Else warn but don't fail - container-is-running counts as a weak smoke signal.

Example

#!/usr/bin/env bash
set -euo pipefail
IMAGE="${1:?Usage: smoke.sh <image>}"
CONTAINER="smoke-$$"
TOKEN="$(openssl rand -hex 16)"
trap 'docker logs "$CONTAINER" 2>/dev/null || true; docker rm -f "$CONTAINER" 2>/dev/null || true' EXIT

docker run -d --name "$CONTAINER" -p 9100:9100 -e "TOKEN=$TOKEN" "$IMAGE"

for _ in $(seq 30); do
  docker inspect -f '{{.State.Running}}' "$CONTAINER" | grep -q true || { docker logs "$CONTAINER"; exit 1; }
  docker logs "$CONTAINER" 2>&1 | grep -q "SERVER_URL=" && break
  sleep 1
done

nc -z 127.0.0.1 9100 && echo OK

Gotchas

  • docker logs | grep is cheap but re-reads the whole log each iteration. Fine for small outputs, not for logs-per-second servers.
  • The readiness sentinel must be on stdout or stderr and flushed promptly - buffered output breaks the probe.
  • trap ... EXIT fires on normal exit AND signals; combined with set -e it's the cleanest cleanup pattern.
  • Use $$ not $RANDOM for the container name in CI - deterministic per test-runner PID makes debugging easier.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.