forked from tianon/docker-postgres-upgrade
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·76 lines (71 loc) · 1.58 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
#!/usr/bin/env bash
set -Eeuo pipefail
# TODO scrape this somehow?
newVersions=(
15
14
)
oldVersions=(
15
14
13
12
11
10
9.6
#9.5
#9.4
#9.3
#9.2
)
suite='bullseye'
# Alias if it's linux
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
if [[ $machine == "Mac" ]]; then
echo "Using gsed"
alias sed='gsed'
fi
for i in "${!newVersions[@]}"; do
new="${newVersions[$i]}"
echo "# $new"
docker pull "postgres:$new-$suite" > /dev/null
(( j = i + 1 ))
for old in "${oldVersions[@]:$j}"; do
dir="$old-to-$new"
echo "- $old -> $new ($dir)"
oldVersion="$(
docker run --rm -e OLD="$old" "postgres:$new-$suite" bash -Eeuo pipefail -c '
sed -i "s/\$/ $OLD/" /etc/apt/sources.list.d/pgdg.list
apt-get update -qq 2>/dev/null
apt-cache policy "postgresql-$OLD" \
| awk "\$1 == \"Candidate:\" { print \$2; exit }"
'
)"
echo " - $oldVersion"
if [ "$oldVersion" = '(none)' ]; then
continue
fi
mkdir -p "$dir"
sed \
-e "s!%%POSTGRES_OLD%%!$old!g" \
-e "s!%%POSTGRES_OLD_VERSION%%!$oldVersion!g" \
-e "s!%%POSTGRES_NEW%%!$new!g" \
-e "s!%%SUITE%%!$suite!g" \
Dockerfile.template \
> "$dir/Dockerfile"
cp docker-upgrade "$dir/"
if [[ "$old" != 9.* ]]; then
gsed -i '/postgresql-contrib-/d' "$dir/Dockerfile"
fi
cd $dir
docker buildx build . --push --platform linux/arm64/v8,linux/amd64 --tag nline/timescale-upgrade:$dir
cd ..
done
done