-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
42 lines (28 loc) · 959 Bytes
/
dockerfile
File metadata and controls
42 lines (28 loc) · 959 Bytes
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
# Stage 1: Install dependencies and run tests
FROM node:14-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy package.json and package-lock.json
COPY package.json ./
# Install all dependencies including devDependencies for testing
RUN npm install
# Copy the entire application code to the working directory
COPY . .
# Run tests
RUN npm test
# Stage 2: Build the production image
FROM node:14-alpine AS production
# Set the working directory inside the container
WORKDIR /app
# Copy package.json and package-lock.json (if available)
COPY package.json ./
# Set the environment to production
ENV NODE_ENV=production
# Install only production dependencies
RUN npm install --only=production
# Copy the application code from the builder stage, excluding dev dependencies and test code
COPY --from=builder /app .
# Expose the port your app runs on
EXPOSE 80
# Define the command to run your app
CMD ["npm", "start"]