-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
55 lines (39 loc) · 1.3 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
FROM node:12.16.2-alpine as build
# Arguments
ARG SERVICE_PORT
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV \
SERVICE_PORT=$SERVICE_PORT \
APP_DIR="/usr/src/preggies"
RUN mkdir -p $APP_DIR
RUN apk add --no-cache git
WORKDIR $APP_DIR
COPY package.json $APP_DIR
RUN yarn install
COPY . .
RUN yarn build
# Production container
FROM node:12.16.2-alpine
ARG NODE_ENV
ARG SERVICE_PORT
# Configuration
ENV SERVICE_PORT=$SERVICE_PORT \
SERVICE_USER=preggies \
SERVICE_USER_ID=1001 \
SERVICE_GROUP=preggies \
SERVICE_GROUP_ID=1001 \
APP_DIR=/usr/src/preggies \
NODE_ENV=$NODE_ENV
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR
RUN addgroup -g $SERVICE_GROUP_ID $SERVICE_GROUP \
&& adduser -D -u $SERVICE_USER_ID -G $SERVICE_GROUP $SERVICE_USER \
&& chown -R $SERVICE_USER:$SERVICE_GROUP $APP_DIR
USER $SERVICE_USER
COPY --chown=$SERVICE_USER:$SERVICE_GROUP --from=build $APP_DIR/lib $APP_DIR/lib
# COPY --chown=$SERVICE_USER:$SERVICE_GROUP --from=build $APP_DIR/node_modules $APP_DIR/node_modules
COPY --chown=$SERVICE_USER:$SERVICE_GROUP --from=build $APP_DIR/package.json $APP_DIR/package.json
COPY --chown=$SERVICE_USER:$SERVICE_GROUP --from=build $APP_DIR/yarn.lock $APP_DIR/yarn.lock
RUN yarn install --prod --cache-folder /tmp/ycache; rm -Rf /tmp/ycache
EXPOSE $SERVICE_PORT
CMD ["yarn", "start"]