-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerfile.prod
55 lines (30 loc) · 981 Bytes
/
dockerfile.prod
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
#! 1. Dependencias
FROM node:21-alpine3.19 AS deps
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
#! 2. Builder - Construye la aplicacion
FROM node:21-alpine3.19 AS build
# Esta es la forma en la que, por asi decirlo, recibimos
# las variables que han sido enviadas en tiempo de
# construccion, asi como la forma en la que hacemos
# referencia a las mismas dentro de nuestro dockerfile
ARG ORDERS_DATABSE_URL
ENV DATABASE_URL=$ORDERS_DATABASE_URL
WORKDIR /usr/src/app
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY . .
RUN npx prisma migrate deploy
RUN npx prisma generate
# RUN npm run test
RUN npm run build
RUN npm ci -f --only=production && npm cache clean --force
#! 3. Crear la imagen final
FROM node:21-alpine3.19 AS prod
WORKDIR /usr/src/app
COPY --from=build /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/dist ./dist
ENV NODE_ENV=production
USER node
EXPOSE 3000
CMD [ "node", "dist/main.js" ]