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

Publish arm64 Docker images #1307

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

Conversation

hoyes
Copy link

@hoyes hoyes commented Dec 14, 2023

Address #917 by adding support for building and publishing arm64 Docker images on CI.

The most direct way to do this seems to be docker buildx, using Github actions provider by Docker, but buildx isn't able to push multi-platform images to a local image store so some supporting changes are required to build.sh:

  1. Allow additional arguments to be passed
  2. Use the same image names as on Docker Hub

Note that 1. changes usage for build.sh when building for a specific platform. This is addressed in README.md and hopefully addresses more use-cases, but not sure about Labgrid policy about breaking changes?

Building non-x86 platforms with Github Actions uses emulation, so enable layer caching and tweak the Dockerfile to make better use of caches.

There is an additional patch to enable image builds on release events and manual triggers.

I have run a action on top of these changes (using the manual trigger) over at my fork: https://github.com/hoyes/labgrid/actions/runs/7209149336, resulting in https://hub.docker.com/u/hoyes

Checklist

  • Documentation for the feature
  • Tests for the feature
  • PR has been tested

@Emantor Emantor self-assigned this Dec 15, 2023
Copy link

codecov bot commented Dec 15, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.1%. Comparing base (a3c068f) to head (b48c415).

❗ Current head b48c415 differs from pull request most recent head 58fdba6. Consider uploading reports for the commit 58fdba6 to get more accurate results

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1307     +/-   ##
========================================
+ Coverage    62.2%   63.1%   +0.9%     
========================================
  Files         164     160      -4     
  Lines       12191   11914    -277     
========================================
- Hits         7583    7520     -63     
+ Misses       4608    4394    -214     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hoyes
Copy link
Author

hoyes commented Feb 26, 2024

@krevsbech any thoughts on these Docker build changes?

@Emantor
Copy link
Member

Emantor commented Mar 25, 2024

This only seems to work with docker, podman raises an error when trying to use the build script:

./dockerfiles/build.sh --platform linux/amd64,linux/arm64
Error: unable to parse value provided `[]` to --cache-from: repository must contain neither a tag nor digest: docker.io/labgrid/client:latest
Error: unable to parse value provided `[]` to --cache-from: repository must contain neither a tag nor digest: docker.io/labgrid/exporter:latest
Error: unable to parse value provided `[]` to --cache-from: repository must contain neither a tag nor digest: docker.io/labgrid/coordinator:latest

@Emantor Emantor assigned hoyes and unassigned Emantor Mar 25, 2024
@Emantor Emantor added the needs author info Requires more information from the PR/Issue author label Mar 25, 2024
To allow customizing the arguments passed to docker/podman build(x)
beyond just the platform, modify build.sh to pass all its arguments
through to the build command.

For the platform case, this means it is now necessary to pass
"--platform linux/arm64" instead of just "linux/arm64" so modify
README.md to reflect this.

This change also has the effect of automatically using buildx if
supported, even if no arguments are passed, so move the information
about buildx further up in the text. The link to podman's buildx is
dropped as (unlike Docker) "podman buildx" is just an alias for
"podman build".

Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
To simplify usage of build.sh on CI, use the same image names for local
development as on the Docker hub (i.e. labgrid/client instead of
labgrid-client).

Allow both the prefix and the tag to be overridden using environment
variables.

Use the same prefix in docker-compose.yml, customizable using the same
environment variable.

Adjust the documentation to reflect the new prefix. It is no longer
necessary to build the images locally before running docker-compose so
remove this part of the staging instructions.

Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
docker buildx is able to create multi-platform docker images in a single
invocation (using emulation where required), but multi-platform images
cannot be stored locally, only pushed directly to a regsitry. So refacor
the workflow a little.

Set common configuration as environment variables.

Add actions to initialize QEMU and buildx.

The remaining steps are modified to:
 * First build just the amd64 image and use this for validation using
   docker-compose (--load only supports single-platform images)
 * Build, tag and push the "latest" images for all platforms in a
   single invocation
 * For tags, override IMAGE_TAG and run the same command again.

Built layers are cached so no redundant work is performed, despite
running the same command multiple times.

Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
It is observed that there are no images on Docker hub for Labgrid
release tags, despite listening to tag events.

This may be because this event is not triggered for tags created via the
Github release UI, so add this event too.

Additionally allow the workflow to be triggered manually for testing
purposes.

Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
@hoyes
Copy link
Author

hoyes commented Mar 28, 2024

It seems caching doesn't work consistently between Podman and Docker.

If it's OK, I've dropped the commit that adds the caching arguments. I tried to enable caching just in the CI workflow but --cache-from requires the specific image name per image (client, coordinator, expertor) which is tricky to pass through. The workflow takes around 15 minutes without it (https://github.com/hoyes/labgrid/actions/runs/8469983487), which isn't too bad.

./dockerfiles/build.sh --platform linux/amd64,linux/arm64 now works for me with Podman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker enhancement needs author info Requires more information from the PR/Issue author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants