-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathupdate.sh
executable file
·95 lines (77 loc) · 2.2 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
#!/bin/bash
set -e
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
generated_warning() {
cat <<-EOH
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
EOH
}
travisEnv=
for version in "${versions[@]}"; do
possibles=( $(
{
git ls-remote --tags https://github.com/varnishcache/varnish-cache.git "refs/tags/varnish-${version}.*" \
| sed -r 's!^.*refs/tags/varnish-([0-9a-z.]+).*$!\1!' \
|| :
} | sort -ruV
) )
fullVersion=
if [ "${#possibles[@]}" -gt 0 ]; then
fullVersion="${possibles[0]}"
fi
if [ -z "$fullVersion" ]; then
echo >&2
echo >&2 "error: unable to determine available releases of $version"
echo >&2
exit 1
fi
url='https://varnish-cache.org/_downloads/varnish-'"$fullVersion"'.tgz'
sha256=$(wget -qO- -o /dev/null "$url" | sha256sum - | awk '{print $1}')
dockerfiles=()
for variant in stretch alpine3.8; do
[ -d "$version/$variant" ] || continue
alpineVer="${variant#alpine}"
baseDockerfile=Dockerfile-debian.template
if [ "${variant#alpine}" != "$variant" ]; then
baseDockerfile=Dockerfile-alpine.template
fi
{ generated_warning; cat "$baseDockerfile"; } > "$version/$variant/Dockerfile"
echo "Generating $version/$variant/Dockerfile from $baseDockerfile"
cp -a \
docker-varnish-entrypoint \
"$version/$variant/"
sed -ri \
-e 's!%%DEBIAN_SUITE%%!'"$variant"'-slim!' \
-e 's!%%ALPINE_VERSION%%!'"$alpineVer"'!' \
"$version/$variant/Dockerfile"
dockerfiles+=( "$version/$variant/Dockerfile" )
done
(
set -x
sed -ri \
-e 's!%%VARNISH_VERSION%%!'"$fullVersion"'!' \
-e 's!%%VARNISH_URL%%!'"$url"'!' \
-e 's!%%VARNISH_SHA256%%!'"$sha256"'!' \
"${dockerfiles[@]}"
)
newTravisEnv=
for dockerfile in "${dockerfiles[@]}"; do
dir="${dockerfile%Dockerfile}"
dir="${dir%/}"
variant="${dir#$version}"
variant="${variant#/}"
newTravisEnv+='\n - VERSION='"$version VARIANT=$variant"
done
travisEnv="$newTravisEnv$travisEnv"
done
travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml