mirror of
https://github.com/SamyRai/tercul-frontend.git
synced 2025-12-27 02:31:34 +00:00
- Replace --frozen-lockfile with --immutable in builder stage - Replace --frozen-lockfile --production with --immutable + autoclean in production stage - This resolves the Yarn 4.9.0 deprecation warnings and build failures
56 lines
1.2 KiB
Docker
56 lines
1.2 KiB
Docker
# Multi-stage build for Node.js frontend application
|
|
FROM node:22.21.1-alpine3.20 AS builder
|
|
|
|
# Enable Corepack for Yarn 4.x
|
|
RUN corepack enable
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package.json yarn.lock ./
|
|
|
|
# Install dependencies
|
|
RUN yarn install --immutable
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN yarn build
|
|
|
|
# Production stage
|
|
FROM node:22.21.1-alpine3.20 AS production
|
|
|
|
# Enable Corepack for Yarn 4.x
|
|
RUN corepack enable
|
|
|
|
# Create app user
|
|
RUN addgroup -g 1001 -S nodejs
|
|
RUN adduser -S nextjs -u 1001
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package.json yarn.lock ./
|
|
|
|
# Install all dependencies first, then clean up dev dependencies
|
|
RUN yarn install --immutable && yarn autoclean --force
|
|
|
|
# Copy built application from builder stage
|
|
COPY --from=builder --chown=nextjs:nodejs /app/dist ./dist
|
|
|
|
# Switch to non-root user
|
|
USER nextjs
|
|
|
|
# Expose the application port
|
|
EXPOSE 3000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD node -e "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"
|
|
|
|
# Command to run the application
|
|
CMD ["yarn", "start"]
|