Skip to content

Merge pull request #154 from Lemoncode/feature/mongo-env-fix #24

Merge pull request #154 from Lemoncode/feature/mongo-env-fix

Merge pull request #154 from Lemoncode/feature/mongo-env-fix #24

Workflow file for this run

name: Deploy Front (Next.js) to Azure App Service (GHCR)
on:
push:
branches: ["main"]
paths:
- "front/**"
- "packages/db-model/**"
- "package.json"
- "package-lock.json"
concurrency:
group: front-prod
cancel-in-progress: true
permissions:
contents: read
packages: write
env:
IMAGE_NAME: ghcr.io/lemoncode/embalse-info-front
IMAGE_TAG: latest
IMAGE_SHA_TAG: sha-${{ github.sha }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Checkout repository source code
- name: Checkout
uses: actions/checkout@v4
# Login to GHCR (GitHub Container Registry)
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Setup Docker Buildx (better caching/build support)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Build and push the Docker image
- name: Build and Push
uses: docker/build-push-action@v6
with:
context: .
file: front/Dockerfile
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
${{ env.IMAGE_NAME }}:${{ env.IMAGE_SHA_TAG }}
# Deploy the image to Azure App Service (Linux container)
- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v3
with:
app-name: ${{ secrets.AZURE_FRONT_APP_NAME }}
publish-profile: ${{ secrets.AZURE_FRONT_PUBLISH_PROFILE }}
images: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_SHA_TAG }}
restart: true
# 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..."
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"