Skip to content

Commit 94a946c

Browse files
committed
Enhance Dockerfile: add test validation step and set production environment variable
1 parent 28945a6 commit 94a946c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

01-contenedores/contenedores-iii/doom-web/Dockerfile.multistages

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@ FROM dependencies AS test
1616
# Copy all files for testing
1717
COPY . .
1818
# Run tests
19-
RUN npm run test
19+
RUN npm run test && echo "tests passed" > /tmp/tests-passed
2020

2121
# ---- Release ----
2222
FROM base AS release
23-
# Add environment variables
24-
# ENV NODE_ENV production
25-
# Copy only necessary files
23+
24+
ENV NODE_ENV=production
25+
26+
# Copy tests validation file (forces test execution)
27+
COPY --from=test /tmp/tests-passed /tmp/
28+
29+
# Install only production dependencies
2630
RUN npm install --omit=dev
31+
32+
# Copy all files
2733
COPY . .
34+
2835
# Expose port and define CMD
2936
EXPOSE 3000
30-
# Specify what command it'll execute when you create a container
3137
CMD ["npm", "start"]

0 commit comments

Comments
 (0)