From 425febc86a031e776241e6a09408e3518de05f72 Mon Sep 17 00:00:00 2001 From: Braulio Date: Mon, 23 Feb 2026 13:34:40 +0100 Subject: [PATCH] updates auto cd --- .github/workflows/deploy-front.yml | 17 ++++++++++++++--- front/Dockerfile | 1 + front/src/app/api/revalidate/route.ts | 12 ++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 front/src/app/api/revalidate/route.ts diff --git a/.github/workflows/deploy-front.yml b/.github/workflows/deploy-front.yml index 238f21f..20842f0 100644 --- a/.github/workflows/deploy-front.yml +++ b/.github/workflows/deploy-front.yml @@ -65,8 +65,19 @@ jobs: # Warm-up: force ISR regeneration so first real user gets data - name: Warm-up (force ISR regeneration) + env: + SITE_URL: https://info-embalse-front-prod-ecguababcfdsepga.westeurope-01.azurewebsites.net + REVALIDATION_SECRET: ${{ secrets.REVALIDATION_SECRET }} run: | echo "Waiting for App Service to start..." - sleep 30 - curl -s -o /dev/null -w "%{http_code}" https://info-embalse-front-prod-ecguababcfdsepga.westeurope-01.azurewebsites.net/ - echo " - Warm-up done, ISR regeneration triggered" + for i in $(seq 1 10); do + STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$SITE_URL/" || true) + echo " Attempt $i: HTTP $STATUS" + if [ "$STATUS" = "200" ]; then break; fi + sleep 10 + done + echo "Triggering on-demand revalidation..." + curl -s "$SITE_URL/api/revalidate?secret=$REVALIDATION_SECRET" + sleep 2 + curl -s -o /dev/null "$SITE_URL/" + echo "Warm-up complete" diff --git a/front/Dockerfile b/front/Dockerfile index 86e1062..783a358 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -45,6 +45,7 @@ ENV PORT=3000 # - public assets in /public COPY --from=builder /app/front/.next/standalone ./ COPY --from=builder /app/front/.next/static ./front/.next/static +COPY --from=builder /app/front/.next/cache ./front/.next/cache COPY --from=builder /app/front/public ./front/public EXPOSE 3000 diff --git a/front/src/app/api/revalidate/route.ts b/front/src/app/api/revalidate/route.ts new file mode 100644 index 0000000..875bcb2 --- /dev/null +++ b/front/src/app/api/revalidate/route.ts @@ -0,0 +1,12 @@ +import { revalidatePath } from "next/cache"; +import { NextRequest, NextResponse } from "next/server"; + +export async function GET(request: NextRequest) { + const secret = request.nextUrl.searchParams.get("secret"); + if (secret !== process.env.REVALIDATION_SECRET) { + return NextResponse.json({ message: "Invalid secret" }, { status: 401 }); + } + + revalidatePath("/"); + return NextResponse.json({ revalidated: true }); +}