Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buildx support for build-docker.sh #16822

Merged
25 changes: 21 additions & 4 deletions dev/scripts/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,42 @@ readonly GENERATE_TARBALLS_SCRIPT="${SCRIPT_DIR}/generate-tarballs"
# Builds a docker image from the specified tarball.
function build_docker_image {
local tarball=$1
local build_mode=$2
local platform=$3
local tmp_dir="$(mktemp -d)"
cp -r "${DOCKER_DIR}" "${tmp_dir}"
cp "${tarball}" "${tmp_dir}/docker"
cd "${tmp_dir}/docker"
# example tarball: /path/to/workdir/alluxio-1.4.0-SNAPSHOT.tar.gz
# docker image tags must be lowercase
local tarball_basename=$(basename ${tarball})
local tag=$(echo ${tarball_basename%.tar.gz} | tr '[:upper:]' '[:lower:]')
echo "Building ${tag} image..."
docker build -t "${tag}" --build-arg "ALLUXIO_TARBALL=${tarball_basename}" .

if [[ "${build_mode}" == "buildx" ]]
then
local tag=$(echo ${tarball_basename%.tar.gz}${platform} | tr '[:upper:]' '[:lower:]')
echo "Building ${tag} image..."
docker buildx build -t "${tag}" --platform="${platform}" --build-arg "ALLUXIO_TARBALL=${tarball_basename}" .
else
local tag=$(echo ${tarball_basename%.tar.gz} | tr '[:upper:]' '[:lower:]')
echo "Building ${tag} image..."
docker build -t "${tag}" --build-arg "ALLUXIO_TARBALL=${tarball_basename}" .
fi
rm -rf "${tmp_dir}"
}

function main {
local build_mode="default"
local platform="linux/amd64"
if [[ $1 == "buildx" ]]
then
build_mode="buildx"
platform=$2
fi
cd "${SCRIPT_DIR}"
local tmp_dir="$(mktemp -d)"
"${GENERATE_TARBALLS_SCRIPT}" single -target "${tmp_dir}/alluxio-\${VERSION}.tar.gz"
local tarball="${tmp_dir}/$(ls -tr ${tmp_dir} | tail -1)"
build_docker_image "${tarball}"
build_docker_image "${tarball}" "${build_mode}" "${platform}"
rm -rf ${tmp_dir}
}

Expand Down