Skip to content

Commit

Permalink
Add architecture param to support multiple arch selections (#4516)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
  • Loading branch information
peterzhuamazon authored Mar 8, 2024
1 parent 846691a commit 19cb196
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions docker/ci/build-image-multi-arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ DIR=""

function usage() {
echo ""
echo "This script is used to build the Docker image with multi architecture (x64 + arm64). It prepares the files required by the Dockerfile in a temporary directory, then builds and tags the Docker image."
echo "This script is used to build the Docker image with multi architecture. It prepares the files required by the Dockerfile in a temporary directory, then builds and tags the Docker image."
echo "--------------------------------------------------------------------------"
echo "Usage: $0 [args]"
echo ""
echo "Required arguments:"
echo -e "-r REPO_NAME\tSpecify the image repo name such as 'ci-runner'"
echo -e "-v TAG_NAME\tSpecify the image tag name such as 'centos7-x64-arm64-jdkmulti-node10.24.1-cypress6.9.1-20211019'"
echo -e "-f DOCKERFILE\tSpecify the dockerfile full path, e.g. dockerfile/opensearch.al2.dockerfile."
echo -e "-f DOCKERFILE\tSpecify the dockerfile full path, e.g. 'dockerfile/opensearch.al2.dockerfile'"
echo -e "-a ARCHITECTURE\tSpecify the architecture of the image, default to 'linux/amd64,linux/arm64', all options: 'linux/amd64,linux/arm64,linux/ppc64le'"
echo ""
echo "Optional arguments:"
echo -e "-h\t\tPrint this message."
Expand All @@ -47,7 +48,7 @@ function cleanup_all() {
cleanup_docker_buildx
File_Delete $DIR
}
while getopts ":hr:v:f:" arg; do
while getopts ":hr:v:f:a:" arg; do
case $arg in
h)
usage
Expand All @@ -62,6 +63,9 @@ while getopts ":hr:v:f:" arg; do
f)
DOCKERFILE=$OPTARG
;;
a)
ARCHITECTURE=$OPTARG
;;
:)
echo "-${OPTARG} requires an argument"
usage
Expand Down Expand Up @@ -90,6 +94,11 @@ then
exit 1
fi

# Architecture switch
if [ -z "$ARCHITECTURE" ]; then
ARCHITECTURE="linux/amd64,linux/arm64"
fi

# Prepare docker buildx
trap cleanup_all TERM INT EXIT
DIR=`Temp_Folder_Create`
Expand All @@ -107,5 +116,5 @@ docker buildx ls | grep $BUILDER_NAME
docker ps | grep $BUILDER_NAME

# Build multi-arch images
docker buildx build --platform linux/amd64,linux/arm64,linux/ppc64le --build-arg VERSION=${TAG_NAME} --build-arg BUILD_DATE=`date -u +%Y-%m-%dT%H:%M:%SZ` --build-arg NOTES=${NOTES} -t "opensearchstaging/${REPO_NAME}:${TAG_NAME}" -f "${DOCKERFILE}" --push .
docker buildx build --platform "$ARCHITECTURE" --build-arg VERSION=${TAG_NAME} --build-arg BUILD_DATE=`date -u +%Y-%m-%dT%H:%M:%SZ` --build-arg NOTES=${NOTES} -t "opensearchstaging/${REPO_NAME}:${TAG_NAME}" -f "${DOCKERFILE}" --push .

2 changes: 1 addition & 1 deletion jenkins/docker/docker-build.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pipeline {
trim: true
)
string(
defaultValue: 'Example: cd docker/ci && bash build-image-multi-arch.sh -r <REPO_NAME> -v <TAG_NAME> -f <DOCKERFILE PATH>',
defaultValue: 'Example: cd docker/ci && bash build-image-multi-arch.sh -r <REPO_NAME> -v <TAG_NAME> -f <DOCKERFILE PATH> -a <(Optional, default to amd64+arm64) linux/amd64,linux/arm64,linux/ppc64le>',
name: 'DOCKER_BUILD_SCRIPT_WITH_COMMANDS',
description: 'The script path of the docker build script, assuming you are already in root dir of DOCKER_BUILD_GIT_REPOSITORY.',
trim: true
Expand Down

0 comments on commit 19cb196

Please sign in to comment.