|
1 | | -# Use Node.js 18 Alpine for smaller image size |
2 | | -FROM node:22-alpine |
| 1 | +# Multi-stage Docker build for Tolgee CLI |
| 2 | +# Stage 1: Build stage with dev dependencies |
| 3 | +FROM node:18-alpine AS builder |
3 | 4 |
|
4 | 5 | # Set working directory |
5 | 6 | WORKDIR /app |
6 | 7 |
|
7 | | -# Copy package.json and package-lock.json first for better Docker layer caching |
| 8 | +# Copy package files first for better Docker layer caching |
8 | 9 | COPY package*.json ./ |
9 | 10 |
|
10 | | -# Install all dependencies (including dev dependencies needed by the built code) |
| 11 | +# Install ALL dependencies (including dev dependencies needed for building) |
11 | 12 | RUN npm ci && npm cache clean --force |
12 | 13 |
|
13 | | -# Copy built application files (as specified in package.json "files" section) |
14 | | -COPY dist/ ./dist/ |
| 14 | +# Copy source files |
| 15 | +COPY src/ ./src/ |
| 16 | +COPY scripts/ ./scripts/ |
| 17 | +COPY tsconfig*.json ./ |
| 18 | +COPY eslint.config.js ./ |
| 19 | + |
| 20 | +# Copy additional files needed for build |
15 | 21 | COPY textmate/ ./textmate/ |
16 | 22 | COPY extractor.d.ts ./ |
17 | 23 | COPY schema.json ./ |
| 24 | + |
| 25 | +# Build the CLI |
| 26 | +RUN npm run build |
| 27 | + |
| 28 | +# Stage 2: Production stage with only runtime dependencies |
| 29 | +FROM node:18-alpine AS production |
| 30 | + |
| 31 | +# Set working directory |
| 32 | +WORKDIR /app |
| 33 | + |
| 34 | +# Copy package files first for better Docker layer caching |
| 35 | +COPY package*.json ./ |
| 36 | + |
| 37 | +# Install ONLY production dependencies |
| 38 | +RUN npm ci --only=production && npm cache clean --force |
| 39 | + |
| 40 | +# Copy built application files from builder stage |
| 41 | +COPY --from=builder /app/dist/ ./dist/ |
| 42 | +COPY --from=builder /app/textmate/ ./textmate/ |
| 43 | +COPY --from=builder /app/extractor.d.ts ./ |
| 44 | +COPY --from=builder /app/schema.json ./ |
| 45 | + |
| 46 | +# Copy documentation files |
18 | 47 | COPY README.md ./ |
19 | 48 | COPY LICENSE ./ |
20 | 49 |
|
21 | | -# Copy node_modules for runtime dependencies |
22 | | -COPY node_modules/ ./node_modules/ |
23 | | - |
24 | 50 | # Make the CLI binary executable |
25 | 51 | RUN chmod +x ./dist/cli.js |
26 | 52 |
|
|
0 commit comments