From c75d03a5489b39e24013357a36d5a0e7e258708d Mon Sep 17 00:00:00 2001 From: Amirhossein Khalili Date: Wed, 20 May 2026 10:10:11 +0330 Subject: [PATCH] migrate frontend service to Next.js --- .gitignore | 3 +++ README.md | 4 +++- docker-compose.yml | 4 +++- frontend/Dockerfile | 34 ++++++++++++++++++++-------------- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 44b143b..5edce2a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ data/ certs/fullchain.pem certs/privateKey.pem .vscode/ + +backend/guilan-ace-backend +frontend/guilan-ace-frontend diff --git a/README.md b/README.md index 952caed..6048c47 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,11 @@ parent-directory/ 3. On the deployment server, place the backend repo at `guilan-ace-deployment/backend/guilan-ace-backend`. 4. On the deployment server, place the frontend repo at `guilan-ace-deployment/frontend/guilan-ace-frontend`. 5. Create `backend/guilan-ace-backend/.env` from the backend repo sample. -6. Run `docker compose up -d --build`. +6. Create `frontend/guilan-ace-frontend/.env` from the frontend repo sample. +7. Run `docker compose up -d --build`. ## Notes - Traefik terminates TLS and routes frontend, API, admin, static, media, Grafana, Prometheus, and Uptime Kuma. +- The frontend is a Next.js standalone Node runtime behind Traefik on internal port `3000`. - Alertmanager has been removed from this stack. Prometheus scraping and Grafana provisioning remain intact. - Dockerfiles live only in this deployment repository, and compose is intentionally wired only for the nested production layout. diff --git a/docker-compose.yml b/docker-compose.yml index 253c6ff..fa0398e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -130,12 +130,14 @@ services: build: context: ./frontend/guilan-ace-frontend dockerfile: ./frontend/Dockerfile + env_file: + - ./frontend/guilan-ace-frontend/.env labels: - traefik.enable=true - traefik.http.routers.frontend.rule=Host(`${NEXT_HOST}`) - traefik.http.routers.frontend.entrypoints=websecure - traefik.http.routers.frontend.tls.certresolver=le - - traefik.http.services.frontend.loadbalancer.server.port=80 + - traefik.http.services.frontend.loadbalancer.server.port=3000 static: image: nginx:1.27-alpine diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 7aa53d0..8f45a04 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,30 +1,36 @@ -FROM node:20-alpine AS builder +FROM node:20-alpine AS deps WORKDIR /app RUN npm config set registry https://package-mirror.liara.ir/repository/npm/ --global -# Copy package files COPY package*.json ./ -# Install dependencies -RUN npm install +RUN npm ci -# Copy source code +FROM node:20-alpine AS builder + +WORKDIR /app + +ENV NODE_ENV=production + +COPY --from=deps /app/node_modules ./node_modules COPY . . -# Build the application RUN npm run build -# Production image -FROM nginx:alpine +FROM node:20-alpine AS runner -# Copy built files to nginx -COPY --from=builder /app/dist /usr/share/nginx/html +WORKDIR /app -# Copy nginx configuration -COPY nginx.conf /etc/nginx/conf.d/default.conf +ENV NODE_ENV=production +ENV PORT=3000 +ENV HOSTNAME=0.0.0.0 -EXPOSE 80 +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static -CMD ["nginx", "-g", "daemon off;"] +EXPOSE 3000 + +CMD ["node", "server.js"]