forked from docker-library/postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·112 lines (97 loc) · 4.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
#!/bin/bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
# sort version numbers with highest last (so it goes first in .travis.yml)
IFS=$'\n'; versions=( $(echo "${versions[*]}" | sort -V) ); unset IFS
defaultDebianSuite='buster-slim'
declare -A debianSuite=(
# https://github.com/docker-library/postgres/issues/582
[9.4]='stretch-slim'
[9.5]='stretch-slim'
[9.6]='stretch-slim'
[10]='stretch-slim'
[11]='stretch-slim'
)
defaultAlpineVersion='3.11'
declare -A alpineVersion=(
#[9.6]='3.5'
)
packagesBase='http://apt.postgresql.org/pub/repos/apt/dists/'
declare -A suitePackageList=() suiteArches=()
travisEnv=
for version in "${versions[@]}"; do
tag="${debianSuite[$version]:-$defaultDebianSuite}"
suite="${tag%%-slim}"
if [ -z "${suitePackageList["$suite"]:+isset}" ]; then
suitePackageList["$suite"]="$(curl -fsSL "${packagesBase}/${suite}-pgdg/main/binary-amd64/Packages.bz2" | bunzip2)"
fi
if [ -z "${suiteArches["$suite"]:+isset}" ]; then
suiteArches["$suite"]="$(curl -fsSL "${packagesBase}/${suite}-pgdg/Release" | gawk -F ':[[:space:]]+' '$1 == "Architectures" { gsub(/[[:space:]]+/, "|", $2); print $2 }')"
fi
versionList="$(echo "${suitePackageList["$suite"]}"; curl -fsSL "${packagesBase}/${suite}-pgdg/${version}/binary-amd64/Packages.bz2" | bunzip2)"
fullVersion="$(echo "$versionList" | awk -F ': ' '$1 == "Package" { pkg = $2 } $1 == "Version" && pkg == "postgresql-'"$version"'" { print $2; exit }' || true)"
majorVersion="${version%%.*}"
echo "$version: $fullVersion"
cp docker-entrypoint.sh "$version/"
sed -e 's/%%PG_MAJOR%%/'"$version"'/g;' \
-e 's/%%PG_VERSION%%/'"$fullVersion"'/g' \
-e 's/%%DEBIAN_TAG%%/'"$tag"'/g' \
-e 's/%%DEBIAN_SUITE%%/'"$suite"'/g' \
-e 's/%%ARCH_LIST%%/'"${suiteArches["$suite"]}"'/g' \
Dockerfile-debian.template > "$version/Dockerfile"
if [ "$majorVersion" = '9' ]; then
sed -i -e 's/WALDIR/XLOGDIR/g' \
-e 's/waldir/xlogdir/g' \
"$version/docker-entrypoint.sh"
# ICU support was introduced in PostgreSQL 10 (https://www.postgresql.org/docs/10/static/release-10.html#id-1.11.6.9.5.13)
sed -i -e '/icu/d' "$version/Dockerfile"
else
# postgresql-contrib-10 package does not exist, but is provided by postgresql-10
# Packages.gz:
# Package: postgresql-10
# Provides: postgresql-contrib-10
sed -i -e '/postgresql-contrib-/d' "$version/Dockerfile"
fi
# TODO figure out what to do with odd version numbers here, like release candidates
srcVersion="${fullVersion%%-*}"
# change "10~beta1" to "10beta1" for ftp urls
tilde='~'
srcVersion="${srcVersion//$tilde/}"
srcSha256="$(curl -fsSL "https://ftp.postgresql.org/pub/source/v${srcVersion}/postgresql-${srcVersion}.tar.bz2.sha256" | cut -d' ' -f1)"
for variant in alpine; do
if [ ! -d "$version/$variant" ]; then
continue
fi
cp docker-entrypoint.sh "$version/$variant/"
sed -i 's/gosu/su-exec/g' "$version/$variant/docker-entrypoint.sh"
sed -e 's/%%PG_MAJOR%%/'"$version"'/g' \
-e 's/%%PG_VERSION%%/'"$srcVersion"'/g' \
-e 's/%%PG_SHA256%%/'"$srcSha256"'/g' \
-e 's/%%ALPINE-VERSION%%/'"${alpineVersion[$version]:-$defaultAlpineVersion}"'/g' \
"Dockerfile-$variant.template" > "$version/$variant/Dockerfile"
if [ "$majorVersion" = '9' ]; then
sed -i -e 's/WALDIR/XLOGDIR/g' \
-e 's/waldir/xlogdir/g' \
"$version/$variant/docker-entrypoint.sh"
# ICU support was introduced in PostgreSQL 10 (https://www.postgresql.org/docs/10/static/release-10.html#id-1.11.6.9.5.13)
sed -i -e '/icu/d' "$version/$variant/Dockerfile"
fi
if [ "$majorVersion" -gt 11 ]; then
sed -i '/backwards compat/d' "$version/$variant/Dockerfile"
fi
if [ "$majorVersion" -lt 11 ]; then
# JIT / LLVM is only supported in PostgreSQL 11+ (https://github.com/docker-library/postgres/issues/475)
sed -i '/llvm/d' "$version/$variant/Dockerfile"
fi
travisEnv="\n - VERSION=$version VARIANT=$variant$travisEnv"
done
travisEnv="\n - VERSION=$version FORCE_DEB_BUILD=1$travisEnv"
travisEnv="\n - VERSION=$version$travisEnv"
done
travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml