Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 4cd8776

Browse files
RI-5036: Comment dockerfile to explain rationale and describe steps
1 parent 4ad5bea commit 4cd8776

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

Dockerfile

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,57 @@
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+
19
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
220
RUN apk update
321
RUN apk add --no-cache --virtual .gyp \
422
python3 \
523
make \
624
g++ \
725
net-tools
26+
27+
# set workdir
828
WORKDIR /usr/src/app
29+
30+
# restore node_modules for front-end
931
COPY package.json yarn.lock babel.config.cjs tsconfig.json ./
1032
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
1136
COPY configs ./configs
1237
COPY scripts ./scripts
1338
COPY redisinsight ./redisinsight
1439
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
2142
RUN yarn build:web
2243
RUN yarn build:statics
2344
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
2448
RUN yarn --cwd ./redisinsight/api install --production
2549
COPY ./redisinsight/api/.yarnclean.prod ./redisinsight/api/.yarnclean
2650
RUN yarn --cwd ./redisinsight/api autoclean --force
2751

2852
FROM node:18.15.0-alpine
2953

54+
# runtime args and environment variables
3055
ARG NODE_ENV=production
3156
ARG SERVER_TLS_CERT
3257
ARG SERVER_TLS_KEY
@@ -37,16 +62,24 @@ ENV SEGMENT_WRITE_KEY=${SEGMENT_WRITE_KEY}
3762
ENV NODE_ENV=${NODE_ENV}
3863
ENV SERVER_STATIC_CONTENT=true
3964
ENV BUILD_TYPE='DOCKER_ON_PREMISE'
65+
66+
# set workdir
4067
WORKDIR /usr/src/app
68+
69+
# copy artifacts built in previous stage to this one
4170
COPY --from=build /usr/src/app/redisinsight/api/dist ./redisinsight/api/dist
4271
COPY --from=build /usr/src/app/redisinsight/api/node_modules ./redisinsight/api/node_modules
4372
COPY --from=build /usr/src/app/redisinsight/ui/dist ./redisinsight/ui/dist
4473

74+
# copy the docker entry point script and make it executable
4575
COPY ./docker-entry.sh ./
4676
RUN chmod +x docker-entry.sh
4777

78+
# since RI is hard-code to port 5000, expose it from the container
4879
EXPOSE 5000
4980

81+
# don't run the node process as root
5082
USER node
5183

84+
# serve the application 🚀
5285
ENTRYPOINT ["./docker-entry.sh", "node", "redisinsight/api/dist/src/main"]

docker-entry.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
# `docker run`
88
set -e
99

10-
echo "Running docker-entry.sh as:"
11-
whoami
10+
echo "Running docker-entry.sh"
1211

1312
# Run the application's entry script with the exec command so it catches SIGTERM properly
1413
exec "$@"

0 commit comments

Comments
 (0)