diff --git a/Changelog.md b/Changelog.md index c2902c43a..b01b5106b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 diff --git a/Dockerfile b/Dockerfile index 0dfbf7f86..0f31c10cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 && \ @@ -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"]