-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
58 lines (41 loc) · 1.52 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1.4
ARG NODE_VERSION=18
################################################################################
# Base image for all stages
FROM node:${NODE_VERSION}-alpine AS base
# Set the working directory
WORKDIR /usr/src/app
# Install essential build tools
# TODO: Uncomment the command if you really need these dependancies
# RUN apk add --no-cache python3 make g++
################################################################################
# Dependencies stage
FROM base AS deps
# Copy package.json and package-lock.json for dependency installation
COPY package.json package-lock.json* ./
# Install only production dependencies for optimized builds
RUN npm ci --only=production
################################################################################
# Build stage (if needed for assets or complex builds)
FROM base AS build
# Copy all source files for building
COPY . .
# Install full dependencies for building (including devDependencies)
RUN npm ci
# ? Example build step (if your project has one)
# RUN npm run build
################################################################################
# Production stage (final)
FROM base AS final
# Set environment to production
ENV NODE_ENV=production
# * Switch to non-root user for security
USER node
# * Copy only essential files from previous stages
COPY package.json .
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app .
# Expose the app port
EXPOSE 3000
# Start the application
CMD ["npm", "start"]