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

feat: Improve Containerfile / enable workflow usage of containerized buildah (tag: v1) #604

Merged
merged 11 commits into from
Jul 18, 2024

Conversation

m0gg
Copy link
Contributor

@m0gg m0gg commented Jul 11, 2024

These are the first bits of my suggestions to improve the buildprocess via Containerfile.
Before going any further, i'd like to hear some feedback whether these kind of refactorings are welcome or not.

@m0gg m0gg changed the title WIP: Improve Containerfile WIP/RFC: Improve Containerfile - Jul 11, 2024
@m0gg m0gg changed the title WIP/RFC: Improve Containerfile - WIP/RFC: Improve Containerfile Jul 11, 2024
@m2Giles
Copy link
Member

m2Giles commented Jul 11, 2024

Thank you for this. One thing is that we don't build with a new enough version of podman to take advantage of heredoc. It's extremely sad and unfortunate.

It looks like most of the changes are taking advantage of dockers latest syntax and things like caching.

@m0gg
Copy link
Contributor Author

m0gg commented Jul 11, 2024

It's extremely sad and unfortunate.

I absolutely agree.

looks like most of the changes are taking advantage of dockers latest syntax and things like caching.

It does run as expected on recent podman though.

May I ask for the reason for such an "old" version of podman?

@castrojo
Copy link
Member

May I ask for the reason for such an "old" version of podman?

The ubuntu builders are 22.04, we're waiting for 24.04 builders to go GA so we can get newer podman versions, which should be sometime soon.

@m0gg
Copy link
Contributor Author

m0gg commented Jul 11, 2024

May I ask for the reason for such an "old" version of podman?

The ubuntu builders are 22.04, we're waiting for 24.04 builders to go GA so we can get newer podman versions, which should be sometime soon.

Sigh ...

In that case, i could continue to test this stuff with gitea and ubuntu-latest runners.

While familiarising myself with the ublue projects, I got the urge to refactor some parts of the build system/scripts.
Are you open to review/comment changes requiring the newer builders?

@castrojo
Copy link
Member

We need newer builders for zstd:chunked compression anyway, so welcome to the queue! We did opt in for a while into 24.04 but we had some builder failures so we rolled back to 22.04, but it's worth investigating again.

Open an issue on what you'd like to refactor and slap an enhancement label on it. Then we can have the other maintainers take a look and work towards consensus. Looking forward to seeing what you have in mind!

@castrojo
Copy link
Member

Looks like the version in 24.04 is also too old for heredoc support, we should perhaps consider running with the podman OBS repo so we're always on the newest version, I think someone's proposed that before?

@m0gg
Copy link
Contributor Author

m0gg commented Jul 12, 2024

Looks like the version in 24.04 is also too old for heredoc support

Not really too old - more like: broken. I don't know what they did to that poor thing, but it told me it's version 1.33.7.

runner@6562b73dd4be:/$ buildah --version
buildah version 1.33.7 (image-spec 1.1.0-rc.5, runtime-spec 1.1.0)
runner@6562b73dd4be:/$ buildah build -f- <<EOC
> FROM alpine
> RUN <<EOF
> echo I am groot
> EOF
> EOC
STEP 1/4: FROM alpine
Resolved "alpine" as an alias (/etc/containers/registries.conf.d/shortnames.conf)
Trying to pull docker.io/library/alpine:latest...
Getting image source signatures
Copying blob ec99f8b99825 done   |
Copying config a606584aa9 done   |
Writing manifest to image destination
STEP 2/4: RUN <<EOF
STEP 3/4: echo I am groot
ERRO[0002] +(UNHANDLED LOGLEVEL) &imagebuilder.Step{Env:[]string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, Command:"echo", Args:[]string{""}, Flags:[]string{}, Attrs:map[string]bool(nil), Message:"ECHO ", Original:"echo I am groot"}
Error: building at STEP "ECHO ": Build error: Unknown instruction: "ECHO" &imagebuilder.Step{Env:[]string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, Command:"echo", Args:[]string{""}, Flags:[]string{}, Attrs:map[string]bool(nil), Message:"ECHO ", Original:"echo I am groot"}

Support for here-documents was added in 1.33.0:

$ podman -r run --rm -i --privileged quay.io/buildah/stable:v1.33.2 buildah build -f- <<EOC
FROM alpine
RUN <<EOF
echo I am groot
EOF
EOC
STEP 1/2: FROM alpine
Resolved "alpine" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/alpine:latest...
Getting image source signatures
Copying blob sha256:ec99f8b99825a742d50fb3ce173d291378a46ab54b8ef7dd75e5654e2a296e99
Copying config sha256:a606584aa9aa875552092ec9e1d62cb98d486f51f389609914039aabd9414687
Writing manifest to image destination
STEP 2/2: RUN <<EOF
time="2024-07-12T20:22:43Z" level=warning msg="Path \"/run/secrets/etc-pki-entitlement\" from \"/etc/containers/mounts.conf\" doesn't exist, skipping"
I am groot
COMMIT
Getting image source signatures
Copying blob sha256:94e5f06ff8e3d4441dc3cd8b090ff38dc911bfa8ebdb0dc28395bc98f82f983f
Copying blob sha256:47f646e0d5136a366531b0238f6d2d6af4db40b315bcd4c96b37e14fd0c59c38
Copying config sha256:6e7b5d99878d8e949c40600eb4ca47dc37e6ff3be2900dcba73049e25425de44
Writing manifest to image destination
--> 6e7b5d99878d
6e7b5d99878d8e949c40600eb4ca47dc37e6ff3be2900dcba73049e25425de44

@m0gg
Copy link
Contributor Author

m0gg commented Jul 12, 2024

While it might seem a little hacky, this worked well when i tested it with gitea actions and the 22.04 builder: 5ca8240

