-
thibault.capt authoredthibault.capt authored
Dockerfile 1.35 KiB
# syntax=docker/dockerfile:1
# Define build arguments for Node.js and pnpm versions
ARG NODE_VERSION=20.11.1
ARG PNPM_VERSION=10.4.1
# Base image for development and building
FROM node:${NODE_VERSION} AS base
# Update Corepack and enable pnpm
RUN npm install --global corepack@latest && corepack enable && corepack prepare pnpm@${PNPM_VERSION} --activate
# Set working directory
WORKDIR /app
# Builder stage for compiling the Angular application
FROM base AS builder
# Copy package manager files
COPY package.json pnpm-lock.yaml ./
# Install dependencies with pnpm
RUN --mount=type=cache,target=/root/.pnpm-store pnpm install --frozen-lockfile
# Copy application source code
COPY . ./
# Build the Angular application
RUN pnpm run build
# Production stage with a minimal image
FROM node:${NODE_VERSION}-slim AS final
# Update Corepack and enable pnpm
RUN npm install --global corepack@latest && corepack enable && corepack prepare pnpm@${PNPM_VERSION} --activate
# Set working directory
WORKDIR /app
# Copy built application and necessary files from builder stage
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./
COPY --from=builder /app/node_modules ./node_modules
# Set environment to production
ENV NODE_ENV=production
# Expose the default Angular port
EXPOSE 4200
# Start the Angular application
CMD ["npx", "http-server", "dist"]