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.
npx -y skills add kjuhwa/skills-hub --skill docker-smoke-test-loopAssembled 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
- 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)". - Cleanup trap before anything else:
Guarantees logs flush to CI output and container is removed even if the script exits abnormally. Thecleanup() { docker logs "$CONTAINER_NAME" 2>/dev/null || true; docker rm -f "$CONTAINER_NAME" 2>/dev/null || true; } trap cleanup EXIT|| trueswallows errors when the container never got created. - Run the container detached:
docker run -d --name ... -p PORT:9100 -e TOKEN .... - 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 viaSMOKE_TEST_TIMEOUTenv.
- Still running?
- Layered test invocation:
- If
bun+apps/cli/src/index.tsexist, 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 $PORTto confirm the port is listening. - Else warn but don't fail - container-is-running counts as a weak smoke signal.
- If
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 | grepis 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 ... EXITfires on normal exit AND signals; combined withset -eit's the cleanest cleanup pattern.- Use
$$not$RANDOMfor the container name in CI - deterministic per test-runner PID makes debugging easier.