File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 4
4
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5
5
#
6
6
7
+ # Usage function
8
+ print_usage () {
9
+ cat << EOF
10
+ Usage: $0 -a <arch> -t <tag>
11
+
12
+ Options:
13
+ -a Architecture (amd64,arm64)
14
+ -t Image tag (e.g., mysql/community-operator, mysql/enterprise-operator)
15
+ -h Show this help message
16
+ EOF
17
+ }
18
+
19
+ # Default values
7
20
ARCH=' amd64'
8
21
IMG_TAG=$( ./tag.sh)
9
22
MAJOR_VERSION=${IMG_TAG: 0: 3}
@@ -14,14 +27,30 @@ while getopts "a:f:t:h" opt; do
14
27
a)
15
28
# Set architecture from -a option
16
29
ARCH=" $OPTARG "
30
+ if [[ -z " $ARCH " || ! " $ARCH " =~ ^(amd64| arm64)$ ]]; then
31
+ echo " Error: Invalid architecture '$ARCH '" >&2
32
+ exit 1
33
+ fi
17
34
;;
18
35
f)
19
36
# Set Dockerfile from -f option
20
37
DOCKERFILE=" $OPTARG "
38
+ if [[ -z " $DOCKERFILE " ]]; then
39
+ echo " Error: Docker file arg (-f) is required and cannot be empty." >&2
40
+ exit 1
41
+ fi
21
42
;;
22
43
t)
23
44
# Set image tag from -t option
24
45
TAG=" $OPTARG "
46
+ if [[ -z " $TAG " ]]; then
47
+ echo " Error: Image tag (-t) is required and cannot be empty." >&2
48
+ exit 1
49
+ fi
50
+ ;;
51
+ h)
52
+ print_usage
53
+ exit 0
25
54
;;
26
55
\? )
27
56
# Unknown option handler
@@ -31,4 +60,12 @@ while getopts "a:f:t:h" opt; do
31
60
esac
32
61
done
33
62
63
+ # check if any unknown args passed to the script
64
+ shift $(( OPTIND - 1 ))
65
+ if [[ $# -gt 0 ]]; then
66
+ echo " Error: Unknown arguments: $* " >&2
67
+ print_usage
68
+ exit 1
69
+ fi
70
+
34
71
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 .
You can’t perform that action at this time.
0 commit comments