From 9b31b92abb401b927702b813b6715fb75136b794 Mon Sep 17 00:00:00 2001 From: mchades Date: Wed, 18 Oct 2023 11:52:16 +0800 Subject: [PATCH] [MINOR] refactor(image): Fix Docker image build error (#532) ### What changes were proposed in this pull request? Clarify `--image` and `--tag` options in the build Docker image script ### Why are the changes needed? `--image` with tag value will bring errors and confusion ### Does this PR introduce _any_ user-facing change? usage of Docker image build command changed ### How was this patch tested? tested locally and pushed the latest built image to the Docker hub --- .github/workflows/docker-image.yml | 4 ++-- dev/docker/hive/README.md | 2 +- dev/docker/hive/build-docker.sh | 20 +++++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 03938c1aa6c..6d6fcb6bf8c 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -45,8 +45,8 @@ jobs: - name: Build and Push the main branch Docker image if: ${{ github.ref_name == 'main' }} - run: ./dev/docker/hive/build-docker.sh --platform all --image ${HIVE_IMAGE_NAME}:${{ github.event.inputs.tag }} --tag ${HIVE_IMAGE_NAME}:latest + run: ./dev/docker/hive/build-docker.sh --platform all --image ${HIVE_IMAGE_NAME} --tag ${{ github.event.inputs.tag }} --latest - name: Build and Push the other branch Docker image if: ${{ github.ref_name != 'main' }} - run: ./dev/docker/hive/build-docker.sh --platform all --image ${HIVE_IMAGE_NAME}:${{ github.event.inputs.tag }} + run: ./dev/docker/hive/build-docker.sh --platform all --image ${HIVE_IMAGE_NAME} --tag ${{ github.event.inputs.tag }} diff --git a/dev/docker/hive/README.md b/dev/docker/hive/README.md index 72ff30d9d16..d37958c3506 100644 --- a/dev/docker/hive/README.md +++ b/dev/docker/hive/README.md @@ -8,7 +8,7 @@ It includes Hadoop-2.x and Hive-2.x, you can use this Docker image to test the G ## Build Docker image ``` -./build-docker.sh --platform [all|linux/amd64|linux/arm64] --image {image_name} --tag {tag_name} +./build-docker.sh --platform [all|linux/amd64|linux/arm64] --image {image_name} --tag {tag_name} --latest ``` ## Run container diff --git a/dev/docker/hive/build-docker.sh b/dev/docker/hive/build-docker.sh index e251d219a30..d41d18091a8 100755 --- a/dev/docker/hive/build-docker.sh +++ b/dev/docker/hive/build-docker.sh @@ -10,7 +10,6 @@ bin="$(cd "${bin}">/dev/null; pwd)" # Environment variables definition HADOOP_VERSION="2.7.3" HIVE_VERSION="2.3.9" -IMAGE_NAME="datastrato/gravitino-ci-hive:0.1.1" HADOOP_PACKAGE_NAME="hadoop-${HADOOP_VERSION}.tar.gz" HADOOP_DOWNLOAD_URL="http://archive.apache.org/dist/hadoop/core/hadoop-${HADOOP_VERSION}/${HADOOP_PACKAGE_NAME}" @@ -19,7 +18,7 @@ HIVE_PACKAGE_NAME="apache-hive-${HIVE_VERSION}-bin.tar.gz" HIVE_DOWNLOAD_URL="https://archive.apache.org/dist/hive/hive-${HIVE_VERSION}/${HIVE_PACKAGE_NAME}" # Build docker image for multi-arch -USAGE="-e Usage: ./build-docker.sh --platform [all|linux/amd64|linux/arm64] --image {image_name} --tag {tag_name}" +USAGE="-e Usage: ./build-docker.sh --platform [all|linux/amd64|linux/arm64] --image {image_name} --tag {tag_name} --latest" # Get platform type if [[ "$1" == "--platform" ]]; then @@ -55,6 +54,13 @@ if [[ "$1" == "--tag" ]]; then shift fi +# Get latest flag +buildLatest=0 +if [[ "$1" == "--latest" ]]; then + shift + buildLatest=1 +fi + # Prepare download packages if [[ ! -d "${bin}/packages" ]]; then mkdir -p "${bin}/packages" @@ -80,14 +86,14 @@ fi cd ${bin} if [[ "${platform_type}" == "all" ]]; then - if [[ "${tag_name}" == "" ]]; then - docker buildx build --platform=linux/amd64,linux/arm64 --build-arg HADOOP_PACKAGE_NAME=${HADOOP_PACKAGE_NAME} --build-arg HIVE_PACKAGE_NAME=${HIVE_PACKAGE_NAME} --push --progress plain -f Dockerfile -t ${image_name} . + if [ ${buildLatest} -eq 1 ]; then + docker buildx build --platform=linux/amd64,linux/arm64 --build-arg HADOOP_PACKAGE_NAME=${HADOOP_PACKAGE_NAME} --build-arg HIVE_PACKAGE_NAME=${HIVE_PACKAGE_NAME} --push --progress plain -f Dockerfile -t ${image_name}:latest -t ${image_name}:${tag_name} . else - docker buildx build --platform=linux/amd64,linux/arm64 --build-arg HADOOP_PACKAGE_NAME=${HADOOP_PACKAGE_NAME} --build-arg HIVE_PACKAGE_NAME=${HIVE_PACKAGE_NAME} --push --progress plain -f Dockerfile -t ${image_name}:${tag_name} . + docker buildx build --platform=linux/amd64,linux/arm64 --build-arg HADOOP_PACKAGE_NAME=${HADOOP_PACKAGE_NAME} --build-arg HIVE_PACKAGE_NAME=${HIVE_PACKAGE_NAME} --push --progress plain -f Dockerfile -t ${image_name}:${tag_name} . fi else - if [[ "${tag_name}" == "" ]]; then - docker buildx build --platform=${platform_type} --build-arg HADOOP_PACKAGE_NAME=${HADOOP_PACKAGE_NAME} --build-arg HIVE_PACKAGE_NAME=${HIVE_PACKAGE_NAME} --output type=docker --progress plain -f Dockerfile -t ${image_name} . + if [ ${buildLatest} -eq 1 ]; then + docker buildx build --platform=${platform_type} --build-arg HADOOP_PACKAGE_NAME=${HADOOP_PACKAGE_NAME} --build-arg HIVE_PACKAGE_NAME=${HIVE_PACKAGE_NAME} --output type=docker --progress plain -f Dockerfile -t ${image_name}:latest -t ${image_name}:${tag_name} . else docker buildx build --platform=${platform_type} --build-arg HADOOP_PACKAGE_NAME=${HADOOP_PACKAGE_NAME} --build-arg HIVE_PACKAGE_NAME=${HIVE_PACKAGE_NAME} --output type=docker --progress plain -f Dockerfile -t ${image_name}:${tag_name} . fi