-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
64 lines (44 loc) · 1.44 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
# Prepare environment
FROM node:14-alpine AS BUILD_IMAGE
# install dependencies of system and remove from cache
RUN apk update && apk add bash curl && rm -rf /var/cache/apk/*
# install node-prune (https://github.com/tj/node-prune)
RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin
WORKDIR /usr/src/app
COPY package.json ./
# install dependencies
RUN yarn
# copy all files
COPY . .
# build application
RUN yarn run build
# remove development dependencies
RUN npm prune --production
# node-prune removing unnecessary files from the node_modules
RUN /usr/local/bin/node-prune
# build application react
RUN cd react-app && yarn && yarn build
# remove unused dependencies manually
# RUN rm -rf node_modules/rxjs/src/
# final result
FROM node:14-alpine
WORKDIR /usr/src/app
# copy from build image
COPY --from=BUILD_IMAGE /usr/src/app/dist ./dist
COPY --from=BUILD_IMAGE /usr/src/app/node_modules ./node_modules
COPY --from=BUILD_IMAGE /usr/src/app/react-app/build ./dist/public
COPY --from=BUILD_IMAGE /usr/src/app/package.json .
RUN mkdir /usr/src/app/uploads
# Sets Arguments by default
ARG APP_VERSION=unknown
ARG RELEASE_DATE=unknown
ARG AUTHOR=unknown
LABEL release-author=$AUTHOR \
release-date=$RELEASE_DATE \
release-version=$APP_VERSION
# add permision to node user
RUN chown -R node:node /usr/src/app
# change to user node
USER node
EXPOSE 4000
CMD [ "yarn", "run", "startProd" ]