Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/deploy-front.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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_TAG }}
restart: true
9 changes: 9 additions & 0 deletions front/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.next
.git
.gitignore
Dockerfile
README.md
npm-debug.log
.env
.env.*
52 changes: 52 additions & 0 deletions front/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ------------------------------------------------------------
# Builder stage
# ------------------------------------------------------------
FROM node:22-alpine AS builder

WORKDIR /app

# 1) Copy only lockfiles + package manifests first for caching
# (so Docker doesn't reinstall deps on every code change)
COPY package.json package-lock.json ./
COPY front/package.json ./front/package.json
COPY packages/db-model/package.json ./packages/db-model/package.json

# 2) Install all dependencies for the monorepo (npm workspaces)
# We need dev deps here because Next build typically requires them.
RUN npm ci

# 3) Now copy the full source code
COPY . .

# 4) Build the internal dependency used by the front (db-model)
# If your workspace name differs, adjust "-w db-model"
RUN npm run -w db-model build --if-present

# 5) Build Next.js (standalone output will be generated)
RUN npm run -w front build


# ------------------------------------------------------------
# Runner stage (small image)
# ------------------------------------------------------------
FROM node:22-alpine AS runner

WORKDIR /app
ENV NODE_ENV=production

# Azure App Service expects the app to listen on 0.0.0.0
ENV HOSTNAME=0.0.0.0
ENV PORT=3000

# Next standalone output:
# - server.js + minimal node_modules in .next/standalone
# - static assets in .next/static
# - public assets in /public
COPY --from=builder /app/front/.next/standalone ./
COPY --from=builder /app/front/.next/static ./.next/static
COPY --from=builder /app/front/public ./public

EXPOSE 3000

# Start Next standalone server
CMD ["node", "server.js"]
8 changes: 8 additions & 0 deletions front/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
// Generates a self-contained production server in .next/standalone
// This avoids shipping the whole node_modules and makes Docker images smaller.
output: "standalone",
};

export default nextConfig;
4 changes: 3 additions & 1 deletion front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"private": true,
"type": "module",
"scripts": {
"start": "next dev"
"start": "next dev",
"build": "next build",
"start-prod": "node .next/standalone/server.js"
},
"dependencies": {
"@fontsource/nunito-sans": "^5.2.7",
Expand Down