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:
|
password:
|
||||||
from_secret: DOCKER_PASSWORD
|
from_secret: DOCKER_PASSWORD
|
||||||
build_args:
|
build_args:
|
||||||
NEXT_PUBLIC_API_BASE_URL:
|
VITE_API_BASE_URL:
|
||||||
from_secret: NEXT_PUBLIC_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
|
from_secret: NEXT_PUBLIC_OMV_BASE_URL
|
||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
@ -53,7 +53,7 @@ steps:
|
|||||||
docker rm mangamochi-frontend 2>/dev/null || true &&
|
docker rm mangamochi-frontend 2>/dev/null || true &&
|
||||||
docker run -d --name mangamochi-frontend \
|
docker run -d --name mangamochi-frontend \
|
||||||
--restart always \
|
--restart always \
|
||||||
-p 80:3000 \
|
-p 80:80 \
|
||||||
$IMAGE
|
$IMAGE
|
||||||
"
|
"
|
||||||
when:
|
when:
|
||||||
|
|||||||
55
Dockerfile
55
Dockerfile
@ -1,54 +1,35 @@
|
|||||||
# Stage 1: Build stage
|
# --- Stage 1: Build stage ---
|
||||||
FROM node:18-alpine AS builder
|
FROM node:22-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package files
|
# Copy and install dependencies
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
COPY package-lock.json* ./
|
|
||||||
|
|
||||||
# Install all dependencies (including dev dependencies)
|
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the application
|
# Build environment vars
|
||||||
ARG NEXT_PUBLIC_API_BASE_URL
|
ARG VITE_API_BASE_URL
|
||||||
ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL}
|
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
|
||||||
|
ARG VITE_OMV_BASE_URL
|
||||||
ARG NEXT_PUBLIC_OMV_BASE_URL
|
ENV VITE_OMV_BASE_URL=${VITE_OMV_BASE_URL}
|
||||||
ENV NEXT_PUBLIC_OMV_BASE_URL=${NEXT_PUBLIC_OMV_BASE_URL}
|
|
||||||
|
|
||||||
|
# Build static files
|
||||||
RUN npm run build
|
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
|
# Copy built static files
|
||||||
RUN addgroup --system --gid 1001 nodejs
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
RUN adduser --system --uid 1001 nextjs
|
|
||||||
|
|
||||||
# Copy necessary files from builder stage
|
# Expose port 80
|
||||||
COPY --from=builder /app/public ./public
|
EXPOSE 80
|
||||||
COPY --from=builder /app/.next ./.next
|
|
||||||
COPY --from=builder /app/node_modules ./node_modules
|
|
||||||
COPY --from=builder /app/package.json ./package.json
|
|
||||||
|
|
||||||
# Set proper permissions
|
# Optional: override default nginx config for SPA routing
|
||||||
RUN chown -R nextjs:nodejs /app
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
# Switch to non-root user
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
USER nextjs
|
|
||||||
|
|
||||||
# Expose port
|
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
# Set environment variable
|
|
||||||
ENV PORT 3000
|
|
||||||
ENV HOSTNAME "0.0.0.0"
|
|
||||||
|
|
||||||
# Start the application
|
|
||||||
CMD ["npm", "start"]
|
|
||||||
|
|||||||
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