From f53cb76ffda7c7c076ed7dc34ad8c9a582e89a1a Mon Sep 17 00:00:00 2001 From: Kyle Verhoog Date: Mon, 12 Feb 2024 22:47:01 -0500 Subject: [PATCH] Optimize docker image The current image is >1.2gb and not at all optimized. We can utilize the python-slim base image and remove unnecessary files in the image. With these changes we cut the image size to less than half (500mb on my local machine). --- Dockerfile | 9 ++++++++- .../notes/image-optimization-d614eccb59441217.yaml | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/image-optimization-d614eccb59441217.yaml diff --git a/Dockerfile b/Dockerfile index 4bb29006..0009a11c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12 +FROM python:3.12-slim EXPOSE 8126 @@ -6,8 +6,15 @@ ENV SNAPSHOT_CI=1 ENV LOG_LEVEL=INFO ENV SNAPSHOT_DIR=/snapshots +RUN apt update && apt install -y git + RUN mkdir -p /src WORKDIR /src COPY . /src RUN pip install /src + +# Cleanup +RUN apt remove -y git +RUN rm -rf /var/lib/apt/lists/* /root/.cache/pip /tmp/* /var/tmp/* /src + CMD ["ddapm-test-agent"] diff --git a/releasenotes/notes/image-optimization-d614eccb59441217.yaml b/releasenotes/notes/image-optimization-d614eccb59441217.yaml new file mode 100644 index 00000000..4009420b --- /dev/null +++ b/releasenotes/notes/image-optimization-d614eccb59441217.yaml @@ -0,0 +1,4 @@ +--- +other: + - | + The image size has been cut roughly in half.