-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·71 lines (65 loc) · 1.66 KB
/
build.sh
File metadata and controls
executable file
·71 lines (65 loc) · 1.66 KB
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
#!/bin/bash
# Copyright (c) 2021, 2023, Oracle and/or its affiliates.
#
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
#
# Usage function
print_usage() {
cat <<EOF
Usage: $0 -a <arch> -t <tag>
Options:
-a Architecture (amd64,arm64)
-t Image tag (e.g., mysql/community-operator, mysql/enterprise-operator)
-h Show this help message
EOF
}
#Default values
ARCH='amd64'
IMG_TAG=$(./tag.sh)
MAJOR_VERSION=${IMG_TAG:0:3}
DOCKERFILE="Dockerfile"
while getopts "a:f:t:h" opt; do
case "$opt" in
a)
# Set architecture from -a option
ARCH="$OPTARG"
if [[ -z "$ARCH" || ! "$ARCH" =~ ^(amd64|arm64)$ ]]; then
echo "Error: Invalid architecture '$ARCH'" >&2
exit 1
fi
;;
f)
# Set Dockerfile from -f option
DOCKERFILE="$OPTARG"
if [[ -z "$DOCKERFILE" ]]; then
echo "Error: Docker file arg (-f) is required and cannot be empty." >&2
exit 1
fi
;;
t)
# Set image tag from -t option
TAG="$OPTARG"
if [[ -z "$TAG" ]]; then
echo "Error: Image tag (-t) is required and cannot be empty." >&2
exit 1
fi
;;
h)
print_usage
exit 0
;;
\?)
# Unknown option handler
echo "Invalid option: -$OPTARG"
exit 1
;;
esac
done
#check if any unknown args passed to the script
shift $((OPTIND - 1))
if [[ $# -gt 0 ]]; then
echo "Error: Unknown arguments: $*" >&2
print_usage
exit 1
fi
docker build --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} --build-arg no_proxy=${no_proxy} -f "${DOCKERFILE}" -t "${TAG}":${MAJOR_VERSION}-$ARCH .