From 3f0858a1bafe4489189d4edb8951ccc3bc956c32 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 28 Jan 2026 21:39:16 +0100 Subject: [PATCH] smoke tests --- .gitea/workflows/deploy.yml | 17 ++++++++++++++++- Dockerfile | 7 +++++++ scripts/smoke-test.ts | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 scripts/smoke-test.ts diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 07906eca..c5907807 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -228,7 +228,22 @@ jobs: docker-compose up -d echo "⏳ Waiting for services to be healthy..." - sleep 10 + MAX_RETRIES=12 + RETRY_COUNT=0 + until curl -s -f http://localhost:3000/health > /dev/null || [ $RETRY_COUNT -eq $MAX_RETRIES ]; do + echo " • Waiting for health check... ($((RETRY_COUNT + 1))/$MAX_RETRIES)" + sleep 5 + RETRY_COUNT=$((RETRY_COUNT + 1)) + done + + if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then + echo "❌ Health check failed after $MAX_RETRIES retries" + echo "🔍 Container logs:" + docker-compose logs --tail=50 + exit 1 + fi + + echo "✅ Health check passed!" echo "🔍 Checking service status..." docker-compose ps diff --git a/Dockerfile b/Dockerfile index a52440c5..cea2e032 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,6 +37,13 @@ RUN npx tsx scripts/validate-env.ts RUN npm run build +# Smoke test during build to catch runtime errors early +# We start the app in the background, wait for it to be ready, and run the smoke test +RUN (node .next/standalone/server.js &) && \ + npx wait-on -t 30000 http://localhost:3000/health && \ + npx tsx scripts/smoke-test.ts http://localhost:3000/health && \ + pkill -f "node .next/standalone/server.js" + # Production image, copy all the files and run next FROM base AS runner WORKDIR /app diff --git a/scripts/smoke-test.ts b/scripts/smoke-test.ts new file mode 100644 index 00000000..b32f97b1 --- /dev/null +++ b/scripts/smoke-test.ts @@ -0,0 +1,36 @@ +import * as http from 'http'; + +/** + * Simple smoke test to verify the application is running and healthy. + * This script is intended to be run against a local or remote instance. + */ + +const url = process.argv[2] || 'http://localhost:3000/health'; +const timeout = 10000; // 10 seconds + +console.log(`🔍 Running smoke test against: ${url}`); + +const request = http.get(url, (res) => { + const { statusCode } = res; + + if (statusCode === 200) { + console.log('✅ Smoke test passed: Application is healthy.'); + process.exit(0); + } else { + console.error(`❌ Smoke test failed: Received status code ${statusCode}`); + process.exit(1); + } +}); + +request.on('error', (err) => { + console.error(`❌ Smoke test failed: ${err.message}`); + process.exit(1); +}); + +request.on('timeout', () => { + console.error('❌ Smoke test failed: Request timed out'); + request.destroy(); + process.exit(1); +}); + +request.setTimeout(timeout);