-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.prod
44 lines (27 loc) · 926 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
# 1. Dependencias
FROM node:20.14.0-alpine3.20 AS deps
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
# 2. Compilar el proyecto
FROM node:20.14.0-alpine3.20 AS build
WORKDIR /usr/src/app
# Copy the node_modules from the deps stage
COPY --from=deps /usr/src/app/node_modules ./node_modules
# Copy the source code
COPY . .
# Compila el código TypeScript (acá se puede agregar el comando para ejecutar los tests)
RUN npm run build
# Limpia las dependencias de desarrollo y limpia la caché
RUN npm prune --omit=dev && npm cache clean --force
# 3. Crear la imagen de Docker
FROM node:20.14.0-alpine3.20 AS prod
WORKDIR /usr/src/app
# Copia los archivos de la etapa de construcción
COPY --from=build /usr/src/app/node_modules ./node_modules
# Copia los archivos de la etapa de construcción
COPY --from=build /usr/src/app/dist ./dist
ENV PORT=3000
USER node
EXPOSE 3000
CMD ["node", "dist/main.js"]