forked from jetty/jetty.docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·97 lines (85 loc) · 2.96 KB
/
update.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
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
greaterThanOrEqualTo9.4 ()
{
# If version is not numerical it cannot be compared properly.
if [[ ! $1 =~ ^[0-9]+\.?[0-9]*$ ]]; then
echo "Invalid version $1"
exit 1
fi
# Compare version numerically using awk.
if awk 'BEGIN{exit ARGV[1]>=ARGV[2]}' "$1" "9.4"; then
return 1
else
return 0
fi
}
# Update the docker files and scripts for every directory in paths.
paths=( "$@" )
if [ ${#paths[@]} -eq 0 ]; then
paths=( $(ls | egrep '^[0-9]' | sort -nr) )
fi
paths=( "${paths[@]%/}" )
MAVEN_METADATA_URL='https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-server/maven-metadata.xml'
available=( $( curl -sSL "$MAVEN_METADATA_URL" | grep -Eo '<(version)>[^<]*</\1>' | awk -F'[<>]' '{ print $3 }' | sort -Vr ) )
for path in "${paths[@]}"; do
version="${path%%-*}" # "9.2"
jvm="${path#*-}" # "jre11-slim"
disto=$(expr "$jvm" : '\(j..\)[0-9].*') # jre
variant=$(expr "$jvm" : '.*-\(.*\)') # slim
release=$(expr "$jvm" : 'j..\([0-9][0-9]*\).*') # 11
label=${release}-${disto}${variant:+-$variant} # 11-jre-slim
milestones=()
releaseCandidates=()
alphaReleases=()
betaReleases=()
fullReleases=()
for candidate in "${available[@]}"; do
if [[ "$candidate" == "$version".* ]]; then
if [[ "$candidate" == *.M* ]]; then
milestones+=("$candidate")
elif [[ "$candidate" == *.RC* ]]; then
releaseCandidates+=("$candidate")
elif [[ "$candidate" == *.v* || "$candidate" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
fullReleases+=("$candidate")
elif [[ "$candidate" == *alpha* ]]; then
alphaReleases+=("$candidate")
elif [[ "$candidate" == *beta* ]]; then
betaReleases+=("$candidate")
fi
fi
done
fullVersion=
if [ -n "${fullReleases-}" ]; then
fullVersion="$fullReleases"
elif [ -n "${releaseCandidates-}" ]; then
fullVersion="$releaseCandidates"
elif [ -n "${milestones-}" ]; then
fullVersion="$milestones"
elif [ -n "${betaReleases-}" ]; then
fullVersion="$betaReleases"
elif [ -n "${alphaReleases-}" ]; then
fullVersion="$alphaReleases"
fi
if [ -z "$fullVersion" ]; then
echo >&2 "Unable to find Jetty package for $path"
exit 1
fi
echo Full Version "${fullVersion}"
if [ -d "$path" ]; then
# Exclude 9.2 from updated script files.
if [[ "$version" != "9.2" ]]; then
cp docker-entrypoint.sh generate-jetty-start.sh "$path"
fi
# Only generate docker file for versions past 9.4, otherwise just update existing Dockerfile.
if greaterThanOrEqualTo9.4 "${version}"; then
# Generate the Dockerfile in the directory for this version.
echo "# DO NOT EDIT. Edit baseDockerfile${variant:+-$variant} and use update.sh" >"$path"/Dockerfile
cat "baseDockerfile${variant:+-$variant}" >>"$path"/Dockerfile
# Set the Jetty and JDK/JRE versions in the generated Dockerfile.
sed -ri 's/^(ENV JETTY_VERSION) .*/\1 '"$fullVersion"'/; ' "$path/Dockerfile"
sed -ri 's/^(FROM openjdk:)LABEL/\1'"$label"'/; ' "$path/Dockerfile"
else
sed -ri 's/^(ENV JETTY_VERSION) .*/\1 '"$fullVersion"'/; ' "$path/Dockerfile"
fi
fi
done