-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
59 lines (40 loc) · 1.37 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
59
FROM node:22-alpine3.18 as build-stage
WORKDIR /app
RUN apk add --no-cache libc6-compat
# Copy the package.json and package-lock.json
COPY --chown=node:node package*.json ./
# Install the dependencies
RUN npm install
# Set to production environment
ENV NODE_ENV production
# Set the Timezone
ENV TZ=Europe/Paris
# Copy source code
COPY --chown=node:node . .
# Run the prisma generate
RUN npx prisma generate
# Generate the production build. The build script runs "nest build" to compile the application.
RUN ["npm","run", "build"]
# Install only the production dependencies and clean cache to optimize image size.
RUN npm i --only=production && npm cache clean --force
# Set Docker as a non-root user
USER node
FROM node:22-alpine3.18 as production-stage
WORKDIR /app
RUN apk add --no-cache libc6-compat
# Set to production environment
ENV NODE_ENV production
# Set the Timezone
ENV TZ=Europe/Paris
# Copy only the necessary files
COPY --chown=node:node --from=build-stage /app/dist dist
COPY --chown=node:node --from=build-stage /app/node_modules node_modules
COPY --chown=node:node --from=build-stage /app/package.json /app
# Copy the prisma folder (schema + migrations)
COPY --chown=node:node --from=build-stage /app/prisma prisma
RUN mkdir -p /app/logs && chmod 777 /app/logs
# Expose the port
EXPOSE 3000
# Set Docker as non-root user
USER node
CMD ["npm", "run", "start:prod"]