monacousa-portal/Dockerfile

58 lines
1.3 KiB
Docker

# Multi-stage build for MonacoUSA Portal
# Stage 1: Builder
FROM node:18-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install all dependencies (including dev dependencies for build)
RUN npm install && npm cache clean --force
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Stage 2: Runtime
FROM node:18-alpine AS runtime
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create app user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nuxt -u 1001
# Set working directory
WORKDIR /app
# Copy built application from builder stage
COPY --from=builder --chown=nuxt:nodejs /app/.output ./.output
# Copy entrypoint script
COPY --chown=nuxt:nodejs docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
# Create volume directory for persistent data
RUN mkdir -p /app/data && chown nuxt:nodejs /app/data
# Switch to non-root user
USER nuxt
# Expose port
EXPOSE 6060
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:6060/api/health', (r) => {r.statusCode === 200 ? process.exit(0) : process.exit(1)})" || exit 1
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Start the application
CMD ["./docker-entrypoint.sh"]