Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Docker image: Multi arch support #7397

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 53 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
version: 2
version: 2.1
jobs:
dockerhubuploadrelease:
machine: true
docker:
- image: docker:git
steps:
- checkout
- run: docker build -f docker/Dockerfile --label gitsha1=${CIRCLE_SHA1} -t matrixdotorg/synapse:${CIRCLE_TAG} -t matrixdotorg/synapse:${CIRCLE_TAG}-py3 .
- setup_remote_docker:
version: 18.09.3
Copy link
Member

Choose a reason for hiding this comment

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

any reason to pin the docker version here? Indeed my impression is that buildx works better with 19.03?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for not responding earlier, I wasn't near a computer for the last 2 weeks.
If I remember correctly, 18.09 is the highest version CircleCI supports and it defaulted to a lower version.
A higher version would be beneficial, as there wouldn't be a need to create context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The newest version available seems to be 19.03 now: https://circleci.com/docs/2.0/building-docker-images/#docker-version
I'll be able to test it and make the other changes this week.

- docker_prepare
- run: docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
- run: docker push matrixdotorg/synapse:${CIRCLE_TAG}
- run: docker push matrixdotorg/synapse:${CIRCLE_TAG}-py3
- docker_build:
parameters: --label gitsha1=${CIRCLE_SHA1} -t matrixdotorg/synapse:${CIRCLE_TAG} -t matrixdotorg/synapse:${CIRCLE_TAG}-py3

dockerhubuploadlatest:
machine: true
docker:
- image: docker:git
steps:
- checkout
- run: docker build -f docker/Dockerfile --label gitsha1=${CIRCLE_SHA1} -t matrixdotorg/synapse:latest -t matrixdotorg/synapse:latest-py3 .
- setup_remote_docker:
version: 18.09.3
- docker_prepare
- run: docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
- run: docker push matrixdotorg/synapse:latest
- run: docker push matrixdotorg/synapse:latest-py3
- docker_build:
parameters: --label gitsha1=${CIRCLE_SHA1} -t matrixdotorg/synapse:latest -t matrixdotorg/synapse:latest-py3

workflows:
version: 2
build:
jobs:
- dockerhubuploadrelease:
Expand All @@ -31,3 +37,40 @@ workflows:
filters:
branches:
only: master

commands:
docker_prepare:
description: Downloads the buildx cli plugin and enables multiarch execution
parameters:
buildx_version:
type: string
default: "v0.4.1"
steps:
- run: apk add --no-cache curl
- run: mkdir -vp ~/.docker/cli-plugins/ ~/dockercache
- run: curl --silent -L "https://github.com/docker/buildx/releases/download/<< parameters.buildx_version >>/buildx-<< parameters.buildx_version >>.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
- run: chmod a+x ~/.docker/cli-plugins/docker-buildx
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- run: docker context create old-style
Copy link
Member

Choose a reason for hiding this comment

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

why is the context called old-style ? (indeed, why do we need to create a context here?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name could be anything, but it was often called old-style in the tutorials I read. Creating a context is needed as CircleCI isn't running a relatively modern version of Docker.

- run: docker buildx create old-style --use

docker_build:
description: Builds and pushed images to dockerhub using buildx
parameters:
dockerfile:
type: string
default: docker/Dockerfile
push:
type: boolean
default: true
Comment on lines +60 to +65
Copy link
Member

Choose a reason for hiding this comment

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

is there any point in parameterising these? it seems to complicate the commandline without any real benefit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, not at this moment. I added these parameters so one could easily expand the pipeline. I can remove the unused parameters.

platforms:
type: string
default: linux/arm64/v8,linux/amd64
context:
type: string
default: .
parameters:
type: string
default: --label gitsha1=${CIRCLE_SHA1}
steps:
- run: docker buildx build -f << parameters.dockerfile >><<# parameters.push >> --push<</ parameters.push >> --platform << parameters.platforms >> << parameters.parameters >> << parameters.context >>
Copy link
Member

Choose a reason for hiding this comment

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

the default output format does not work well in circleci. suggest --progress=plain.

1 change: 1 addition & 0 deletions changelog.d/7397.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Build multi-arch docker images. Contributed by @Starbix.