|
| 1 | +# Stage 1: Build |
| 2 | +FROM node:20-alpine AS builder |
| 3 | + |
| 4 | +# Install Yarn globally |
| 5 | +RUN corepack enable && corepack prepare yarn@1.22.22 --activate |
| 6 | + |
| 7 | +# Set working directory |
| 8 | +WORKDIR /app |
| 9 | + |
| 10 | +# Copy package files |
| 11 | +COPY package.json yarn.lock ./ |
| 12 | + |
| 13 | +# Install all dependencies (including devDependencies for build) |
| 14 | +# Skip scripts to prevent prepare hook from running before source is copied |
| 15 | +RUN yarn install --frozen-lockfile --ignore-scripts |
| 16 | + |
| 17 | +# Copy source code |
| 18 | +COPY . . |
| 19 | + |
| 20 | +# Build the application (compile TypeScript + copy static assets) |
| 21 | +RUN yarn build |
| 22 | + |
| 23 | +# Stage 2: Production |
| 24 | +FROM node:20-alpine |
| 25 | + |
| 26 | +# Install Yarn globally |
| 27 | +RUN corepack enable && corepack prepare yarn@1.22.22 --activate |
| 28 | + |
| 29 | +# Set working directory |
| 30 | +WORKDIR /app |
| 31 | + |
| 32 | +# Copy package files |
| 33 | +COPY package.json yarn.lock ./ |
| 34 | + |
| 35 | +# Install only production dependencies |
| 36 | +# Skip scripts since we're only copying pre-built artifacts |
| 37 | +RUN yarn install --frozen-lockfile --production --ignore-scripts |
| 38 | + |
| 39 | +# Copy built application from builder stage |
| 40 | +COPY --from=builder /app/dist ./dist |
| 41 | + |
| 42 | +# Copy config directory structure (for config.json mount point) |
| 43 | +# Note: example.config.json is already in dist/config/ from the build process |
| 44 | +# This ensures the directory structure exists for the volume mount |
| 45 | +COPY --from=builder /app/dist/config/example.config.json ./dist/config/ |
| 46 | + |
| 47 | +# Create proto_samples directory |
| 48 | +RUN mkdir -p proto_samples |
| 49 | + |
| 50 | +# Expose the default port |
| 51 | +EXPOSE 8081 |
| 52 | + |
| 53 | +# Set NODE_ENV to production |
| 54 | +ENV NODE_ENV=production |
| 55 | + |
| 56 | +# Health check |
| 57 | +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ |
| 58 | + CMD node -e "require('http').get('http://localhost:8081/', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" |
| 59 | + |
| 60 | +# Start the application |
| 61 | +CMD ["node", "dist/index.js"] |
0 commit comments