-
Notifications
You must be signed in to change notification settings - Fork 7
/
update.sh
executable file
·200 lines (172 loc) · 6.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env bash
# To add a new python version, just add a folder.
# E.g. mkdir -p python3.8/stretch/onbuild
set -e;
declare -A blacklist=(
[bot]=1 [templates]=1 [examples]=1
)
# set -x;
set -o nounset; # Treat undefined variables as errors, not as null.
set -o pipefail; # If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully.
set -o errtrace;
shopt -s nullglob;
# cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" # todo?
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=
appveyorEnv=
readme=
echo "versions:" ${versions[@]};
for folder in "${versions[@]}"; do
if [[ -n "${blacklist[$folder]:-}" ]]; then
echo "Skipping $folder, blacklist"
continue
fi
version=${folder#python}
if [ "python$version" != "$folder" ]; then
echo "Skipping $folder, not python*"
continue
fi
echo "Trying $version"
# check if is '-rc' version
rcVersion="${version%-rc}"
rcVersion="${rcVersion#python}"
rcGrepV='-v'
if [ "$rcVersion" != "${version#python}" ]; then
rcGrepV=
fi
# get possible versions, via the tags on github.
possibles=( $(
{
git ls-remote --tags https://github.com/python/cpython.git "refs/tags/v${rcVersion}.*" \
| sed -r 's!^.*refs/tags/v([0-9.]+).*$!\1!' \
|| :
# this page has a very aggressive varnish cache in front of it, which is why we also scrape tags from GitHub
curl -fsSL 'https://www.python.org/ftp/python/' \
| grep '<a href="'"$rcVersion." \
| sed -r 's!.*<a href="([^"/]+)/?".*!\1!' \
|| :
} | sort -ruV # todo
) )
echo "possibles: ${possibles[@]}";
fullVersion=
for possible in "${possibles[@]}"; do
possibleVersions=( $(
curl -fsSL "https://www.python.org/ftp/python/$possible/" \
| grep '<a href="Python-'"$rcVersion"'.*\.tar\.xz"' \
| sed -r 's!.*<a href="Python-([^"/]+)\.tar\.xz".*!\1!' \
| grep $rcGrepV -E -- '[a-zA-Z]+' \
| sort -rV \
|| true
) )
if [ "${#possibleVersions[@]}" -gt 0 ]; then
fullVersion="${possibleVersions[0]}"
break
fi
done
if [ -z "$fullVersion" ]; then
{
echo
echo
echo " error: cannot find $version (alpha/beta/rc?)"
echo
echo
} >&2
exit 1
fi
echo "$version: $fullVersion"
# "python3.6/stretch/port/onbuild"
# $dir: "python3.6/stretch/port/onbuild"
# $version: "3.6"
# $style: "port" | "socket"
# $v: "stretch/port/onbuild"
# $variant: "onbuild" | "alpine" | "windowsserver"
# $template: "debian" | "onbuild"
#
for style in \
port \
socket \
; do
for v in \
alpine{3.4,3.6} \
{wheezy,jessie,stretch,buster}/${style}{/slim,/onbuild,} \
windows/{windowsservercore,nanoserver} \
; do
dir="python$version/$v"
echo "dir: $dir"
# check if exists
if [ ! -d "$dir" ]; then
echo "folder: not found, skipping"
continue
fi
echo "folder: found, let's go"
echo "…"
variant="$(basename "$v")" # python3.6/port/onbuild -> onbuild python3.6/port -> port
echo "version: $version"
echo "template: $style";
echo "variant: $variant"
case "$variant" in
slim|onbuild) # python3.6/stretch/port/onbuild -> onbuild
template="$variant"; # onbuild
tag="$(basename "$(dirname "$dir")")"; # port
variant="$(basename "$(dirname "$(dirname "$dir")")")"; # stretch
;;
alpine*)
template='alpine';
tag="${variant#alpine}";
;;
*) # python3.6/stretch/port -> debian
template='debian';
tag="$variant"; # stretch
variant="$(basename "$(dirname "$dir")")"; # stretch
;;
esac
template="templates/Dockerfile.${style}.${template}.template"
echo "template: $template"
if [[ "$version" == 2.* ]]; then
echo " TODO: vimdiff ${versions[-1]}/$v/Dockerfile $version/$v/Dockerfile"
else
{ generated_warning; cat "$template"; } > "$dir/Dockerfile"
fi
python_tag=$version-$variant
image_label=$version-$variant-$tag
onbuild_label=$version-$variant-$tag-onbuild
echo "TAGS2: $version - $variant - $tag - $style"
echo python_tag=$python_tag
echo image_label=$image_label
sed -ri \
-e 's/^(FROM python):%%PLACEHOLDER%%/\1:'"${python_tag}"'/' \
-e 's/^(FROM luckydonald\/telegram-bot):%%PLACEHOLDER%%/\1:'"${image_label}"'/' \
-e 's!^(LABEL docker\.image\.base="luckydonald/telegram-bot:)%%PLACEHOLDER%%(")!\1'"${image_label}"'\2!' \
-e 's!^(LABEL docker\.image\.base="luckydonald/telegram-bot:)%%PLACEHOLDER%%(-onbuild")!\1'"${image_label}"'\2!' \
"$dir/Dockerfile"
case "$v" in
*/onbuild) ;; # don't list onbuilds, those are done by travis anyway as separate secondary step as they need the previous image.
windows/*)
appveyorEnv="$appveyorEnv"'\n - version: '"$version"'\n variant: '"$variant"
;;
*)
travisEnv="$travisEnv"'\n - VERSION='"$version"' VARIANT='"$v"' MODE=build'
# travisEnv="$travisEnv"'\n - VERSION='"$version"' VARIANT='"$v"' MODE=tests'
;;
esac
done
done
done
echo -e '=== <travisEnv> ==='"$travisEnv\n"'=== </travisEnv> ==='
travis=$(sed '/env:/,/before_install:/c\env:'"$travisEnv"'\nbefore_install:' .travis.yml)
echo "$travis" > .travis.yml
#appveyor="$(awk -v 'RS=\n' '$1 == "environment:" { $0 = "environment:\n matrix:'"$appveyorEnv"'" } { printf "%s%s", $0, RS }' .appveyor.yml)"
#echo "$appveyor" > .appveyor.yml