Skip to content

Commit

Permalink
Merge pull request databricks#20 from tabular-io/add-image-push-script
Browse files Browse the repository at this point in the history
Infra - Add script to push new image to Dockerhub
  • Loading branch information
samredai authored Jul 18, 2022
2 parents abe0332 + 642a2a4 commit 79b5855
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions dev/build-and-push-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

set -e

usage () {
echo "usage: $0 [-t <image_tag>]"
echo " -t Version tag of the image being pushed. Defaults to \"latest\""
echo " -v Turn on VERBOSE / DEBUG output"
exit 1
}

validate_tag_or_throw() {
if [[ ! "$1" =~ ^([a-z0-9\_])([\-\.\_a-z0-9]{0,127})$ ]]; then
echo "The image tag \"$1\" is invalid."
echo " A valid image tag must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes."
echo " A tag name may not start with a period or a dash and may contain a maximum of 128 characters"
exit 1
fi
}

# Default repository remote name
REPOSITORY="tabulario"
IMAGE_NAME="spark-iceberg"
TAG="latest"

while getopts "t:v" opt; do
case "${opt}" in
t)
TAG="${OPTARG}"
;;
v)
set -x
;;
*)
usage
;;
esac
done

shift $((OPTIND-1))

if [[ -z "$TAG" ]]; then
echo "You must specify the image tag to be used via the -t switch. If left empty, then \"latest\" will be used"
usage
fi

# Validate docker is installed
if ! command -v docker &> /dev/null; then
echo "The docker command could not be found. Please install docker and rerun."
exit
fi

# Validate docker is on
if ! docker info > /dev/null 2>&1; then
echo "The docker daemon is not running or accessible. Please start docker and rerun."
usage
fi

# Validate the tag is acceptable
validate_tag_or_throw "$TAG"

# Build full image target and log.
IMAGE_TARGET=${REPOSITORY}/${IMAGE_NAME}:${TAG}

echo "Building and pushing multi-architecture image as ${IMAGE_TARGET} for platforms linux/amd64 and linux/arm64"

docker buildx build -t ${IMAGE_TARGET} --platform=linux/amd64,linux/arm64 ./spark --load

0 comments on commit 79b5855

Please sign in to comment.