Skip to content

Make the images available in ghcr.io #37

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

glehmann
Copy link
Member

Based on #35

I had to move the user logic to the image entrypoint to make the images usable by any user even if he/she is not using the usual 1000:1000 ids.

The logic for the repository creation was moved to the Dockerfiles to make the images buildable with the standard github action docker/build-push-action.

Hopefully it will help with the issue with the repository selection in #35.

@glehmann glehmann requested review from ydirson and psafont July 24, 2025 15:14
Copy link

@psafont psafont left a comment

Choose a reason for hiding this comment

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

🎉🎉

(I've only reviewed the last 3 commits)

@glehmann glehmann force-pushed the gln/build-env-improvements-lzqx branch 6 times, most recently from 9e73f03 to 87724c2 Compare July 25, 2025 08:14
@glehmann
Copy link
Member Author

It works with docker but not with podman: we can't run with --userns=keep-id to be root at the container startup, but we need --userns=keep-id to keep the ownership of the files in the shared volume.

I'll propose something else.

@glehmann glehmann force-pushed the gln/build-env-improvements-lzqx branch 3 times, most recently from 78407fa to 7998f39 Compare July 25, 2025 13:57
@glehmann
Copy link
Member Author

It should be good now.

I've used podman's option --userns=keep-id:uid=1000,gid=1000, to map the builder user to but I'm not sure if that's an option that appeared recently or not.
@ydirson could you test it with your podman version?

@glehmann
Copy link
Member Author

glehmann commented Jul 25, 2025

I've also added 88d5bec to reduce the image sizes.

@glehmann glehmann force-pushed the gln/build-env-improvements-lzqx branch from 7998f39 to 88d5bec Compare July 25, 2025 14:22
@ydirson
Copy link

ydirson commented Jul 30, 2025

I've also added 88d5bec to reduce the image sizes.

There is an idiom to squash everything into a single layer, but I also see docker build --squash.

@@ -102,11 +102,13 @@ def main():
docker_arch = args.platform or ("linux/amd64/v2" if branch == "9.0" else "linux/amd64")

docker_args = [RUNNER, "run", "-i", "-t",
"-u", "builder",
Copy link

Choose a reason for hiding this comment

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

I see that with Docker we delegate to the entrypoint the change of user, but I see nothing for the podman case?

Copy link
Member Author

Choose a reason for hiding this comment

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

podman, with --userns=keep-id, already starts with the user ids of the user launching the command.
podman does the mapping of the ids in the mounted volumes, so the files are created with the right owner/group.
docker doesn't do that mapping in the mounted volumes, so we have to switch the user in the container to the ids of the users launching the command

Copy link

Choose a reason for hiding this comment

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

we have to switch the user in the container to the ids of the users launching the command

isn't that only required when docker runs as root (which is both the default because of the daemon, and bad practice to start with, and the essential reason I'm suggesting we just drop its support)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it is. But many dev are still using docker, so I don't think it's time yet to drop docker support

Comment on lines +74 to +79
# platforms: |
# linux/amd64/v2
Copy link

Choose a reason for hiding this comment

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

Explicit platform for 8.x likely does not hurt, if only for documentation purposes

Copy link

Choose a reason for hiding this comment

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

but for 8.x, the arch is linux/amd64

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, fixed!

context: .
file: ./Dockerfile-8.x
push: true
tags: ghcr.io/${{ github.repository }}:8.2
Copy link

Choose a reason for hiding this comment

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

We likely want those official floating tags to be set only when run on master, maybe we set particular tags for PRs?
Also, timestamped tags as is common may be interesting to have.

Copy link
Member Author

Choose a reason for hiding this comment

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

The workflow is only configured on master.
Other tags may be useful, as well as building for PRs, but we must consider cleaning up the old images.

Copy link

Choose a reason for hiding this comment

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

The workflow is only configured on master.

Actually it seems to be configured for main instead :)

Copy link

Choose a reason for hiding this comment

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

Also, there would be a reason for allowing it to run not just on master: detecting pipeline errors before they reach master

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, that would be nice. Maybe push to the registry when on the master branch then.

@glehmann glehmann force-pushed the gln/build-env-improvements-lzqx branch 2 times, most recently from e6311bc to 248ec8f Compare August 1, 2025 14:12
@glehmann glehmann marked this pull request as ready for review August 1, 2025 14:12
@glehmann glehmann requested a review from ydirson August 1, 2025 14:13
Comment on lines -109 to +110
docker_args += ["--userns=keep-id", "--security-opt", "label=disable"]
# With podman we use the `--userns` option to map the builder user to
# the user on the system.
docker_args += [f"--userns=keep-id:uid=1000,gid=1000", "--security-opt", "label=disable"]
Copy link

Choose a reason for hiding this comment

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

The fact the uid is preserved so entrypoint is entered as builder and not as root as in the Docker case is likely useful to document. But is it really a good idea to have such a big difference between the 2 runners? (especially as we want to move more root actions into the entrypoint in the future)

Comment on lines +112 to +115
# With docker, we modify the builder user in the entrypoint to match the
# uid:gid of the user launching the container, and then continue with
# the builder user thanks to gosu.
docker_args += ["-e", f'BUILDER_UID={os.getuid()}', "-e", f'BUILDER_GID={os.getgid()}']
Copy link

Choose a reason for hiding this comment

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

a reader might ask "why gosu and and just su"

Copy link
Member Author

Choose a reason for hiding this comment

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

Then he/she will quickly find on the internet why :-)

I usually try to only document what is specific to the project.
Do you think there is something specific about gosu in that context that should be commented?

@glehmann glehmann force-pushed the gln/build-env-improvements-lzqx branch from 248ec8f to 57683dd Compare August 1, 2025 15:47
Signed-off-by: Gaëtan Lehmann <[email protected]>
This way the image is usable by everybody, independantly of its ids.

With docker, we modify the builder user in the entrypoint to match the
uid:gid of the user launching the container, and then continue with
the builder user thanks to gosu.

With podman we use the `--userns` option to map the builder user to
the user on the system. I haven't found a way with podman to use the
same mechanism as in docker, and vis versa.

Signed-off-by: Gaëtan Lehmann <[email protected]>
The images are always built, but only pushed to the registry when
running on the master branch.

Signed-off-by: Gaëtan Lehmann <[email protected]>
for a significantly smaller image size.

Before:

ghcr.io/xcp-ng/xcp-ng-build-env             8.2            e985e704c252  10 minutes ago  1.03 GB
ghcr.io/xcp-ng/xcp-ng-build-env             8.3            b557dcb6d541  11 minutes ago  1.14 GB
ghcr.io/xcp-ng/xcp-ng-build-env             9.0            c738df7d5577  11 minutes ago  857 MB

After:

ghcr.io/xcp-ng/xcp-ng-build-env             8.2            a9a91fa03db8  7 seconds ago       491 MB
ghcr.io/xcp-ng/xcp-ng-build-env             8.3            a36b1399ac01  About a minute ago  557 MB
ghcr.io/xcp-ng/xcp-ng-build-env             9.0            78011dcbd6f3  11 minutes ago      708 MB

Signed-off-by: Gaëtan Lehmann <[email protected]>
@glehmann glehmann force-pushed the gln/build-env-improvements-lzqx branch from 57683dd to e21ff80 Compare August 1, 2025 17:33
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.

4 participants