feat(lab-04): complete Phase 5 - Storage & S3 lab
Phase Plan: - 05-PLAN.md: Combined execution plan for efficiency - 05-RESEARCH.md: Domain research on volumes and MinIO Test Scripts (4): - 01-volumes-test.sh: Volume persistence verification - 02-minio-test.sh: MinIO S3 API testing - 03-persistence-test.sh: Database persistence verification - 99-final-verification.sh: End-to-end verification Documentation (6 files): Tutorial: Docker volumes, MinIO S3 How-to: Manage volumes Reference: Volume syntax Explanation: Storage↔S3 parallels Infrastructure: - docker-compose.yml: MinIO S3 + PostgreSQL + test container - Named volumes: minio-data, db-data, test-data (INF-04 compliant) Key concepts: - Named volumes = EBS volumes - MinIO = S3 bucket (100% API compatible) - Data persistence across container lifecycle Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
14
labs/lab-04-storage/tests/01-volumes-test.sh
Executable file
14
labs/lab-04-storage/tests/01-volumes-test.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
# Test Docker Volumes persistence
|
||||
echo "Testing Docker Volumes..."
|
||||
docker compose up -d test && sleep 2
|
||||
docker exec lab04-test sh -c "echo 'data' > /test/persistent.txt"
|
||||
docker compose down
|
||||
docker compose up -d test && sleep 2
|
||||
if docker exec lab04-test cat /test/persistent.txt | grep -q "data"; then
|
||||
echo "✓ Volume persistence works"
|
||||
exit 0
|
||||
else
|
||||
echo "✗ Volume persistence failed"
|
||||
exit 1
|
||||
fi
|
||||
22
labs/lab-04-storage/tests/02-minio-test.sh
Executable file
22
labs/lab-04-storage/tests/02-minio-test.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
# Test MinIO S3 API
|
||||
echo "Testing MinIO S3 API..."
|
||||
docker compose up -d minio && sleep 5
|
||||
# Wait for MinIO to be ready
|
||||
for i in {1..10}; do
|
||||
if curl -sf http://127.0.0.1:9000/minio/health/live &>/dev/null; then
|
||||
echo "✓ MinIO is ready"
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
# Test S3 API with mc (MinIO client)
|
||||
docker exec lab04-minio mc alias set local http://localhost:9000 minioadmin minioadmin123
|
||||
docker exec lab04-minio mc mb local/testbucket
|
||||
if docker exec lab04-minio mc ls local/ | grep -q "testbucket"; then
|
||||
echo "✓ S3 bucket creation works"
|
||||
exit 0
|
||||
else
|
||||
echo "✗ S3 bucket creation failed"
|
||||
exit 1
|
||||
fi
|
||||
16
labs/lab-04-storage/tests/03-persistence-test.sh
Executable file
16
labs/lab-04-storage/tests/03-persistence-test.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
# Test data persistence in database
|
||||
echo "Testing database persistence..."
|
||||
docker compose up -d db && sleep 10
|
||||
docker exec lab04-db psql -U lab04_user -d lab04_db -c "CREATE TABLE IF NOT EXISTS test (id SERIAL, data TEXT);"
|
||||
docker exec lab04-db psql -U lab04_user -d lab04_db -c "INSERT INTO test (data) VALUES ('persistent');"
|
||||
docker compose down
|
||||
docker compose up -d db && sleep 10
|
||||
RESULT=$(docker exec lab04-db psql -U lab04_user -d lab04_db -tAc "SELECT data FROM test WHERE id=1;")
|
||||
if [[ "$RESULT" == "persistent" ]]; then
|
||||
echo "✓ Database persistence works"
|
||||
exit 0
|
||||
else
|
||||
echo "✗ Database persistence failed"
|
||||
exit 1
|
||||
fi
|
||||
29
labs/lab-04-storage/tests/99-final-verification.sh
Executable file
29
labs/lab-04-storage/tests/99-final-verification.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
# Final verification for Lab 04
|
||||
echo "Lab 04 Final Verification"
|
||||
cd "$(dirname "$0")/.."
|
||||
pass=0; fail=0
|
||||
check() { if eval "$1"; then echo "✓ $2"; ((pass++)); else echo "✗ $2"; ((fail++)); fi; }
|
||||
|
||||
# Infrastructure checks
|
||||
check "[[ -f docker-compose.yml ]]" "docker-compose.yml exists"
|
||||
check "docker compose config &>/dev/null" "Syntax valid"
|
||||
|
||||
# Start services
|
||||
docker compose up -d && sleep 8
|
||||
|
||||
# Volume checks
|
||||
VOLUMES=$(docker volume ls --format '{{.Name}}' | grep -c "lab04" || echo "0")
|
||||
check "[[ $VOLUMES -ge 3 ]]" "Named volumes created ($VOLUMES)"
|
||||
|
||||
# MinIO checks
|
||||
check "curl -sf http://127.0.0.1:9000/minio/health/live" "MinIO API accessible"
|
||||
check "curl -sf http://127.0.0.1:9001 &>/dev/null" "MinIO console accessible"
|
||||
|
||||
# Persistence check
|
||||
docker exec lab04-test sh -c "echo test > /test/file.txt"
|
||||
docker compose restart test && sleep 3
|
||||
check "docker exec lab04-test cat /test/file.txt | grep -q test" "Data persists after restart"
|
||||
|
||||
echo "Passed: $pass, Failed: $fail"
|
||||
[[ $fail -eq 0 ]] && exit 0 || exit 1
|
||||
Reference in New Issue
Block a user