forked from microsoft/openjdk-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate-image.sh
executable file
·78 lines (64 loc) · 2.07 KB
/
validate-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
#!/bin/bash
ARGS=""
while (( "$#" )); do
case "$1" in
-s|--skip-pull)
SKIPPULL=1
shift
;;
-*|--*=)
echo "Invalid flag: $1" >&2
exit 1
;;
*)
ARGS="$ARGS $1"
shift
;;
esac
done
eval set -- "$ARGS"
distro=$1
jdkvendor=$2
jdkversion=$3
expectedversion=$4
# Set the base MCR repo
basemcr="mcr.microsoft.com/openjdk/jdk"
dockerfile="./docker/$distro/Dockerfile.$jdkvendor-$jdkversion-jdk"
image="${basemcr}:${jdkversion}-${distro}"
# Check image is published
if [[ "$SKIPPULL" != "1" ]]; then
docker pull "${image}" > /dev/null 2>&1
fi
if [[ $? -ne 0 ]]; then
echo "::error title=Image not found ($jdkversion-$distro)::Container image '$image' not found!"
exit 1
fi
# Validate the image if expectedversion is set (not blank)
if [[ ! -z "$expectedversion" ]]; then
if [[ "${distro}" == "distroless" ]]; then
java_version=$(docker run --rm $image -version 2>&1 | head -n 1 | awk -F '"' '{print $2}')
else
java_version=$(docker run --rm $image /bin/bash -c "source \$JAVA_HOME/release && echo \$JAVA_VERSION")
fi
java_version=${java_version//[$'\t\r\n']}
java_version=${java_version%%*( )}
if [[ "$java_version" == "$expectedversion" ]]; then
echo "::notice title=Validation succeeded ($jdkversion-$distro)::Image '${image}' contains expected JDK version: ${expectedversion}"
else
echo "::error title=Wrong minor JDK version ($jdkversion-$distro)::Image '${image}' contains unexpected JDK version: ${java_version}. Expected: ${expectedversion}."
exit 1
fi
fi
# Check if CDS is enabled
if [[ "${distro}" == "distroless" ]]; then
java_version_string=$(docker run --rm $image -version 2>&1)
else
java_version_string=$(docker run --rm $image /bin/bash -c "java -version 2>&1")
fi
if [[ "$java_version_string" =~ "sharing" ]]; then
echo "::notice title=CDS enabled ($jdkversion-$distro)::Image '${image}' has enabled CDS."
else
echo "::warning title=CDS disabled ($jdkversion-$distro)::Image '${image}' has disabled CDS."
fi
# Run tests
bash test-image.sh $distro $jdkversion