@m2Giles
Copy link
Member

m2Giles commented Jul 12, 2024

That's hacky, but we do have to workaround the limitations of the builders. Letting this start to run workflows

@m0gg m0gg force-pushed the improve-containerfile branch 3 times, most recently from 6beaa7b to cfd6ee4 Compare July 13, 2024 07:52
@m0gg m0gg force-pushed the improve-containerfile branch 2 times, most recently from 998b7a7 to 3624553 Compare July 13, 2024 09:22
@bigpod98
Copy link
Contributor

not exactly all that up to speed on heredocs but what does a build gain with using heredocs

@m0gg m0gg force-pushed the improve-containerfile branch from 3624553 to 2f934b3 Compare July 13, 2024 15:23
@m0gg
Copy link
Contributor Author

m0gg commented Jul 13, 2024

Now it successfully runs on GH. Maybe someone would like to trigger the workflow again?

@m0gg
Copy link
Contributor Author

m0gg commented Jul 13, 2024

not exactly all that up to speed on heredocs but what does a build gain with using heredocs

Ultimately, it's preference. Heredocs can be written like normal scripts do: multiple lines, set -eu, etc., etc.
They are a lot more maintainable than sequences of && \.

But this isn't just about heredocs.

@m2Giles
Copy link
Member

m2Giles commented Jul 13, 2024

I noticed that for the mount commands there is a difference between how docker and podman handle these. Docker appears to not like nested mounts. Also docker gets angry with it called context since that's a reserved word.

While we use podman for building, keeping compatibility with docker is a plus.

Overall I really like what this is doing and especially considering that we are copying in the kernel now, reducing the size of the image by removing those COPY layers is great.

@m0gg
Copy link
Contributor Author

m0gg commented Jul 13, 2024

I noticed that for the mount commands there is a difference between how docker and podman handle these. Docker appears to not like nested mounts. Also docker gets angry with it called context since that's a reserved word.

While we use podman for building, keeping compatibility with docker is a plus.

Overall I really like what this is doing and especially considering that we are copying in the kernel now, reducing the size of the image by removing those COPY layers is great.

Interesting. A quick just build did not yield any complaints or warnings on my rootless docker 25.0.2 (using buildx). @m2Giles what version are you using?

edit:
I did already remove the nested mounts because the github runner didn't like aswell.

@m2Giles
Copy link
Member

m2Giles commented Jul 13, 2024

docker buildx is v0.16
docker is 27.0.3

Wouldn't be surprised if it's some weird ordering

I think the are neat. And they're widly supported nowadays. Much more
readable than sequences of ` && \`.
@m0gg m0gg force-pushed the improve-containerfile branch from f24de65 to ef474ca Compare July 15, 2024 10:21
@m0gg m0gg changed the title WIP/RFC: Improve Containerfile feat: Improve Containerfile / enable workflow usage of containerized buildah (tag: v1) Jul 15, 2024
@m0gg
Copy link
Contributor Author

m0gg commented Jul 15, 2024

This latest version runs without complaints on recent docker/buildx and podman. I've already put in too many commits which are may be considered unrelated or personal preference, so please comment away. I could split out some of them if desired.

m2Giles
m2Giles previously approved these changes Jul 17, 2024
Copy link
Member

@m2Giles m2Giles left a comment

Choose a reason for hiding this comment

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

I like this a lot and gives us a good blueprint for improving containerfiles in the rest of the organization.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 17, 2024
Copy link
Contributor

@bsherman bsherman left a comment

Choose a reason for hiding this comment

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

I'm requesting a few small changes. My reasons are either to maintain readability of the code or to avoid changes which I don't see as needed.

Happy to discuss.

Thanks!

@dosubot dosubot bot removed the lgtm This PR has been approved by a maintainer label Jul 17, 2024
@m0gg m0gg force-pushed the improve-containerfile branch from ef474ca to c5e8b54 Compare July 17, 2024 13:17
@m2Giles
Copy link
Member

m2Giles commented Jul 17, 2024

One thing I'm also noticing in the build logs is that dracut no longer has access to /dev/kmsg and/or /dev/logger so dracuts output are hidden.

The other change that is catching my eye is the change from a for loop to a while loop in github installer script. I know read is preferable when working with arrays, but just trying to understand why the change was made there.

The xargs change is more readable now, bracket bash is something shellcheck indicates to use at times, but I think this is more readable.

Again, I do think the vast majority of this is an excellent improvement, and just would like some clarification on style changes or rationale for using different techniques.

@m0gg m0gg force-pushed the improve-containerfile branch from f559aae to d0e1dbd Compare July 17, 2024 18:12
m0gg added 9 commits July 17, 2024 20:34
The additional intermediate target `context` is a workaround for directly
mounting the context because selinux policies on podman machine denies access
to the mounted directoy.
This adds a workflow task which installs a wrapper script for buildah.
Buildah in ubuntu-22.04 builders is very dated and the buildah
executable in the current beta builder 24.04 misbehaves when
using heredocs.
The scripts uses bash style arrays and/or conditionals which *could* be
unsupported by `/bin/sh`.
 * streamline loading and installation of rpmfusion repo rpms
 * ro buildcontext is now located at `$BUILDCONTEXT_DIR`
 * ro rpms live under `$RPMS_DIR`
buildx complained about mismatched casing
@m0gg m0gg force-pushed the improve-containerfile branch from d0e1dbd to 034e548 Compare July 17, 2024 18:41
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 17, 2024
@m2Giles m2Giles added this pull request to the merge queue Jul 18, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 18, 2024
@bsherman bsherman added this pull request to the merge queue Jul 18, 2024
Merged via the queue into ublue-os:main with commit 85d2bd8 Jul 18, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants