Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce builder image size #240

Open
MrLuje opened this issue Jun 17, 2023 · 4 comments
Open

Reduce builder image size #240

MrLuje opened this issue Jun 17, 2023 · 4 comments

Comments

@MrLuje
Copy link

MrLuje commented Jun 17, 2023

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 :

  • ubi-quarkus-graalvmce-s2i
  • ubi-quarkus-mandrel-builder-image

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

@cescoffier
Copy link
Member

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

Just adding a rm in the script should work.

@cescoffier cescoffier changed the title Optimize builder images Reduce builder image size Jun 18, 2023
@MrLuje
Copy link
Author

MrLuje commented Jun 25, 2023

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
Copy link
Member

Does that command works with podman?

@MrLuje
Copy link
Author

MrLuje commented Jun 25, 2023

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants