1
+ # this dockerfile has two stages, a build stage and the executable stage.
2
+ # the build stage is responsible for building the frontend, the backend,
3
+ # and the frontend's static assets. ideally, we could build the frontend and backend
4
+ # independently and in parallel in different stages, but there is a dependency
5
+ # on the backend to build those assets. until we fix that, this approach is
6
+ # the best way to minimize the number of node_module restores and build steps
7
+ # while still keeping the final image small.
8
+
1
9
FROM node:18.15.0-alpine as build
10
+
11
+ # build time args and environment variables
12
+ ARG SERVER_TLS_CERT
13
+ ARG SERVER_TLS_KEY
14
+ ARG SEGMENT_WRITE_KEY
15
+ ENV SERVER_TLS_CERT=${SERVER_TLS_CERT}
16
+ ENV SERVER_TLS_KEY=${SERVER_TLS_KEY}
17
+ ENV SEGMENT_WRITE_KEY=${SEGMENT_WRITE_KEY}
18
+
19
+ # update apk repository and install build dependencies
2
20
RUN apk update
3
21
RUN apk add --no-cache --virtual .gyp \
4
22
python3 \
5
23
make \
6
24
g++ \
7
25
net-tools
26
+
27
+ # set workdir
8
28
WORKDIR /usr/src/app
29
+
30
+ # restore node_modules for front-end
9
31
COPY package.json yarn.lock babel.config.cjs tsconfig.json ./
10
32
RUN SKIP_POSTINSTALL=1 yarn install
33
+
34
+ # prepare backend by copying scripts/configs and installing node modules
35
+ # this is required to build the static assets
11
36
COPY configs ./configs
12
37
COPY scripts ./scripts
13
38
COPY redisinsight ./redisinsight
14
39
RUN yarn --cwd redisinsight/api install
15
- ARG SERVER_TLS_CERT
16
- ARG SERVER_TLS_KEY
17
- ARG SEGMENT_WRITE_KEY
18
- ENV SERVER_TLS_CERT=${SERVER_TLS_CERT}
19
- ENV SERVER_TLS_KEY=${SERVER_TLS_KEY}
20
- ENV SEGMENT_WRITE_KEY=${SEGMENT_WRITE_KEY}
40
+
41
+ # build the frontend, static assets, and backend api
21
42
RUN yarn build:web
22
43
RUN yarn build:statics
23
44
RUN yarn build:prod
45
+
46
+ # install backend _again_ to build native modules and remove dev dependencies,
47
+ # then run autoclean to remove additional unnecessary files
24
48
RUN yarn --cwd ./redisinsight/api install --production
25
49
COPY ./redisinsight/api/.yarnclean.prod ./redisinsight/api/.yarnclean
26
50
RUN yarn --cwd ./redisinsight/api autoclean --force
27
51
28
52
FROM node:18.15.0-alpine
29
53
54
+ # runtime args and environment variables
30
55
ARG NODE_ENV=production
31
56
ARG SERVER_TLS_CERT
32
57
ARG SERVER_TLS_KEY
@@ -37,16 +62,24 @@ ENV SEGMENT_WRITE_KEY=${SEGMENT_WRITE_KEY}
37
62
ENV NODE_ENV=${NODE_ENV}
38
63
ENV SERVER_STATIC_CONTENT=true
39
64
ENV BUILD_TYPE='DOCKER_ON_PREMISE'
65
+
66
+ # set workdir
40
67
WORKDIR /usr/src/app
68
+
69
+ # copy artifacts built in previous stage to this one
41
70
COPY --from=build /usr/src/app/redisinsight/api/dist ./redisinsight/api/dist
42
71
COPY --from=build /usr/src/app/redisinsight/api/node_modules ./redisinsight/api/node_modules
43
72
COPY --from=build /usr/src/app/redisinsight/ui/dist ./redisinsight/ui/dist
44
73
74
+ # copy the docker entry point script and make it executable
45
75
COPY ./docker-entry.sh ./
46
76
RUN chmod +x docker-entry.sh
47
77
78
+ # since RI is hard-code to port 5000, expose it from the container
48
79
EXPOSE 5000
49
80
81
+ # don't run the node process as root
50
82
USER node
51
83
84
+ # serve the application 🚀
52
85
ENTRYPOINT ["./docker-entry.sh" , "node" , "redisinsight/api/dist/src/main" ]
0 commit comments