Skip to content

Commit

Permalink
Add buildx support for build-docker.sh
Browse files Browse the repository at this point in the history
### What changes are proposed in this pull request?
Fix #16821

Developers can execute cross compare with `build-docker.sh`
etc.
`./build-docker.sh buildx linux/arm64`

### Why are the changes needed?
Nope.

### Does this PR introduce any user facing changes?
Nope, just for developers.

pr-link: #16822
change-id: cid-736afb945b565d6756fa671e257a67d1db5e408a
  • Loading branch information
JySongWithZhangCe authored Jan 30, 2023
1 parent fb07ea4 commit 98dba4d
Showing 1 changed file with 21 additions and 4 deletions.
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

0 comments on commit 98dba4d

Please sign in to comment.