forked from databricks/docker-spark-iceberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-and-push-image.sh
executable file
·85 lines (72 loc) · 2.45 KB
/
build-and-push-image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
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