Skip to content

Commit 6effb4e

Browse files
feat: add docker_test_before_push config — local test gate before push
- New setting in claude-mastery-project.conf: docker_test_before_push (disabled by default, enable for production projects) - When enabled: blocks docker push until image is built, run locally, verified not to crash, health check passes, no fatal errors in logs - Updated /optimize-docker command with Step 5 local test gate - Added Rule 10 to CLAUDE.md and GitHub Pages - Updated /optimize-docker command card on GitHub Pages Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6de0c82 commit 6effb4e

4 files changed

Lines changed: 92 additions & 3 deletions

File tree

.claude/commands/optimize-docker.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,57 @@ CMD ["node", "dist/index.js"]
292292

293293
If `.dockerignore` is missing or incomplete, create/update it with all required entries.
294294

295-
## Step 5 — RuleCatch Report
295+
## Step 5 — Docker Local Test Gate (if enabled)
296+
297+
Check `claude-mastery-project.conf` for `docker_test_before_push`:
298+
299+
**When `docker_test_before_push = true`:**
300+
301+
Before ANY `docker push` is allowed, you MUST run this verification sequence. If any step fails, STOP and fix the issue — do NOT push.
302+
303+
```bash
304+
# 1. Build the image
305+
docker build -t $IMAGE_NAME .
306+
307+
# 2. Run container locally
308+
docker run -d -p 3001:3001 --name test-container $IMAGE_NAME
309+
310+
# 3. Wait for startup
311+
sleep 5
312+
313+
# 4. Verify container is still running (didn't crash)
314+
docker ps --filter "name=test-container" --filter "status=running" -q
315+
316+
# 5. Check health endpoint responds
317+
curl -sf http://localhost:3001/health || echo "HEALTH CHECK FAILED"
318+
319+
# 6. Check container logs for fatal errors
320+
docker logs test-container 2>&1 | grep -iE "(error|fatal|exception|ENOENT|cannot find)" && echo "ERRORS FOUND IN LOGS"
321+
322+
# 7. Clean up test container
323+
docker stop test-container && docker rm test-container
324+
```
325+
326+
**Pass criteria — ALL must be true:**
327+
- Container is still running after 5 seconds (didn't exit with error)
328+
- Health endpoint returns HTTP 200
329+
- No fatal errors in container logs
330+
331+
**If any check fails:** Report exactly what failed, show the logs, and do NOT push. Fix the issue first.
332+
333+
**When `docker_test_before_push = false` (default):** Skip this step. The user manages their own testing.
334+
335+
This gate applies to ALL docker push operations, not just `/optimize-docker`. Any command or workflow that pushes to Docker Hub must check this setting first.
336+
337+
## Step 6 — RuleCatch Report
296338

297339
After all changes are complete, check RuleCatch:
298340

299341
- If the RuleCatch MCP server is available: query for violations in the modified Docker files
300342
- Report any violations found
301343
- If no MCP: suggest checking the RuleCatch dashboard
302344

303-
## Step 6 — Report
345+
## Step 7 — Report
304346

305347
Output a summary:
306348
- Image size estimate (before vs after)

CLAUDE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,31 @@ const orders = await getOrdersByUserId(user.id); // needs user.id
391391
- Worktrees let you run multiple Claude sessions in parallel without conflicts
392392
- RuleCatch catches violations Claude missed — last line of defense before merge
393393

394+
### 10. Docker Push Gate — Local Test Before Push
395+
396+
**Disabled by default.** When enabled (`docker_test_before_push = true` in `claude-mastery-project.conf`), ANY `docker push` is BLOCKED until the image passes local verification:
397+
398+
1. Build the image
399+
2. Run the container locally
400+
3. Wait 5 seconds for startup
401+
4. Verify container is still running (didn't crash/exit)
402+
5. Hit the health endpoint (must return 200)
403+
6. Check logs for fatal errors
404+
7. Clean up test container
405+
8. **Only then** allow `docker push`
406+
407+
If any step fails: STOP, show what failed, and do NOT push.
408+
409+
```bash
410+
# Enable in claude-mastery-project.conf:
411+
docker_test_before_push = true
412+
413+
# Disable (default):
414+
docker_test_before_push = false
415+
```
416+
417+
This gate applies globally — every command or workflow that pushes to Docker Hub must respect it.
418+
394419
---
395420

396421
## When Something Seems Wrong

claude-mastery-project.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# Set to false if you prefer manual branch management
1818
# sanitize: Auto-sanitize all MongoDB query inputs against NoSQL injection (default: true)
1919
# Set to false if you handle sanitization yourself or don't use MongoDB
20+
# docker_test_before_push:
21+
# When true, BLOCK any docker push until the image is built, run locally,
22+
# and verified to start without error (exit code 0, health check passes).
23+
# Default: false. Enable for production projects to prevent broken deploys.
2024
#
2125
# Profile values:
2226
# type: webapp | api | fullstack | cli
@@ -36,6 +40,7 @@
3640
root_dir = ~/projects
3741
auto_branch = true # Auto-create feature branches when on main (set false to disable)
3842
sanitize = true # Auto-sanitize all MongoDB query inputs against NoSQL injection (set false to disable)
43+
docker_test_before_push = false # When true, must build + run + health-check locally before pushing to Docker Hub
3944

4045
[clean]
4146
# All Claude Code infrastructure, zero coding opinions.

docs/index.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,23 @@ <h3>Parallelize Independent Awaits</h3>
577577
const products = await getProducts(); // waits unnecessarily
578578
const orders = await getOrders(); // waits unnecessarily</code></pre>
579579
</div>
580+
581+
<div class="rule-block">
582+
<div class="rule-header">
583+
<span class="rule-number">Rule 10</span>
584+
<h3>Docker Push Gate &mdash; Local Test First</h3>
585+
</div>
586+
<p><strong>Disabled by default.</strong> When enabled, NO <code>docker push</code> is allowed until the image passes local verification:</p>
587+
<ol>
588+
<li>Build the image</li>
589+
<li>Run the container locally</li>
590+
<li>Verify it doesn't crash (still running after 5s)</li>
591+
<li>Health endpoint returns 200</li>
592+
<li>No fatal errors in logs</li>
593+
<li>Clean up, <strong>then</strong> push</li>
594+
</ol>
595+
<p>Enable with <code>docker_test_before_push = true</code> in <code>claude-mastery-project.conf</code>. Applies to all commands that push Docker images.</p>
596+
</div>
580597
</div>
581598

582599
<h3>When Something Seems Wrong</h3>
@@ -845,7 +862,7 @@ <h3><code>/optimize-docker</code></h3>
845862
<li><strong>No secrets in build args</strong> &mdash; runtime env only</li>
846863
<li><strong>Pin versions</strong> &mdash; no <code>:latest</code> tags</li>
847864
</ol>
848-
<p>Generates an optimized Dockerfile, verifies <code>.dockerignore</code>, and reports image size estimate with before/after comparison.</p>
865+
<p>Generates an optimized Dockerfile, verifies <code>.dockerignore</code>, and reports image size estimate with before/after comparison. When <code>docker_test_before_push = true</code> in conf, blocks <code>docker push</code> until the image passes local verification (build, run, health check, no crash).</p>
849866
</div>
850867

851868
<div class="command-card">

0 commit comments

Comments
 (0)