Skip to content
This repository was archived by the owner on Jul 31, 2024. It is now read-only.

Create cross-platform docker images#1762

Closed
jwhitlock wants to merge 3 commits intomainfrom
circle-ci-multi-image-1636
Closed

Create cross-platform docker images#1762
jwhitlock wants to merge 3 commits intomainfrom
circle-ci-multi-image-1636

Conversation

@jwhitlock
Copy link
Contributor

For issue #1636, create Docker images with linux/amd64 and linux/arm64 variants. This uses techniques described on the tutorial Building Docker images for multiple operating system architectures.

This add make cross-build to run docker buildx to build the multi-platform images, but doesn't ensure that buildx is installed and configured.

The CircleCI configuration is changed to use a machine image, using similar but slightly different steps. The bundled docker is used, and version details are logged and added to an artifact. A when step is used to determine if we're building a tag or the main branch. If this is the case, then buildx is installed and configured, and used to build the image tagged with the SHA1 / tag name, as well as the latest tag if it is the main branch.

@jwhitlock
Copy link
Contributor Author

I've tested make cross-build locally, but it doesn't run in CircleCI yet. I'll see if I can adjust the condition to test against this branch...

@jwhitlock jwhitlock force-pushed the circle-ci-multi-image-1636 branch 3 times, most recently from 0091318 to ef97f8c Compare January 5, 2022 23:34
Split the workflow into two jobs:

- test: Build, lint, and test in a Docker runner
- build-push: Build and push in a machine executor

Commands common to both jobs are factored into commands:

- capture_host_info: Capture host and Docker information in an artifact
- create_version_json: Create Dockerflow's version.json
- login_to_dockerhub: Login if credentials are provided

The docker version is updated from 20.10.6 to 20.10.11, the latest.

A filter is used to restrict the build-push job to the main branch and
tags. There's an additional check to keep PR forks from pushing images.

This prepares for building cross-compiled images with buildx, which will
require a machine executor.
Add `make cross-build` to build multi-platform images with buildx, and
use it when merging to main or tagging.
@jwhitlock jwhitlock force-pushed the circle-ci-multi-image-1636 branch from ef97f8c to cf53bbe Compare January 6, 2022 01:06
@jwhitlock
Copy link
Contributor Author

This worked, but it too 30 minutes to build the two variants, versus about 5 minutes for just the amd64 version. I don't think this will be acceptable, since the arm64 version is mostly for developers.

I'm curious if an arm64 server would be any faster:

https://circleci.com/docs/2.0/arm-resources/

It may make sense to go back to a previous version of this command, where all the build / lint / test steps were in the same job, and then run the same job on an arm64 machine, and then build the manifest in a follow-on step.

This may require using docker manifest, described here as the "hard way":

https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/

It may also require using workflows to get the data from the machine-specific builds to the manifest writer:

https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs

Of course, now we're approaching the effort to migrate to Taskcluster...

@jwhitlock
Copy link
Contributor Author

I'm going to close this PR. I don't think the end result is worth the effort at this time. As far as I know, 100% of the people that want to run arm64 are me, and make build works fine for that.

@jwhitlock jwhitlock closed this Jan 6, 2022
@jwhitlock jwhitlock deleted the circle-ci-multi-image-1636 branch January 6, 2022 18:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant