Skip to content

Commit a79a0d3

Browse files
authored
Dockerfile enhancement: multistage build (#991)
This issue aims to refactor the current Dockerfile to use a multistage build approach. The motivation for this change is to: 1. Reduce final image size by excluding unnecessary build-time dependencies (e.g., gcc, libpython3-dev, etc.) 2. Enhance maintainability by clearly separating build and runtime concerns ``` Size of the current docker image: 3.82GB Size of the docker image after multi-stage build: 1.06GB ``` Closes #990
1 parent e508241 commit a79a0d3

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Diff for: Dockerfile

+18-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
# * Install python3-venv for the built-in Python3 venv module (not installed by default).
1717
# * Install gcloud CLI from Google Cloud's apt repository.
1818

19-
FROM debian:12
19+
# Stage 1: Build
20+
FROM debian:12 AS build
2021
# Install packages used by the Experiment. Python and Git are required for the experiment.
2122
# Curl, certs, and gnupg are required to install gcloud.
2223
RUN apt-get update && \
@@ -32,27 +33,27 @@ RUN apt-get update && \
3233
wget2 \
3334
clang-format && \
3435
python3 -m venv /venv
36+
3537
# Install gcloud cli.
3638
RUN echo "deb https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
3739
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
3840
apt-get update -y && \
3941
apt-get install google-cloud-cli -y
40-
# Set timezone to Australia/Sydney.
41-
ENV TZ='Australia/Sydney'
42-
43-
42+
4443
# Install Docker for OSS-Fuzz.
4544
# Add Docker's official GPG key:
4645
RUN apt-get install ca-certificates curl gnupg && \
4746
install -m 0755 -d /etc/apt/keyrings && \
4847
curl -fsSL https://download.docker.com/linux/debian/gpg \
4948
| gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
5049
chmod a+r /etc/apt/keyrings/docker.gpg
50+
5151
# Add the repository to Apt sources:
5252
RUN echo \
5353
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
5454
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
5555
tee /etc/apt/sources.list.d/docker.list > /dev/null
56+
5657
RUN apt-get update && \
5758
apt-get install -y \
5859
docker-ce \
@@ -61,8 +62,17 @@ RUN apt-get update && \
6162
docker-buildx-plugin \
6263
docker-compose-plugin
6364

64-
6565
COPY . /experiment
6666
WORKDIR /experiment
67-
RUN /venv/bin/pip install --disable-pip-version-check -r requirements.txt
68-
ENTRYPOINT ["/venv/bin/python3", "./report/docker_run.py"]
67+
RUN /venv/bin/pip install --disable-pip-version-check --default-timeout=100 -r requirements.txt
68+
69+
# Stage 2: Runtime
70+
FROM debian:12
71+
# Set timezone to Australia/Sydney.
72+
ENV TZ='Australia/Sydney'
73+
74+
COPY --from=build /venv /venv
75+
COPY --from=build /experiment /experiment
76+
WORKDIR /experiment
77+
78+
ENTRYPOINT ["/venv/bin/python3", "./report/docker_run.py"]

0 commit comments

Comments
 (0)