-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
executable file
·73 lines (58 loc) · 2.2 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
ARG NODE_VERSION=20.18.1
FROM node:$NODE_VERSION
# Run install in development for devDependencies/dependencies to be installed correctly
ENV NODE_ENV development
ARG BUILD_MODE=production
ENV BUILD_MODE $BUILD_MODE
RUN npm i npm@latest -g
# Create app directory
RUN mkdir /usr/src/app && mkdir /usr/src/app/therr-services && mkdir /usr/src/app/therr-services/websocket-service && chown -R node:node /usr/src/app
WORKDIR /usr/src/app
# the official node image provides an unprivileged user as a security best practice
# but we have to manually enable it. We put it here so npm installs dependencies as the same
# user who runs the app.
# https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user
USER node
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# Note: This is the root mono-repo directory
COPY package*.json ./
COPY .babelrc ./
COPY global-config.js ./
COPY webpack.parts.js ./
COPY ./node_modules ./node_modules
COPY therr-public-library ./therr-public-library
# Set libary directory permissions
USER root
RUN chown -R node:node /usr/src/app
USER node
# Install dependencies and set PATH variable
# Even in production, install devDependencies
# RUN npm ci --no-optional
ENV PATH $PATH:/usr/src/app/node_modules/.bin:$PATH
# Install and build libraries
WORKDIR /usr/src/app/therr-public-library/therr-js-utilities
RUN npm run build
# Copy main app files
WORKDIR /usr/src/app
COPY ./therr-services/websocket-service ./therr-services/websocket-service
USER root
RUN chown -R node:node /usr/src/app/therr-services/websocket-service
USER node
WORKDIR /usr/src/app/therr-services/websocket-service
RUN if [ "$BUILD_MODE" = "development" ]; then \
echo "Building in $BUILD_MODE mode" \
&& npm run build:dev; \
else \
echo "Building in $BUILD_MODE mode" \
&& npm run build;\
fi
# check every 30s to ensure this service returns HTTP 200
# HEALTHCHECK --interval=30s CMD node healthcheck.js
# Run app with an environment equal to the mode that it was built
ARG BUILD_MODE=production
ENV BUILD_MODE $BUILD_MODE
ENV NODE_ENV $BUILD_MODE
RUN echo "Running app in $NODE_ENV"
EXPOSE 7743
CMD ["node", "./build/server.js"]