Skip to content

Commit

Permalink
[MINOR] refactor(image): Fix Docker image build error (#532)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
mchades authored Oct 18, 2023
1 parent e5320a7 commit 9b31b92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion dev/docker/hive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions dev/docker/hive/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 9b31b92

Please sign in to comment.