Spaces:
Running
Running
File size: 1,473 Bytes
2df0cf9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | {% if config.multiStage %}
# Multi-stage build for Node.js
FROM node:{{ config.nodeVersion or '18' }}-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production
# Copy source code
COPY . .
{% if config.buildCommand %}
# Build application
RUN {{ config.buildCommand }}
{% endif %}
# Production stage
FROM node:{{ config.nodeVersion or '18' }}-alpine
WORKDIR /app
# Copy from builder
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app .
{% else %}
# Node.js {{ config.nodeVersion or '18' }} Dockerfile
FROM node:{{ config.nodeVersion or '18' }}-alpine
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
{% if config.developmentMode %}
RUN npm install
{% else %}
RUN npm ci --only=production
{% endif %}
# Copy application code
COPY . .
{% if config.buildCommand and not config.developmentMode %}
# Build application
RUN {{ config.buildCommand }}
{% endif %}
{% endif %}
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 && \
chown -R nodejs:nodejs /app
USER nodejs
# Expose port
EXPOSE {{ config.port or '3000' }}
{% if config.developmentMode %}
# Development mode
ENV NODE_ENV=development
# Install development dependencies
CMD ["npm", "run", "dev"]
{% else %}
# Production mode
ENV NODE_ENV=production
# Start application
CMD ["node", "{{ config.entrypoint or 'index.js' }}"]
{% endif %}
|