Files
svelte-mud/Dockerfile

47 lines
943 B
Docker
Raw Normal View History

2025-04-21 14:12:36 +02:00
# Multi-stage build Dockerfile for Svelte MUD client
# Build stage
FROM node:20-alpine AS build
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
2025-04-21 22:25:00 +02:00
RUN npm install
2025-04-21 14:12:36 +02:00
# Copy source files
COPY . .
# Build the application
RUN npm run build
# Production stage
FROM node:20-alpine AS production
# Set working directory
WORKDIR /app
# Create a non-root user and group with the node user ID
RUN addgroup -g 1001 -S nodejs && \
adduser -S -u 1001 -G nodejs nodejs
# Install only production dependencies
COPY package*.json ./
2025-04-21 22:25:00 +02:00
RUN npm install --omit=dev
2025-04-21 14:12:36 +02:00
# Copy built application from the build stage
COPY --from=build /app/build ./build
2025-04-21 23:22:32 +02:00
COPY --from=build /app/src ./src
COPY --from=build /app/run-production.js ./
2025-04-21 14:12:36 +02:00
# Switch to non-root user
USER nodejs
# Set environment variables
ENV NODE_ENV=production
2025-04-21 23:22:32 +02:00
# Start both servers using the production script
CMD ["node", "run-production.js"]