-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Dockerfile
68 lines (59 loc) · 2.09 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
# First stage: cache the dev dependencies.
FROM node:alpine as dev-dependencies
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# Create the user and group files that will be used in the running container to
# run the process as an unprivileged user.
RUN mkdir /user && \
echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
echo 'nobody:x:65534:' > /user/group
# Second stage: cache the prod dependencies.
FROM node:alpine as prod-dependencies
WORKDIR /app
COPY package.api.json package.json
RUN npm i --production
# Third stage: build the executable.
FROM node:alpine as builder
WORKDIR /app
COPY --from=dev-dependencies /app /app
COPY apps/api apps/api
COPY libs/models libs/models
COPY libs/utils libs/utils
COPY tools/hooks/api.webpack.js tools/hooks/api.webpack.js
COPY angular.json nx.json tsconfig.json ./
RUN npm i typescript@3.1.6
ENV NODE_ENV production
RUN $(npm bin)/ng build api --prod
# Final stage: the running container.
#FROM astefanutti/scratch-node
#COPY --from=busybox:1.30.1 /bin/busybox /bin/busybox
FROM mhart/alpine-node:11
# Import the user and group files from the first stage.
COPY --from=dev-dependencies /user/group /user/passwd /etc/
COPY --from=prod-dependencies /app .
COPY --from=builder /app/dist/apps/api .
EXPOSE 3000
# Perform any further action as an unprivileged user.
USER nobody:nobody
# Metadata params
ARG VERSION=0.0.1
ARG BUILD_DATE
ARG VCS_URL=ngx-starter-kit
ARG VCS_REF=1
ARG NAME=ngxapi
ARG VENDOR=sumo
# Metadata
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name=$NAME \
org.label-schema.description="NGX Api" \
org.label-schema.url="https://example.com" \
org.label-schema.vcs-url=https://github.com/xmlking/$VCS_URL \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vendor=$VENDOR \
org.label-schema.version=$VERSION \
org.label-schema.docker.schema-version="1.0" \
org.label-schema.docker.cmd="docker run -it -p 3000:3000 xmlking/ngxapi"
ENTRYPOINT ["node", "main.js"]
# TODO:
# https://github.com/alextanhongpin/go-docker-multi-stage-build/blob/master/Dockerfile