Skip to content

Commit

Permalink
Reduce size of Docker image (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcginnes authored Sep 19, 2024
1 parent c6c03eb commit 52283ba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- **Fixed** Docker image containing more files than necessary.
([#613](https://github.com/aws/graph-explorer/pull/613))
- **Improved** Docker image size, reducing it by 196 MB
([#619](https://github.com/aws/graph-explorer/pull/619))
- **Improved** query generation by removing empty lines
([#608](https://github.com/aws/graph-explorer/pull/608))
- **Fixed** security vulnerabilities in the Docker image from dev dependencies
Expand Down
49 changes: 34 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
# syntax=docker/dockerfile:1
FROM amazonlinux:2023
ARG NEPTUNE_NOTEBOOK

ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION=v20.17.0
ENV NEPTUNE_NOTEBOOK=$NEPTUNE_NOTEBOOK
ENV HOME=/graph-explorer

# Conditionally set the following environment values using +/- variable expansion
# https://docs.docker.com/reference/dockerfile/#environment-replacement
#
# If NEPTUNE_NOTEBOOK value is set then
# - GRAPH_EXP_ENV_ROOT_FOLDER = /proxy/9250/explorer
# - PROXY_SERVER_HTTP_PORT = 9250
# - LOG_STYLE = cloudwatch
# Else the values are the defaults
# - GRAPH_EXP_ENV_ROOT_FOLDER = /explorer
# - PROXY_SERVER_HTTP_PORT = 80
# - LOG_STYLE = default

ENV GRAPH_EXP_ENV_ROOT_FOLDER=${NEPTUNE_NOTEBOOK:+/proxy/9250/explorer}
ENV GRAPH_EXP_ENV_ROOT_FOLDER=${GRAPH_EXP_ENV_ROOT_FOLDER:-/explorer}

ENV PROXY_SERVER_HTTP_PORT=${NEPTUNE_NOTEBOOK:+9250}
ENV PROXY_SERVER_HTTP_PORT=${PROXY_SERVER_HTTP_PORT:-80}

ENV LOG_STYLE=${NEPTUNE_NOTEBOOK:+cloudwatch}
ENV LOG_STYLE=${LOG_STYLE:-default}

WORKDIR /
COPY . /graph-explorer/
WORKDIR /graph-explorer

# Keeping all the RUN commands on a single line reduces the number of layers and,
# as a result, significantly reduces the final image size.
RUN yum update -y && \
Expand All @@ -18,26 +44,19 @@ RUN yum update -y && \
nvm use $NODE_VERSION && \
corepack enable && \
pnpm install && \
pnpm build && pnpm clean:dep && pnpm install --prod --ignore-scripts && \
yum clean all && \
yum remove -y tar gzip findutils && \
yum remove -y tar gzip findutils git && \
rm -rf /var/cache/yum && \
chmod a+x ./process-environment.sh
# Set node/npm in path so we can reuse it in the next run layer
rm -rf $HOME/.local && \
chmod a+x ./process-environment.sh && \
chmod a+x ./docker-entrypoint.sh

# Set node/npm in path so it can be used by the app when the container is run
ENV NODE_PATH=$NVM_DIR/versions/node/$NODE_VERSION/lib/node_modules
ENV PATH=$NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH
WORKDIR /graph-explorer/
ENV HOME=/graph-explorer
ENV NEPTUNE_NOTEBOOK=$NEPTUNE_NOTEBOOK
RUN if [ -n "$NEPTUNE_NOTEBOOK" ] && [ "$NEPTUNE_NOTEBOOK" = "true" ]; then \
echo "GRAPH_EXP_ENV_ROOT_FOLDER=/proxy/9250/explorer" >> ./packages/graph-explorer/.env; \
echo "PROXY_SERVER_HTTP_PORT=9250" >> ./packages/graph-explorer/.env; \
echo "LOG_STYLE=cloudwatch" >> ./packages/graph-explorer/.env; \
else \
echo "GRAPH_EXP_ENV_ROOT_FOLDER=/explorer" >> ./packages/graph-explorer/.env; \
fi && \
pnpm build && pnpm clean:dep && pnpm install --prod --ignore-scripts

EXPOSE 443
EXPOSE 80
EXPOSE 9250
RUN chmod a+x ./docker-entrypoint.sh
ENTRYPOINT ["./docker-entrypoint.sh"]

0 comments on commit 52283ba

Please sign in to comment.