From 400c9f19fac03d895b034d8a6cedcfbd746d14f6 Mon Sep 17 00:00:00 2001 From: Rodrigo Verdiani Date: Thu, 30 Oct 2025 16:37:36 -0300 Subject: [PATCH] feature(docker): update Dockerfile for Nginx production setup and adjust build args --- .woodpecker/pipeline.yaml | 6 ++--- Dockerfile | 55 +++++++++++++-------------------------- nginx.conf | 11 ++++++++ 3 files changed, 32 insertions(+), 40 deletions(-) create mode 100644 nginx.conf diff --git a/.woodpecker/pipeline.yaml b/.woodpecker/pipeline.yaml index 6d1bfb1..78d6ef3 100644 --- a/.woodpecker/pipeline.yaml +++ b/.woodpecker/pipeline.yaml @@ -18,9 +18,9 @@ steps: password: from_secret: DOCKER_PASSWORD build_args: - NEXT_PUBLIC_API_BASE_URL: + VITE_API_BASE_URL: from_secret: NEXT_PUBLIC_API_BASE_URL - NEXT_PUBLIC_OMV_BASE_URL: + VITE_OMV_BASE_URL: from_secret: NEXT_PUBLIC_OMV_BASE_URL tags: - latest @@ -53,7 +53,7 @@ steps: docker rm mangamochi-frontend 2>/dev/null || true && docker run -d --name mangamochi-frontend \ --restart always \ - -p 80:3000 \ + -p 80:80 \ $IMAGE " when: diff --git a/Dockerfile b/Dockerfile index 4f6c7e7..3207291 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,54 +1,35 @@ -# Stage 1: Build stage -FROM node:18-alpine AS builder +# --- Stage 1: Build stage --- +FROM node:22-alpine AS builder WORKDIR /app -# Copy package files +# Copy and install dependencies COPY package*.json ./ -COPY package-lock.json* ./ - -# Install all dependencies (including dev dependencies) RUN npm ci # Copy source code COPY . . -# Build the application -ARG NEXT_PUBLIC_API_BASE_URL -ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL} - -ARG NEXT_PUBLIC_OMV_BASE_URL -ENV NEXT_PUBLIC_OMV_BASE_URL=${NEXT_PUBLIC_OMV_BASE_URL} +# Build environment vars +ARG VITE_API_BASE_URL +ENV VITE_API_BASE_URL=${VITE_API_BASE_URL} +ARG VITE_OMV_BASE_URL +ENV VITE_OMV_BASE_URL=${VITE_OMV_BASE_URL} +# Build static files RUN npm run build -# Stage 2: Production stage -FROM node:18-alpine AS runner -WORKDIR /app +# --- Stage 2: Nginx stage --- +FROM nginx:alpine AS runner -# Create non-root user for security -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs +# Copy built static files +COPY --from=builder /app/dist /usr/share/nginx/html -# Copy necessary files from builder stage -COPY --from=builder /app/public ./public -COPY --from=builder /app/.next ./.next -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/package.json ./package.json +# Expose port 80 +EXPOSE 80 -# Set proper permissions -RUN chown -R nextjs:nodejs /app +# Optional: override default nginx config for SPA routing +COPY nginx.conf /etc/nginx/conf.d/default.conf -# Switch to non-root user -USER nextjs - -# Expose port -EXPOSE 3000 - -# Set environment variable -ENV PORT 3000 -ENV HOSTNAME "0.0.0.0" - -# Start the application -CMD ["npm", "start"] +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..bb3f608 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,11 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri /index.html; + } +}