@@ -6,10 +6,9 @@ echo "▶️ $0 $*"
66set -e
77
88if [ " ${1} x" == " x" ] || [ " ${1} " == " --help" ] || [ " ${1} " == " -h" ]; then
9- echo " Usage: ${0} <branch> [--push|--push-only ]"
9+ echo " Usage: ${0} <branch> [--push]"
1010 echo " branch The branch or tag to build. Required."
1111 echo " --push Pushes the built Docker image to the registry."
12- echo " --push-only Only pushes the Docker image to the registry, but does not build it."
1312 echo " "
1413 echo " You can use the following ENV variables to customize the build:"
1514 echo " SRC_ORG Which fork of netbox to use (i.e. github.com/\$ {SRC_ORG}/\$ {SRC_REPO})."
@@ -30,6 +29,9 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
3029 echo " When <branch>=master: latest"
3130 echo " When <branch>=develop: snapshot"
3231 echo " Else: same as <branch>"
32+ echo " DOCKER_BUILD_PLATFORMS platforms the docker buildx will build the image for"
33+ echo " Used for specifying multiple arches."
34+ echo " Default: linux/amd64,linux/arm64"
3335 echo " DOCKER_REGISTRY The Docker repository's registry (i.e. '\$ {DOCKER_REGISTRY}/\$ {DOCKER_ORG}/\$ {DOCKER_REPO}'')"
3436 echo " Used for tagging the image."
3537 echo " Default: docker.io"
@@ -95,8 +97,6 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
9597 fi
9698fi
9799
98- source ./build-functions/gh-functions.sh
99-
100100# ##
101101# Enabling dry-run mode
102102# ##
@@ -201,6 +201,12 @@ if [ -d "${NETBOX_PATH}/.git" ]; then
201201 )
202202fi
203203
204+
205+ # ##
206+ # Variables for arch target
207+ # ##
208+ DOCKER_BUILD_PLATFORMS=" ${DOCKER_BUILD_PLATFORMS-linux/ amd64,linux/ arm64} "
209+
204210# ##
205211# Variables for tagging the docker image
206212# ##
@@ -375,38 +381,23 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
375381 if [ -n " ${NO_PROXY} " ]; then
376382 DOCKER_BUILD_ARGS+=(--build-arg " no_proxy=${NO_PROXY} " )
377383 fi
384+ if [ " ${2} " == " --push" ]; then
385+ DOCKER_BUILD_ARGS+=(--push)
386+ fi
378387
379388 # ##
380389 # Building the docker image
381390 # ##
382391 if [ " ${SHOULD_BUILD} " == " true" ]; then
383392 echo " 🐳 Building the Docker image '${TARGET_DOCKER_TAG_PROJECT} '."
384393 echo " Build reason set to: ${BUILD_REASON} "
385- $DRY docker build " ${DOCKER_BUILD_ARGS[@]} " .
394+ $DRY docker buildx build --platform ${DOCKER_BUILD_PLATFORMS} " ${DOCKER_BUILD_ARGS[@]} " .
386395 echo " ✅ Finished building the Docker images '${TARGET_DOCKER_TAG_PROJECT} '"
387- echo " 🔎 Inspecting labels on '${TARGET_DOCKER_TAG_PROJECT} '"
388- $DRY docker inspect " ${TARGET_DOCKER_TAG_PROJECT} " --format " {{json .Config.Labels}}"
389396 else
390397 echo " Build skipped because sources didn't change"
391398 echo " ::set-output name=skipped::true"
392399 fi
393400 fi
394401
395- # ##
396- # Pushing the docker images if either `--push` or `--push-only` are passed
397- # ##
398- if [ " ${2} " == " --push" ] || [ " ${2} " == " --push-only" ]; then
399- source ./build-functions/docker-functions.sh
400- push_image_to_registry " ${TARGET_DOCKER_TAG} "
401- push_image_to_registry " ${TARGET_DOCKER_TAG_PROJECT} "
402-
403- if [ -n " ${TARGET_DOCKER_SHORT_TAG} " ]; then
404- push_image_to_registry " ${TARGET_DOCKER_SHORT_TAG} "
405- push_image_to_registry " ${TARGET_DOCKER_SHORT_TAG_PROJECT} "
406- push_image_to_registry " ${TARGET_DOCKER_LATEST_TAG} "
407- push_image_to_registry " ${TARGET_DOCKER_LATEST_TAG_PROJECT} "
408- fi
409- fi
410-
411402 gh_echo " ::endgroup::"
412403done
0 commit comments