-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
79 lines (56 loc) · 1.75 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
######################
##### Base stage #####
######################
# Base image with alias
FROM alpine:3.7 as base
# Create and define work directory
WORKDIR /code
# Install Node.js
RUN apk --update --no-cache add nodejs
# Expose application port
EXPOSE 8080
# Copy only the minimal required files
COPY package.json /code/
##############################
##### Dependencies stage #####
##############################
# Dependencies image with alias
FROM base as dependencies
# Copy only the minimal required files
COPY package-lock.json /code/
# Update system, install dependencies, install npm production dependencies
RUN apk --update --no-cache add --virtual build-dependencies make gcc g++ python && \
npm set progress=false && \
npm install --silent --production
###########################
###### Develop stage ######
###########################
# Develop image with alias
FROM dependencies as develop
# Add environment vars for development mode
ENV NODE_ENV=development
# Install npm development dependencies
RUN npm set progress=false && \
npm install --silent
# Copy source files
COPY ./ /code
# Build application
RUN npm run build
#########################
##### Release stage #####
#########################
# Release image with alias
FROM base as release
# Add environment vars for production
ENV NODE_ENV=production
# Copy only required files to run the production application
COPY --from=dependencies /code/node_modules /code/node_modules
COPY --from=develop /code/build /code/build
# Create dedicated user to not run the application as root (security best practice)
RUN adduser -D -h /code -u 5000 myuser && \
chown -R myuser:myuser /code
USER myuser
# Define entrypoint
ENTRYPOINT ["npm", "run"]
# Define default command
CMD ["start"]