Skip to content

Commit efb6cb8

Browse files
committed
Support automated multi-arch builds on Docker Hub
1 parent 899881a commit efb6cb8

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

Multi-Arch-Builds-on-Docker-Hub.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Multi-arch builds on Docker Hub
2+
3+
The [Custom build phase hooks](https://docs.docker.com/docker-hub/builds/advanced/#override-build-test-or-push-commands) build all variants for all platforms, e.g. `amd64` and `arm32v7`, on Docker Hub.
4+
5+
More specifically, the hooks
6+
7+
- Build the image variants in the `build` phase
8+
- Push all images in the `push` phase
9+
- Update the multi-arch manifest in the `post_push` phase
10+
11+
The `post_push` hook generates and pushes the manifest which - simply put - is just a list of references to other images.
12+
13+
```yaml
14+
# Manifest for resilio/sync:release-2.6.3 which points to the amd64 and arm32v7 images
15+
image: resilio/sync:release-2.6.3
16+
manifests:
17+
- image: resilio/sync:release-2.6.3-amd64
18+
platform:
19+
architecture: amd64
20+
os: linux
21+
- image: resilio/sync:release-2.6.3-arm32v7
22+
platform:
23+
architecture: arm
24+
os: linux
25+
variant: v7
26+
```
27+
28+
## Setting up Docker Hub Automated Builds
29+
30+
The following Docker Hub configuration for Automated Builds results in the tags listed in the [README.md](./README.md).
31+
32+
| Source Type | Source | Docker Tag | Dockerfile location | Build Context |
33+
| ----------- | ------ | ------------------- | ------------------- | ------------- |
34+
| Branch | master | latest | Dockerfile | / |
35+
| Tag | /.\*/ | release-{sourceref} | Dockerfile | / |
36+
37+
The `master` branch creates the multi-arch `latest` image and its the platform specific `latest-*` variants.
38+
39+
The tags are published as `release-*` images, e.g. the Git tag `2.6.3` creates the multi-arch `release-2.6.3` image and its platform specific `release-2.6.3-*` variants.
40+
41+
## References
42+
43+
For more details, see [Advanced options for Autobuild and Autotest](https://docs.docker.com/docker-hub/builds/advanced/).

hooks/build

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Custom build script to build images for all supported architectures.
4+
#
5+
# Example for IMAGE_NAME: resilio/sync:release-2.6.3
6+
# Images built:
7+
# - resilio/sync:release-2.6.3-amd64
8+
# - resilio/sync:release-2.6.3-arm32v7
9+
10+
for arch in amd64 arm32v7
11+
do
12+
echo "Building $IMAGE_NAME-$arch"
13+
docker build --build-arg FROM_ARCH=$arch --file $DOCKERFILE_PATH --tag $IMAGE_NAME-$arch .
14+
done

hooks/post_push

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
echo "Pushing multi-arch manifest $IMAGE_NAME"
4+
5+
# Use manifest-tool to create the manifest, given the experimental
6+
# "docker manifest" command isn't available yet on Docker Hub.
7+
curl -Lo manifest-tool https://github.com/estesp/manifest-tool/releases/download/v0.9.0/manifest-tool-linux-amd64
8+
chmod +x manifest-tool
9+
10+
cat > manifest-generated.yaml << EOF
11+
image: $IMAGE_NAME
12+
manifests:
13+
- image: $IMAGE_NAME-amd64
14+
platform:
15+
architecture: amd64
16+
os: linux
17+
- image: $IMAGE_NAME-arm32v7
18+
platform:
19+
architecture: arm
20+
os: linux
21+
variant: v7
22+
EOF
23+
24+
./manifest-tool push from-spec manifest-generated.yaml

hooks/pre_build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
# Register qemu-*-static for all supported processors except the
4+
# current one, but also remove all registered binfmt_misc before
5+
docker run --rm --privileged multiarch/qemu-user-static:register --reset

hooks/push

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Custom build script to push images for all supported architectures.
4+
#
5+
# Example for IMAGE_NAME: resilio/sync:release-2.6.3
6+
# Images pushed:
7+
# - resilio/sync:release-2.6.3-amd64
8+
# - resilio/sync:release-2.6.3-arm32v7
9+
10+
for arch in amd64 arm32v7
11+
do
12+
echo "Pushing $IMAGE_NAME-$arch"
13+
docker push $IMAGE_NAME-$arch
14+
done

0 commit comments

Comments
 (0)