Skip to content

Commit 9d9cf92

Browse files
ceyonurqdm12
andauthored
add multiatch docker build to support arm (#1417)
* add multiatch docker build to support arm * fix build img id * Update .github/workflows/publish_docker.yml Co-authored-by: Quentin McGaw <[email protected]> Signed-off-by: Ceyhun Onur <[email protected]> * Update .github/workflows/publish_docker.yml Co-authored-by: Quentin McGaw <[email protected]> Signed-off-by: Ceyhun Onur <[email protected]> * fix vm id * remove debug echo * revert format change --------- Signed-off-by: Ceyhun Onur <[email protected]> Co-authored-by: Quentin McGaw <[email protected]>
1 parent e60bb75 commit 9d9cf92

File tree

3 files changed

+56
-43
lines changed

3 files changed

+56
-43
lines changed

.github/workflows/publish_docker.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ on:
1717

1818
jobs:
1919
publish_docker_image:
20-
name: Publish Docker Image
21-
runs-on: ubuntu-20.04
20+
runs-on: ubuntu-latest
2221
steps:
2322
- uses: actions/checkout@v4
24-
- name: Publish image to Dockerhub
23+
- uses: docker/setup-qemu-action@v3
24+
- uses: docker/setup-buildx-action@v3
25+
- name: Build and publish images to DockerHub
2526
env:
2627
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
2728
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
2829
DOCKER_REPO: "avaplatform/subnet-evm"
29-
run: .github/workflows/publish_docker_image.sh ${{ inputs.vm_id }}
30+
VM_ID: ${{ inputs.vm_id }}
31+
PUBLISH: 1
32+
PLATFORMS: "linux/amd64,linux/arm64"
33+
run: scripts/build_docker_image.sh

.github/workflows/publish_docker_image.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

scripts/build_docker_image.sh

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,25 @@
22

33
set -euo pipefail
44

5+
# If set to non-empty, prompts the building of a multi-arch image when the image
6+
# name indicates use of a registry.
7+
#
8+
# A registry is required to build a multi-arch image since a multi-arch image is
9+
# not really an image at all. A multi-arch image (also called a manifest) is
10+
# basically a list of arch-specific images available from the same registry that
11+
# hosts the manifest. Manifests are not supported for local images.
12+
#
13+
# Reference: https://docs.docker.com/build/building/multi-platform/
14+
PLATFORMS="${PLATFORMS:-}"
15+
16+
# If set to non-empty, the image will be published to the registry.
17+
PUBLISH="${PUBLISH:-}"
18+
519
# Directory above this script
6-
SUBNET_EVM_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
20+
SUBNET_EVM_PATH=$(
21+
cd "$(dirname "${BASH_SOURCE[0]}")"
22+
cd .. && pwd
23+
)
724

825
# Load the constants
926
source "$SUBNET_EVM_PATH"/scripts/constants.sh
@@ -14,18 +31,45 @@ source "$SUBNET_EVM_PATH"/scripts/versions.sh
1431
# WARNING: this will use the most recent commit even if there are un-committed changes present
1532
BUILD_IMAGE_ID=${BUILD_IMAGE_ID:-"${CURRENT_BRANCH}"}
1633

34+
# buildx (BuildKit) improves the speed and UI of builds over the legacy builder and
35+
# simplifies creation of multi-arch images.
36+
#
37+
# Reference: https://docs.docker.com/build/buildkit/
38+
DOCKER_CMD="docker buildx build"
39+
40+
if [[ -n "${PUBLISH}" ]]; then
41+
DOCKER_CMD="${DOCKER_CMD} --push"
42+
43+
echo "Pushing $DOCKERHUB_REPO:$BUILD_IMAGE_ID"
44+
45+
# A populated DOCKER_USERNAME env var triggers login
46+
if [[ -n "${DOCKER_USERNAME:-}" ]]; then
47+
echo "$DOCKER_PASS" | docker login --username "$DOCKER_USERNAME" --password-stdin
48+
fi
49+
fi
50+
51+
# Build a multi-arch image if requested
52+
if [[ -n "${PLATFORMS}" ]]; then
53+
DOCKER_CMD="${DOCKER_CMD} --platform=${PLATFORMS}"
54+
fi
55+
1756
VM_ID=${VM_ID:-"${DEFAULT_VM_ID}"}
18-
if [[ "${VM_ID}" != "${DEFAULT_VM_ID}" ]]; then
57+
if [[ "${VM_ID}" != "${DEFAULT_VM_ID}" ]]; then
1958
DOCKERHUB_TAG="${VM_ID}-${DOCKERHUB_TAG}"
2059
fi
2160

2261
# Default to the release image. Will need to be overridden when testing against unreleased versions.
2362
AVALANCHEGO_NODE_IMAGE="${AVALANCHEGO_NODE_IMAGE:-${AVALANCHEGO_IMAGE_NAME}:${AVALANCHE_VERSION}}"
2463

2564
echo "Building Docker Image: $DOCKERHUB_REPO:$BUILD_IMAGE_ID based of AvalancheGo@$AVALANCHE_VERSION"
26-
docker build -t "$DOCKERHUB_REPO:$BUILD_IMAGE_ID" -t "$DOCKERHUB_REPO:${DOCKERHUB_TAG}" \
27-
"$SUBNET_EVM_PATH" -f "$SUBNET_EVM_PATH/Dockerfile" \
65+
${DOCKER_CMD} -t "$DOCKERHUB_REPO:$BUILD_IMAGE_ID" -t "$DOCKERHUB_REPO:${DOCKERHUB_TAG}" \
66+
"$SUBNET_EVM_PATH" -f "$SUBNET_EVM_PATH/Dockerfile" \
2867
--build-arg AVALANCHEGO_NODE_IMAGE="$AVALANCHEGO_NODE_IMAGE" \
2968
--build-arg SUBNET_EVM_COMMIT="$SUBNET_EVM_COMMIT" \
3069
--build-arg CURRENT_BRANCH="$CURRENT_BRANCH" \
3170
--build-arg VM_ID="$VM_ID"
71+
72+
if [[ -n "${PUBLISH}" && $CURRENT_BRANCH == "master" ]]; then
73+
echo "Tagging current image as $DOCKERHUB_REPO:latest"
74+
docker buildx imagetools create -t "$DOCKERHUB_REPO:latest" "$DOCKERHUB_REPO:$BUILD_IMAGE_ID"
75+
fi

0 commit comments

Comments
 (0)