feature(docker): update Dockerfile for Nginx production setup and adjust build args
All checks were successful
ci/woodpecker/push/pipeline Pipeline was successful
All checks were successful
ci/woodpecker/push/pipeline Pipeline was successful
This commit is contained in:
parent
1fadfeb313
commit
400c9f19fa
@ -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:
|
||||
|
||||
55
Dockerfile
55
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;"]
|
||||
|
||||
11
nginx.conf
Normal file
11
nginx.conf
Normal file
@ -0,0 +1,11 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user