Fix deploy health check for /mstcontroller and cut ready-loop waste.
Deploy edu.mstaut.ir / deploy (push) Successful in 5m56s

Admin login moved off /admin; old path caused 404 spam for up to two minutes. Slim smoke checks, shorter retries, quieter migrate logs, and npm ci without audit in the image build.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
smhk1376andCursor committed 2026-10-16 16:57:31 +03:30
1 parent 69bdaf0113
commit c97498a2ae
4 files changed
+48 -20

No files matched your search

+26 -14
View File
@@ -18,7 +18,9 @@ docker inspect insaight-postgres --format '{{json .NetworkSettings.Networks}}' |
docker volume create "$UPLOAD_VOLUME" >/dev/null
# Keep the current app running throughout the build.
docker build --build-arg NEXT_PUBLIC_SITE_URL=https://edu.mstaut.ir -t "$IMAGE" .
DOCKER_BUILDKIT=1 docker build \
--build-arg NEXT_PUBLIC_SITE_URL=https://edu.mstaut.ir \
-t "$IMAGE" .
# Back up before applying the repository's transactional, versioned migrations.
# Migrations are forward-only and idempotent (schema_migrations); dump is the safety net.
@@ -30,7 +32,7 @@ test -s "$BACKUP"
docker run --rm --network "$NETWORK" --env-file "$ENV_FILE" \
-v "$PWD/db:/app/db:ro" --entrypoint node "$IMAGE" db/migrate.mjs
# Check the database and rendered pages before switching the public upstream.
# Check the database and a minimal page set before switching the public upstream.
CANDIDATE="edu-candidate-${REVISION:0:12}"
docker run -d --name "$CANDIDATE" --network "$NETWORK" --env-file "$ENV_FILE" \
-e UPLOAD_DIR=/app/public/uploads \
@@ -39,24 +41,34 @@ docker run -d --name "$CANDIDATE" --network "$NETWORK" --env-file "$ENV_FILE" \
cleanup_candidate() { docker rm -f "$CANDIDATE" >/dev/null 2>&1 || true; }
trap cleanup_candidate EXIT
READY=false
for attempt in $(seq 1 60); do
for attempt in $(seq 1 24); do
if docker exec "$CANDIDATE" node -e '
(async () => {
const { Pool } = require("pg");
const pool = new Pool({connectionString: process.env.DATABASE_URL, connectionTimeoutMillis: 5000});
await pool.query("SELECT 1"); await pool.end();
for (const route of ["/", "/programs", "/professional", "/admin/login"]) {
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
connectionTimeoutMillis: 3000,
});
await pool.query("SELECT 1");
await pool.end();
// Minimal smoke: home + admin login (path moved from /admin).
for (const route of ["/", "/mstcontroller/login"]) {
const response = await fetch("http://127.0.0.1:3000" + route);
if (!response.ok) throw new Error(route + ": " + response.status);
}
for (const resource of ["courses", "programs", "events", "articles"]) {
const response = await fetch("http://127.0.0.1:3000/api/" + resource);
const body = await response.json();
if (!response.ok || !Array.isArray(body.data)) throw new Error("API check failed: " + resource);
const api = await fetch("http://127.0.0.1:3000/api/courses");
const body = await api.json();
if (!api.ok || !Array.isArray(body.data)) {
throw new Error("API check failed: courses");
}
})().catch(error => { console.error(error.message); process.exit(1); });
})().catch((error) => {
console.error(error.message || error);
process.exit(1);
});
'; then READY=true; break; fi
sleep 2
sleep 1
done
if [ "$READY" != true ]; then docker logs --tail 50 "$CANDIDATE"; exit 1; fi
cleanup_candidate
@@ -84,11 +96,11 @@ docker run -d --name "$CONTAINER" --restart unless-stopped \
-v "$UPLOAD_VOLUME:/app/public/uploads" \
-p 127.0.0.1:3000:3000 "$IMAGE"
READY=false
for attempt in $(seq 1 30); do
for attempt in $(seq 1 20); do
if curl -fsS --max-time 5 --resolve edu.mstaut.ir:443:127.0.0.1 https://edu.mstaut.ir/ >/dev/null; then
READY=true; break
fi
sleep 2
sleep 1
done
test "$READY" = true
trap - ERR