57 lines
1.3 KiB
Docker
57 lines
1.3 KiB
Docker
# Build stage
|
|
FROM node:18-alpine AS builder
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies
|
|
RUN npm ci
|
|
|
|
# Copy source code and config files
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN npm run build
|
|
|
|
# Production stage
|
|
FROM node:18-alpine AS runner
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install production dependencies only
|
|
RUN npm ci --only=production
|
|
|
|
# Copy necessary files from builder
|
|
COPY --from=builder /app/.next ./.next/
|
|
COPY --from=builder /app/public ./public/
|
|
COPY --from=builder /app/next.config.js ./
|
|
|
|
# Create a directory for markdown files
|
|
RUN mkdir -p /markdown
|
|
|
|
# Set environment variables
|
|
ENV NODE_ENV=production
|
|
ENV PORT=8080
|
|
ENV HOSTNAME=0.0.0.0
|
|
|
|
# Expose the port
|
|
EXPOSE 8080
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1
|
|
|
|
# Start the application
|
|
CMD ["npm", "start"]
|
|
|
|
# Do NOT copy posts/admin.json or posts/admin.json.tmp into the image
|
|
# These files are excluded via .dockerignore for security
|
|
# In production, mount the posts directory as a volume to persist posts and admin password
|
|
# If posts/admin.json does not exist, the default admin password is 'admin' (see README) |