forked from docker-library/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·188 lines (161 loc) · 6.17 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
#!/usr/bin/env bash
set -x
set -Eeuo pipefail
shopt -s nullglob
# https://www.python.org/downloads/23Introduction (under "OpenPGP Public Keys")
declare -A gpgKeys=(
# gpg: key AA65421D: public key "Ned Deily (Python release signing key) <[email protected]>" imported
[3.7]='0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D'
# https://www.python.org/dev/peps/pep-0537/#release-manager-and-crew
# gpg: key B26995E310250568: public key "\xc5\x81ukasz Langa (GPG langa.pl) <[email protected]>" imported
[3.8]='E3FF2839C048B25C084DEBE9B26995E310250568'
# https://www.python.org/dev/peps/pep-0569/#release-manager-and-crew
# gpg: key B26995E310250568: public key "\xc5\x81ukasz Langa (GPG langa.pl) <[email protected]>" imported
[3.9]='E3FF2839C048B25C084DEBE9B26995E310250568'
# https://www.python.org/dev/peps/pep-0596/#release-manager-and-crew
# gpg: key 64E628F8D684696D: public key "Pablo Galindo Salgado <[email protected]>" imported
[3.10]='A035C8C19219BA821ECEA86B64E628F8D684696D'
# https://www.python.org/dev/peps/pep-0619/#release-manager-and-crew
# gpg: key 64E628F8D684696D: public key "Pablo Galindo Salgado <[email protected]>" imported
[3.11]='A035C8C19219BA821ECEA86B64E628F8D684696D'
# https://www.python.org/dev/peps/pep-0664/#release-manager-and-crew
)
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
pipVersion="$(curl -fsSL 'https://pypi.org/pypi/pip/json' | jq -r .info.version)"
getPipCommit="$(curl -fsSL 'https://github.com/pypa/get-pip/commits/main/public/get-pip.py.atom' | tac|tac | awk -F '[[:space:]]*[<>/]+' '$2 == "id" && $3 ~ /Commit/ { print $4; exit }')"
getPipUrl="https://github.com/pypa/get-pip/raw/$getPipCommit/public/get-pip.py"
getPipSha256="$(curl -fsSL "$getPipUrl" | sha256sum | cut -d' ' -f1)"
generated_warning() {
cat <<-EOH
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
EOH
}
is_good_version() {
local dir="$1"; shift
local dirVersion="$1"; shift
local fullVersion="$1"; shift
if ! wget -q -O /dev/null -o /dev/null --spider "https://www.python.org/ftp/python/$dirVersion/Python-$fullVersion.tar.xz"; then
return 1
fi
if [ -d "$dir/windows" ] && ! wget -q -O /dev/null -o /dev/null --spider "https://www.python.org/ftp/python/$dirVersion/python-$fullVersion-amd64.exe"; then
return 1
fi
return 0
}
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
rcGrepV='-v'
if [ "$rcVersion" != "$version" ]; then
rcGrepV=
fi
possibles=( $(
{
git ls-remote --tags https://github.com/python/cpython.git "refs/tags/v${rcVersion}.*" \
| sed -r 's!^.*refs/tags/v([0-9a-z.]+).*$!\1!' \
| grep $rcGrepV -E -- '[a-zA-Z]+' \
|| :
# 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!' \
| grep $rcGrepV -E -- '[a-zA-Z]+' \
|| :
} | sort -ruV
) )
fullVersion=
declare -A impossible=()
for possible in "${possibles[@]}"; do
rcPossible="${possible%%[a-z]*}"
# varnish is great until it isn't (usually the directory listing we scrape below is updated/uncached significantly later than the release being available)
if is_good_version "$version" "$rcPossible" "$possible"; then
fullVersion="$possible"
break
fi
if [ -n "${impossible[$rcPossible]:-}" ]; then
continue
fi
impossible[$rcPossible]=1
possibleVersions=( $(
wget -qO- -o /dev/null "https://www.python.org/ftp/python/$rcPossible/" \
| 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
) )
for possibleVersion in "${possibleVersions[@]}"; do
if is_good_version "$version" "$rcPossible" "$possibleVersion"; then
fullVersion="$possibleVersion"
break
fi
done
done
if [ -z "$fullVersion" ]; then
{
echo
echo
echo " error: cannot find $version (alpha/beta/rc?)"
echo
echo
} >&2
exit 1
fi
echo "$version: $fullVersion"
for v in \
alpine{3.16,3.17} \
{stretch,buster}{/slim,} \
windows/windowsservercore-{1809,ltsc2016} \
bionic{/lite,} \
; do
dir="$version/$v"
variant="$(basename "$v")"
[ -d "$dir" ] || continue
case "$variant" in
slim) template="$variant"; tag="$(basename "$(dirname "$dir")")" ;;
lite) template="$variant"; tag="$(basename "$(dirname "$dir")")" ;;
windowsservercore-*) template='windowsservercore'; tag="${variant#*-}" ;;
alpine*) template='alpine'; tag="${variant#alpine}" ;;
bionic) template='ubuntu'; tag="$variant" ;;
*) template='debian'; tag="$variant" ;;
esac
if [ "$variant" = 'slim' ]; then
# use "debian:*-slim" variants for "python:*-slim" variants
tag+='-slim'
fi
template="Dockerfile-${template}.template"
{ generated_warning; cat "$template"; } > "$dir/Dockerfile"
sed -ri \
-e 's/^(ENV GPG_KEY) .*/\1 '"${gpgKeys[$version]:-${gpgKeys[$rcVersion]}}"'/' \
-e 's/^(ENV PYTHON_VERSION) .*/\1 '"$fullVersion"'/' \
-e 's/^(ENV PYTHON_RELEASE) .*/\1 '"${fullVersion%%[a-z]*}"'/' \
-e 's/^(ENV PYTHON_PIP_VERSION) .*/\1 '"$pipVersion"'/' \
-e 's!^(ENV PYTHON_GET_PIP_URL) .*!\1 '"$getPipUrl"'!' \
-e 's!^(ENV PYTHON_GET_PIP_SHA256) .*!\1 '"$getPipSha256"'!' \
-e 's/^(FROM python):.*/\1:'"$version-$tag"'/' \
-e 's!^(FROM (debian|buildpack-deps|vaporio/foundation|vaporio/buildpack-deps|alpine|mcr[.]microsoft[.]com/[^:]+)):.*!\1:'"$tag"'!' \
"$dir/Dockerfile"
major="${rcVersion%%.*}"
minor="${rcVersion#$major.}"
minor="${minor%%.*}"
if [ "$minor" -ge 8 ]; then
# PROFILE_TASK has a reasonable default starting in 3.8+; see:
# https://bugs.python.org/issue36044
# https://github.com/python/cpython/pull/14702
# https://github.com/python/cpython/pull/14910
perl -0 -i -p -e "s![^\n]+PROFILE_TASK(='[^']+?')?[^\n]+\n!!gs" "$dir/Dockerfile"
fi
if [ "$minor" -ge 9 ]; then
# "wininst-*.exe" is not installed for Unix platforms on Python 3.9+: https://github.com/python/cpython/pull/14511
sed -ri -e '/wininst/d' "$dir/Dockerfile"
fi
done
done