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

Cleanup Dockerfile and convert non-distributable handling to ONBUILD #179

Merged
merged 5 commits into from
Sep 4, 2024

Conversation

mmlb
Copy link
Member

@mmlb mmlb commented Aug 30, 2024

What does this PR do

Bunch of minor (imo) clean ups to the Dockerfile and scripts/install-non-distributable.sh to start.
Then converts the whole fetching of non-distributable files from at ironlib image build time to ONBUILD and thus when consumers build their own images based off of ironlib's image.

This looks similar to how we used to do things before except there's better handling for skipping all of it by keeping what we do today of requiring a build-arg to opt in to proprietary deps. The old ONBBUILD setup used to check for presence of the fetcher script to decide to run the fetch. That was annoying because consumers would need a whole Dockerfile/repo setup just to have the script.

How can this change be tested by a PR reviewer?

Build this docker image with/without the args to opt-in to proprietary binaries, there should be no difference between the 2 images. Lets assume you tag it my-local-ironlib.

Now do the same with/without build using the following Dockerfile:

FROM ghcr.io/metal-toolbox/vogelkop:v0.4.0 AS vogelkop

FROM my-local-ironlib
COPY --from=vogelkop /usr/sbin/vogelkop /usr/sbin/vogelkop

Running docker build --build-arg INSTALL_NON_DISTRIBUTABLE=true will fail and complain about missing AWS creds. Build again with the build-arg and it will complete. Also note that since no ARG is present in this example Dockerfile the secrets do not leak into the final image (verification left up to reader).

Dockerfile Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
mmlb added 5 commits September 3, 2024 09:36
Add files that do not get used by Dockerfile so that changes to these
files do not bust layer cache when building examples and the later
stages.
Nothing too crazy here:

* Better named intermediate stages
* Better indentation for readability
* No need to add extra args to microdnf (verified same number of
  packages installed with/without args)
* No need for both ARG and ENV as ARG already exports to the environment
* Make RUN step easier to read by skipping in bash script instead
Change from minio to s5cmd because s5cmd is plain faster, has batch
support for easier use and plays better with AWS env vars that everyone
else has standardized on.

Clean up the rest of the script by doing a better job explicitly
checking the environment variables early and with better error messages.
Also take advantage of `set -e` to avoid `&&` and indentation.
This way downstream consumers do not need to fork or otherwise build the
ironlib image to add the non-distributable binaries. Take vogelkop as an
example, OSS Dockerfile can depend on this image just fine. Downstream
users can then do something like:

```Dockerfile
FROM $vogelkopimage AS vogelkop

FROM $ironlibimage
COPY --from=vogelkop /usr/bin/vogelkop /usr/bin

```

And then provide the values for ONBUILD on the docker command line to
fetch the non-distributable files. No need to fork ironlib nor
vogelkop's Dockerfiles!
@mmlb mmlb force-pushed the rework-docker-builds branch from 754a225 to f909b99 Compare September 3, 2024 13:37
@mmlb mmlb requested a review from joelrebel September 3, 2024 13:37
Copy link
Member

@joelrebel joelrebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this up!

@mmlb mmlb enabled auto-merge September 4, 2024 13:23
@mmlb mmlb merged commit e153616 into metal-toolbox:main Sep 4, 2024
5 checks passed
@mmlb mmlb deleted the rework-docker-builds branch September 4, 2024 13:23
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

Successfully merging this pull request may close these issues.

2 participants