Files
blog/write-server/Dockerfile
T

74 lines
1.7 KiB
Docker
Raw Normal View History

2026-06-21 20:42:44 +08:00
# Write Server Dockerfile
# Multi-stage build for production
# Stage 1: Install dependencies
FROM node:20-alpine AS deps
WORKDIR /app
# Copy package files
COPY package.json package-lock.json ./
# Install dependencies
RUN npm ci --only=production && \
npm cache clean --force
# Stage 2: Build application
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
COPY package.json package-lock.json ./
# Install all dependencies (including devDependencies)
RUN npm ci
# Copy source code
COPY . .
# Build application
RUN npm run build
# Stage 3: Production
FROM node:20-alpine AS runner
WORKDIR /app
2026-06-21 22:30:54 +08:00
# Install Hugo and su-exec (for entrypoint)
RUN apk add --no-cache hugo su-exec
2026-06-21 20:42:44 +08:00
# Create non-root user
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy built application
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
2026-06-21 22:38:28 +08:00
# Copy production node_modules as fallback (standalone may miss some deps)
COPY --from=deps /app/node_modules ./node_modules
2026-06-21 20:42:44 +08:00
# Copy package.json for version info
COPY --from=builder /app/package.json ./
2026-06-21 22:30:54 +08:00
# Copy entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
2026-06-21 20:42:44 +08:00
2026-06-21 22:30:54 +08:00
# Create necessary directories
RUN mkdir -p /app/logs /app/backups /app/recycle/posts /app/recycle/meta
2026-06-21 20:42:44 +08:00
# Expose port
EXPOSE 8016
# Set environment variables
ENV NODE_ENV=production
ENV PORT=8016
ENV HOSTNAME="0.0.0.0"
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8016/api/stats || exit 1
2026-06-21 22:30:54 +08:00
# Start application via entrypoint (fixes permissions, drops to nextjs)
ENTRYPOINT ["/entrypoint.sh"]
2026-06-21 20:42:44 +08:00
CMD ["node", "server.js"]