-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.sh
executable file
·78 lines (64 loc) · 1.71 KB
/
build.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
#!/bin/bash
jdkversions=(`cat jdk_versions | grep -v "# *" | grep -v "^$"`)
distros=(`ls -1 docker/`)
image_prefix="mcr.microsoft.com/openjdk/jdk"
help() {
cat << EOF
Microsoft Build of OpenJDK - Docker Image Builder
Copyright (c) 2021, Microsoft Corporation
$ build.sh [--all] | [distro] [version]
Arguments:
--all: builds all base images and JDK versions defined in './jdk_versions'
[distro]: the base image to build
Any of: ${distros[*]}
[version]: the JDK version to use
Any of: ${jdkversions[*]}
EOF
exit 0
}
# Builds the image with tag '$jdk-$distro'
build_image() {
_distro=$1
_jdk=$2
docker build \
--build-arg JDK_VERSION=$_jdk \
-f docker/$_distro/Dockerfile \
-t $image_prefix:$_jdk-$_distro docker/$_distro
}
build_all() {
echo "Building all distro images and JDK versions."
for d in ${distros[*]}; do
for j in ${jdkversions[*]}; do
build_image $d $j
done
done
exit 0
}
build_single() {
# Check if distro argument is valid
if [[ ! ${distros[*]} =~ "$1" ]]; then
echo "Base image '${1}' not available."
exit 1
fi
# Check if jdk version argument is valid
if [[ ! ${jdkversions[*]} =~ "$2" ]]; then
echo "JDK version '${2}' not available."
exit 1
fi
# Build a single image
echo "Building single image 'distro=${1} jdk=${2}' ..."
build_image $1 $2
}
# Check if needs to print help
if [[ "$#" -eq 0 ]] || [[ "$#" -gt "2" ]]; then help; fi
# Check if user wants to build all. Otherwise builds one, or show help message.
if [[ "$#" -eq 1 ]] && [[ '--all' == "$1" ]]; then
build_all
elif [[ "$#" -eq 1 ]]; then
echo "Invalid argument: '${1}'"
exit 1
elif [ "$#" -eq 2 ]; then
build_single $1 $2
else
help
fi