10000 chore: fix binary collection; install .deb pg binaries for u18 (#681) · supabase/postgres@b3e089c · GitHub
[go: up one dir, main page]

Skip to content

Commit b3e089c

Browse files
authored
chore: fix binary collection; install .deb pg binaries for u18 (#681)
* chore: fix binary collection; install .deb pg binaries on u18 * chore: ubuntu 18 postgres .deb install compat * chore: bump version * chore: Install ubuntu 18 deps * chore: additional handling * chore: bump version * chore: more library locations * chore: bump postgres version
1 parent 80c4bd0 commit b3e089c

File tree

9 files changed

+120
-36
lines changed

9 files changed

+120
-36
lines changed

.github/workflows/ami-build-ubuntu-18.yml

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ on:
1818
workflow_dispatch:
1919

2020
jobs:
21-
build:
22-
runs-on: [self-hosted, X64]
21+
build:
22+
strategy:
23+
matrix:
24+
include:
25+
- runner: arm-runner
26+
arch: arm64
27+
ubuntu_release: bionic
28+
ubuntu_version: 18.04
29+
mcpu: neoverse-n1
30+
runs-on: ${{ matrix.runner }}
2331
timeout-minutes: 150
2432
permissions:
2533
contents: write
@@ -28,8 +36,62 @@ jobs:
2836

2937
steps:
3038
- name: Checkout Repo
31-
uses: actions/checkout@v2
39+
uses: actions/checkout@v3
3240

41+
- id: args
42+
uses: mikefarah/yq@master
43+
with:
44+
cmd: yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml'
45+
- run: docker context create builders
46+
- uses: docker/setup-buildx-action@v2
47+
with:
48+
endpoint: builders
49+
- uses: docker/build-push-action@v3
50+
with:
51+
push: false
52+
load: true
53+
build-args: |
54+
${{ steps.args.outputs.result }}
55+
target: extensions
56+
tags: supabase/postgres:extensions
57+
platforms: linux/${{ matrix.arch }}
58+
cache-from: type=gha
59+
cache-to: type=gha,mode=max
60+
61+
- name: Extract built packages
62+
run: |
63+
mkdir -p /tmp/extensions ansible/files/extensions
64+
docker save supabase/postgres:extensions | tar xv -C /tmp/extensions
65+
for layer in /tmp/extensions/*/layer.tar; do
66+
tar xvf "$layer" -C ansible/files/extensions --strip-components 1
67+
done
68+
69+
- id: version
70+
run: echo "${{ steps.args.outputs.result }}" | grep "postgresql" >> "$GITHUB_OUTPUT"
71+
- name: Build Postgres deb
72+
uses: docker/build-push-action@v3
73+
with:
74+
push: false
75+
load: true
76+
file: docker/Dockerfile
77+
target: pg-deb
78+
build-args: |
79+
ubuntu_release=${{ matrix.ubuntu_release }}
80+
ubuntu_release_no=${{ matrix.ubuntu_version }}
81+
postgresql_major=${{ steps.version.outputs.postgresql_major }}
82+
postgresql_release=${{ steps.version.outputs.postgresql_release }}
83+
CPPFLAGS=-mcpu=${{ matrix.mcpu }}
84+
tags: supabase/postgres:deb-u18
85+
platforms: linux/${{ matrix.arch }}
86+
cache-from: type=gha
87+
cache-to: type=gha,mode=max
88+
- name: Extract Postgres deb
89+
run: |
90+
mkdir -p /tmp/build ansible/files/postgres
91+
docker save supabase/postgres:deb-u18 | tar xv -C /tmp/build
92+
for layer in /tmp/build/*/layer.tar; do
93+
tar xvf "$layer" -C ansible/files/postgres --strip-components 1
94+
done
3395
- name: Build AMI
3496
run: |
3597
GIT_SHA=${{github.sha}}

.github/workflows/ami-release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jobs:
1616
include:
1717
- runner: arm-runner
1818
arch: arm64
19-
ubuntu: focal
19+
ubuntu_release: focal
20+
ubuntu_version: 20.04
2021
mcpu: neoverse-n1
2122
runs-on: ${{ matrix.runner }}
2223
timeout-minutes: 150
@@ -66,7 +67,8 @@ jobs:
6667
file: docker/Dockerfile
6768
target: pg-deb
6869
build-args: |
69-
ubuntu_release=${{ matrix.ubuntu }}
70+
ubuntu_release=${{ matrix.ubuntu_release }}
71+
ubuntu_release_no=${{ matrix.ubuntu_version }}
7072
postgresql_major=${{ steps.version.outputs.postgresql_major }}
7173
postgresql_release=${{ steps.version.outputs.postgresql_release }}
7274
CPPFLAGS=-mcpu=${{ matrix.mcpu }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ARG rum_release=1.3.13
2424
ARG pg_hashids_release=cd0e1b31d52b394a0df64079406a14a4f7387cd6
2525
ARG libsodium_release=1.0.18
2626
ARG pgsodium_release=3.1.6
27-
ARG pg_graphql_release=1.1.0
27+
ARG pg_graphql_release=1.2.2
2828
ARG pg_stat_monitor_release=1.1.1
2929
ARG pg_jsonschema_release=0.1.4
3030
ARG vault_release=0.2.8

ansible/files/admin_api_scripts/pg_upgrade_complete.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
set -eEuo pipefail
99

10+
SCRIPT_DIR=$(dirname -- "$0";)
1011
# shellcheck disable=SC1091
11-
source ./pg_upgrade_common.sh
12+
source "$SCRIPT_DIR/pg_upgrade_common.sh"
1213

1314
LOG_FILE="/tmp/pg-upgrade-complete.log"
1415

ansible/files/admin_api_scripts/pg_upgrade_initiate.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ PG13_EXTENSIONS_TO_DISABLE=(
2727

2828
set -eEuo pipefail
2929

30+
SCRIPT_DIR=$(dirname -- "$0";)
3031
# shellcheck disable=SC1091
31-
source ./pg_upgrade_common.sh
32+
source "$SCRIPT_DIR/pg_upgrade_common.sh"
3233

3334
LOG_FILE="/var/log/pg-upgrade-initiate.log"
3435

@@ -68,13 +69,17 @@ cleanup() {
6869
ship_logs "/var/log/pg_upgrade_output.d/pg_upgrade.log" || true
6970
fi
7071

71-
if [ -L /var/lib/postgresql ]; then
72-
rm /var/lib/postgresql
73-
mv /var/lib/postgresql.bak /var/lib/postgresql
72+
if [ -L "/usr/share/postgresql/${PGVERSION}" ]; then
73+
rm "/usr/share/postgresql/${PGVERSION}"
74+
75+
if [ -f "/usr/share/postgresql/${PGVERSION}.bak" ]; then
76+
mv "/usr/share/postgresql/${PGVERSION}.bak" "/usr/share/postgresql/${PGVERSION}"
77+
fi
7478
fi
7579

76-
if [ -L /usr/lib/postgresql/lib/aarch64/libpq.so.5 ]; then
80+
if [ -f "/usr/lib/postgresql/lib/aarch64/libpq.so.5.bak" ]; then
7781
rm /usr/lib/postgresql/lib/aarch64/libpq.so.5
82+
mv /usr/lib/postgresql/lib/aarch64/libpq.so.5.bak /usr/lib/postgresql/lib/aarch64/libpq.so.5
7883
fi
7984

8085
if [ "$IS_DRY_RUN" = false ]; then
@@ -169,10 +174,11 @@ function initiate_upgrade {
169174
chown -R postgres:postgres "/tmp/pg_upgrade_bin/$PGVERSION"
170175

171176
# Make latest libpq available to pg_upgrade
172-
mkdir -p /usr/lib/postgresql/lib/aarch64
173-
if [ ! -L /usr/lib/postgresql/lib/aarch64/libpq.so.5 ]; then
174-
ln -s "$PGLIBNEW/libpq.so.5" /usr/lib/postgresql/lib/aarch64/libpq.so.5
177+
mkdir -p /usr/lib/aarch64-linux-gnu
178+
if [ -f "/usr/lib/aarch64-linux-gnu/libpq.so.5" ]; then
179+
mv /usr/lib/aarch64-linux-gnu/libpq.so.5 /usr/lib/aarch64-linux-gnu/libpq.so.5.bak
175180
fi
181+
ln -s "$PG_UPGRADE_BIN_DIR/libpq.so.5" /usr/lib/aarch64-linux-gnu/libpq.so.5
176182

177183
# upgrade job outputs a log in the cwd; needs write permissions
178184
mkdir -p /tmp/pg_upgrade/
@@ -221,6 +227,14 @@ function initiate_upgrade {
221227
echo "7. Granting SUPERUSER to postgres user"
222228
run_sql -c "ALTER USER postgres WITH SUPERUSER;"
223229

230+
if [ -d "/usr/share/postgresql/${PGVERSION}" ]; then
231+
mv "/usr/share/postgresql/${PGVERSION}" "/usr/share/postgresql/${PGVERSION}.bak"
232+
fi
233+
ln -s "$PGSHARENEW" "/usr/share/postgresql/${PGVERSION}"
234+
235+
cp --remove-destination "$PGLIBNEW"/*.control "$PGSHARENEW/extension/"
236+
cp --remove-destination "$PGLIBNEW"/*.sql "$PGSHARENEW/extension/"
237+
224238
echo "8. Creating new data directory, initializing database"
225239
chown -R postgres:postgres "$MOUNT_POINT/"
226240
rm -rf "${PGDATANEW:?}/"
@@ -243,20 +257,6 @@ EOF
243257
if [ "$IS_DRY_RUN" = true ]; then
244258
UPGRADE_COMMAND="$UPGRADE_COMMAND --check"
245259
else
246-
mv /var/lib/postgresql /var/lib/postgresql.bak
247-
ln -s "$PGSHARENEW" /var/lib/postgresql
248-
249-
if [ ! -L /var/lib/postgresql.bak/data ]; then
250-
if [ -L /var/lib/postgresql/data ]; then
251-
rm /var/lib/postgresql/data
252-
fi
253-
ln -s /var/lib/postgresql.bak/data /var/lib/postgresql/data
254-
fi
255-
256-
if [ ! -L /var/lib/postgresql/data ]; then
257-
ln -s /data/pgdata /var/lib/postgresql/data
258-
fi
259-
260260
echo "9. Stopping postgres; running pg_upgrade"
261261
systemctl stop postgresql
262262
fi

ansible/tasks/internal/collect-pg-binaries.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,34 @@
66
- name: Collect Postgres binaries - collect binaries and libraries
77
copy:
88
remote_src: yes
9-
src: /usr/lib/postgresql/{{ item }}/
9+
src: /usr/lib/postgresql/{{ postgresql_major }}/{{ item }}/
1010
dest: /tmp/pg_binaries/{{ postgresql_major }}/{{ item }}/
1111
with_items:
1212
- bin
1313
- lib
1414

15+
- name: Collect Postgres libraries - collect libraries which are in /usr/lib/postgresql/lib/
16+
copy:
17+
remote_src: yes
18+
src: /usr/lib/postgresql/lib/
19+
dest: /tmp/pg_binaries/{{ postgresql_major }}/lib/
20+
21+
- name: Collect Postgres libraries - collect libraries which are in /var/lib/postgresql/extension/
22+
copy:
23+
remote_src: yes
24+
src: /var/lib/postgresql/extension/
25+
dest: /tmp/pg_binaries/{{ postgresql_major }}/lib/
26+
27+
- name: Collect Postgres libraries - collect latest libpq
28+
copy:
29+
remote_src: yes
30+
src: /usr/lib/aarch64-linux-gnu/libpq.so.5
31+
dest: /tmp/pg_binaries/{{ postgresql_major }}/libpq.so.5
32+
1533
- name: Collect Postgres binaries - collect shared files
1634
copy:
1735
remote_src: yes
18-
src: /var/lib/postgresql/
36+
src: /usr/share/postgresql/{{ postgresql_major }}/
1937
dest: /tmp/pg_binaries/{{ postgresql_major }}/share/
2038

2139
- name: Collect Postgres binaries - create tarfile

ansible/tasks/internal/supautils.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- clang-12
1616
update_cache: yes
1717
cache_valid_time: 3600
18-
when: ansible_distribution_version != "18.04"
18+
when: ansible_distribution_version == "18.04"
1919

2020
- name: supautils - download latest release
2121
get_url:

common.vars.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.1.0.98"
1+
postgres-version = "15.1.0.99"

docker/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ ARG ubuntu_release=focal
22
FROM ubuntu:${ubuntu_release} as base
33

44
ARG ubuntu_release
5+
ARG ubuntu_release_no
56
ARG postgresql_major=15
67
ARG postgresql_release=${postgresql_major}.1
78

@@ -39,8 +40,8 @@ RUN apt-get build-dep -y postgresql-common pgdg-keyring && \
3940
dpkg-scanpackages . > Packages && \
4041
apt-get -o Acquire::GzipIndexes=false update
4142

42-
RUN apt-get build-dep -y "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg20.04+1" && \
43-
apt-get source --compile "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg20.04+1" && \
43+
RUN apt-get build-dep -y "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg${ubuntu_release_no}+1" && \
44+
apt-get source --compile "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg${ubuntu_release_no}+1" && \
4445
dpkg-scanpackages . > Packages && \
4546
apt-get -o Acquire::GzipIndexes=false update
4647

@@ -60,7 +61,7 @@ RUN echo "deb [ trusted=yes ] file:///tmp/build ./" > /etc/apt/sources.list.d/te
6061
apt-get -o Acquire::GzipIndexes=false update && \
6162
apt-get install -y --no-install-recommends postgresql-common && \
6263
sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf && \
63-
apt-get install -y --no-install-recommends "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg20.04+1" && \
64+
apt-get install -y --no-install-recommends "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg${ubuntu_release_no}+1" && \
6465
rm -rf /var/lib/apt/lists/* && \
6566
rm -rf /tmp/build /etc/apt/sources.list.d/temp.list
6667

0 commit comments

Comments
 (0)
0