Skip to content

Commit

Permalink
fix: allow building ARM64 images in AMD CI jobs
Browse files Browse the repository at this point in the history
You can't use the default `docker build` to build multi-arch images,
this is something we need if we want to build ARM-based images in
CircleCI. The alternative would be to move _all_ our CircleCI jobs to
ARM which is more expensive and a bunch of work.
  • Loading branch information
rowanmanning committed Jan 24, 2025
1 parent a267b08 commit 863b54e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions plugins/docker/src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,32 @@ export default class DockerBuild extends Task<{
const imageTags = [imageName, ...getImageTagsFromEnvironment(imageOptions)]
this.logger.info(`Building image "${imageIdentifier}": with tags ${imageTags.join(', ')}`)
try {
const child = spawn('docker', [
// We need to create a builder so that we're not limited to
// building AMD64 images due to the platform our CircleCI
// builds run on
const childCreate = spawn('docker', [
'buildx',
'create',
'--platform',
imageOptions.platform,
'--use' // This is a shortcut that prevents us having to run `docker buildx use`
])
hookFork(this.logger, 'docker-build-create', childCreate)
await waitOnExit('docker-build-create', childCreate)

const childBuild = spawn('docker', [
'buildx',
'build',
'--load', // Without this, the image is not stored and so we can't push it later
'--platform',
imageOptions.platform,
...imageTags.flatMap((tag) => ['--tag', tag]),
'--file',
imageOptions.definition,
process.cwd()
])
hookFork(this.logger, 'docker-build', child)
await waitOnExit('docker-build', child)
hookFork(this.logger, 'docker-build', childBuild)
await waitOnExit('docker-build', childBuild)
} catch (err) {
if (err instanceof Error) {
const error = new ToolKitError('docker build failed to run')
Expand Down

0 comments on commit 863b54e

Please sign in to comment.