Files
Luca Sacchi Ricciardi 23a9ffe443 feat(lab-03): complete Phase 4 - Compute & EC2 lab
Phase Plans (5 files):
- 04-RESEARCH.md: Domain research on Docker limits, healthchecks, EC2 parallels
- 04-VALIDATION.md: Success criteria and validation strategy
- 04-01-PLAN.md: Test infrastructure (RED phase)
- 04-02-PLAN.md: Diátxis documentation
- 04-03-PLAN.md: Infrastructure implementation (GREEN phase)

Test Scripts (6 files, 1300+ lines):
- 01-resource-limits-test.sh: Validate INF-03 compliance
- 02-healthcheck-test.sh: Validate healthcheck configuration
- 03-enforcement-test.sh: Verify resource limits with docker stats
- 04-verify-infrastructure.sh: Infrastructure verification
- 99-final-verification.sh: End-to-end student verification
- run-all-tests.sh: Test orchestration with fail-fast
- quick-test.sh: Fast validation (<30s)

Documentation (11 files, 2500+ lines):
Tutorials (3):
- 01-set-resource-limits.md: EC2 instance types, Docker limits syntax
- 02-implement-healthchecks.md: ELB health check parallels
- 03-dependencies-with-health.md: depends_on with service_healthy

How-to Guides (4):
- check-resource-usage.md: docker stats monitoring
- test-limits-enforcement.md: Stress testing CPU/memory
- custom-healthcheck.md: HTTP, TCP, database healthchecks
- instance-type-mapping.md: Docker limits → EC2 mapping

Reference (3):
- compose-resources-syntax.md: Complete deploy.resources reference
- healthcheck-syntax.md: All healthcheck parameters
- ec2-instance-mapping.md: Instance type mapping table

Explanation (1):
- compute-ec2-parallels.md: Container=EC2, Limits=Instance Type, Healthcheck=ELB

Infrastructure:
- docker-compose.yml: 5 services (web, app, worker, db, stress-test)
  All services: INF-03 compliant (cpus + memory limits)
  All services: healthcheck configured
  EC2 parallels: t2.nano, t2.micro, t2.small, t2.medium, m5.large
- Dockerfile: Alpine 3.19 + stress tools + non-root user

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 15:16:58 +02:00

7.7 KiB

phase, plan, type, wave, depends_on, files_modified, autonomous, requirements, user_setup, must_haves
phase plan type wave depends_on files_modified autonomous requirements user_setup must_haves
04-lab-03-compute-ec2 01 execute 0
labs/lab-03-compute/tests/01-resource-limits-test.sh
labs/lab-03-compute/tests/02-healthcheck-test.sh
labs/lab-03-compute/tests/03-enforcement-test.sh
labs/lab-03-compute/tests/99-final-verification.sh
labs/lab-03-compute/tests/run-all-tests.sh
labs/lab-03-compute/tests/quick-test.sh
true
TEST-01
TEST-05
INF-03
LAB-03
truths artifacts key_links
Test scripts exist and validate resource limits before implementation
Tests verify INF-03 compliance (all containers have CPU/memory limits)
Tests verify healthcheck implementation
Tests can enforce resource limits and verify with docker stats
Final verification script provides clear pass/fail report
path provides min_lines
labs/lab-03-compute/tests/01-resource-limits-test.sh Resource limits validation 80
path provides min_lines
labs/lab-03-compute/tests/02-healthcheck-test.sh Healthcheck testing 100
path provides min_lines
labs/lab-03-compute/tests/03-enforcement-test.sh Resource enforcement verification 120
path provides min_lines
labs/lab-03-compute/tests/99-final-verification.sh Student double-check command 100
path provides min_lines
labs/lab-03-compute/tests/run-all-tests.sh Test orchestration with fail-fast 50
path provides min_lines
labs/lab-03-compute/tests/quick-test.sh Quick validation for development 30
from to via pattern
tests/01-resource-limits-test.sh docker-compose.yml resources yq or grep for deploy.resources.limits deploy:.*resources:.*limits
from to via pattern
tests/02-healthcheck-test.sh docker-compose.yml healthcheck grep for healthcheck section healthcheck:
from to via pattern
tests/03-enforcement-test.sh docker stats docker stats --no-stream for verification docker.*stats
from to via pattern
tests/99-final-verification.sh INF-03 requirement Verify all services have cpu and memory limits INF-03
Create comprehensive test infrastructure for Lab 03 (Compute & EC2) following TDD RED phase methodology. Tests validate Docker Compose resource limits (CPU/memory), healthcheck implementation, and INF-03 compliance (all containers must have resource limits).

Purpose: Establish verification foundation before implementing compute infrastructure. Tests fail initially (RED phase) and pass after implementation (GREEN phase in Plan 04-03).

Output: 6 bash test scripts covering resource limits validation, healthcheck testing, enforcement verification, and final verification for students.

<execution_context> @/home/luca/.claude/get-shit-done/workflows/execute-plan.md @/home/luca/.claude/get-shit-done/templates/summary.md </execution_context>

@.planning/REQUIREMENTS.md @.planning/phases/04-lab-03-compute-ec2/04-RESEARCH.md @.planning/phases/04-lab-03-compute-ec2/04-VALIDATION.md @.planning/phases/03-lab-02-network-vpc/03-01-PLAN.md

Test Patterns from Phase 2 and 3

From labs/lab-01-iam/tests/run-all-tests.sh:

  • Use set -euo pipefail for error handling
  • Color-coded output (GREEN for pass, RED for fail, BLUE for info)
  • Summary with pass/fail counts
  • Exit code 0 for all pass, 1 for any failure

From labs/lab-02-network/tests/04-verify-infrastructure.sh:

  • Parse docker-compose.yml with docker compose config
  • Use jq for JSON parsing when needed
  • Verify compliance with grep patterns
  • Use awk for robust counting

Key Docker Commands for Testing

Resource Limits Verification

# Check if service has CPU limit
docker compose config | grep -A 10 "service_name:" | grep -c "cpus:"

# Check if service has memory limit
docker compose config | grep -A 10 "service_name:" | grep -c "memory:"

# Get container limits
docker inspect container_name --format '{{.HostConfig.NanoCpus}}'
docker inspect container_name --format '{{.HostConfig.Memory}}'

Healthcheck Verification

# Check if service has healthcheck
docker compose config | grep -A 20 "service_name:" | grep -c "healthcheck:"

# Get container health status
docker inspect container_name --format '{{.State.Health.Status}}'

Resource Monitoring

# Get live stats
docker stats --no-stream

# Get specific container stats
docker stats container_name --no-stream --format "{{.CPUPerc}}\t{{.MemUsage}}"

Testing Strategy

Test 1: Resource Limits Configuration

Purpose: Verify docker-compose.yml has resource limits defined Expected Result: FAIL initially (no limits configured) Pass Criteria After Implementation: All services have cpus and memory limits

Test 2: Healthcheck Configuration

Purpose: Verify services have healthchecks defined Expected Result: FAIL initially (no healthchecks configured) Pass Criteria After Implementation: All services have valid healthchecks

Test 3: Resource Enforcement

Purpose: Deploy test container and verify limits are enforced Expected Result: FAIL initially (no test container defined) Pass Criteria After Implementation: docker stats shows enforcement

Test 4: INF-03 Compliance

Purpose: Verify mandatory resource limits for all services Expected Result: FAIL initially Pass Criteria After Implementation: 100% compliance

Implementation Notes

  1. Directory Structure:
labs/lab-03-compute/
├── tests/
│   ├── 01-resource-limits-test.sh
│   ├── 02-healthcheck-test.sh
│   ├── 03-enforcement-test.sh
│   ├── 99-final-verification.sh
│   ├── run-all-tests.sh
│   └── quick-test.sh
├── docker-compose.yml  (created in 04-03)
└── README.md
  1. Test Execution Order:

    • 01-resource-limits-test.sh: Parse compose file for limits
    • 02-healthcheck-test.sh: Parse compose file for healthchecks
    • 03-enforcement-test.sh: Deploy test and verify enforcement
    • 99-final-verification.sh: End-to-end student verification
  2. Error Handling:

    • Each test should be independent
    • Use descriptive error messages
    • Provide remediation hints
  3. Color Coding:

    RED='\033[0;31m'
    GREEN='\033[0;32m'
    BLUE='\033[0;34m'
    BOLD='\033[1m'
    NC='\033[0m'
    

Success Criteria

Plan 04-01 is complete when:

  1. All 6 test scripts created
  2. Each script meets minimum line requirements
  3. Tests fail when executed on empty/non-existent lab-03-compute
  4. run-all-tests.sh executes all tests in sequence
  5. Tests cover: resource limits, healthchecks, enforcement, INF-03
1. Create labs/lab-03-compute/tests/ directory 2. Create 01-resource-limits-test.sh (80+ lines) - Parse docker-compose.yml for deploy.resources.limits - Verify cpus and memory for all services - Report missing limits 3. Create 02-healthcheck-test.sh (100+ lines) - Parse docker-compose.yml for healthcheck sections - Verify test, interval, timeout, retries - Report missing healthchecks 4. Create 03-enforcement-test.sh (120+ lines) - Deploy test container with stress image - Verify CPU limit enforcement with docker stats - Verify memory OOM on exceed - Cleanup test container 5. Create 99-final-verification.sh (100+ lines) - Combine all checks into student-facing verification - INF-03 compliance report - Healthcheck status report - Clear pass/fail summary 6. Create run-all-tests.sh (50+ lines) - Execute all test scripts in sequence - Fail-fast on first failure - Summary report 7. Create quick-test.sh (30+ lines) - Fast validation (< 30 seconds) - Essential checks only