quarkusio / quarkus-images

Set of container images delivered for Quarkus
Apache License 2.0
115 stars 76 forks source link

Reduce builder image size #240

Open MrLuje opened 1 year ago

MrLuje commented 1 year ago

I was looking at quay.io/quarkus/ubi-quarkus-graalvmce-builder-image:22.3.2-java17-amd64 with dive and noticed it reported a temporary file costing ~250MB on the final image image

This can be avoided by using a multistage build and extracting the tar in another stage. image

From what I see, the biggest gain are on the following images but the same fix could be applied to any image using artifacts :

I'll first open a PR for ubi-quarkus-graalvmce-builder-image and ubi-quarkus-graalvmce-s2i since they share the same module

cescoffier commented 1 year ago

Builder images do not try to be small, but in this case, yes.

Just adding a rm in the script should work.

MrLuje commented 1 year ago

Just adding a rm in the script should work.

Unfortunately no, it must be copied, extracted and deleted in the same operation for it to not being recorded in the layer. IMHO a good solution would be to use RUN --mount=type=bind,source=...,target=... syntax (https://github.com/moby/buildkit/blob/v0.10/frontend/dockerfile/docs/syntax.md#run---mounttypebind-the-default-mount-type) to mount the temp file directly during the RUN command :

- COPY /target/artifacts/graalvm-jdk-17.0.7-linux-x64.tar.gz /tmp/graalvm/graalvm-jdk-17.0.7-linux-x64.tar.gz
RUN 
+ --mount=type=bind,source=/target/artifacts/graalvm-jdk-17.0.7-linux-x64.tar.gz,target=/tmp/graalvm/graalvm-jdk-17.0.7-linux-x64.tar.gz \
    tar xzf /tmp/graalvm/graalvm-jdk-17.0.7-linux-x64.tar.gz -C /opt \
    && mv /opt/graalvm-community-openjdk-17.0.7* /opt/graalvm \
-    && rm -Rf /tmp/graalvm-jdk-17.0.7-linux-x64.tar.gz

If that's ok with you, I'll open a PR with it

cescoffier commented 1 year ago

Does that command works with podman?

MrLuje commented 1 year ago

I'm not really familiar with Podman but with version 4.5.1, it worked (aliased docker to podman) Will it be caught by CI if there are compatibility issues ?