22
33set -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
926source " $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
1532BUILD_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+
1756VM_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} "
2059fi
2160
2261# Default to the release image. Will need to be overridden when testing against unreleased versions.
2362AVALANCHEGO_NODE_IMAGE=" ${AVALANCHEGO_NODE_IMAGE:- ${AVALANCHEGO_IMAGE_NAME} : ${AVALANCHE_VERSION} } "
2463
2564echo " 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