Skip to content

Commit b961afe

Browse files
authored
Merge branch 'develop' into local-infra-bootstrap
2 parents 241f519 + ca87f92 commit b961afe

33 files changed

+2025
-329
lines changed

.github/workflows/publish-nix-pgupgrade-scripts.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ jobs:
4949
- name: Grab release version
5050
id: process_release_version
5151
run: |
52-
VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
53-
VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
52+
VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
53+
VERSION=$(echo $VERSION | tr -d '"') # Remove any surrounding quotes
5454
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
5555
VERSION=${{ inputs.postgresVersion }}
5656
fi
@@ -81,7 +81,6 @@ jobs:
8181
SLACK_COLOR: 'danger'
8282
SLACK_MESSAGE: 'Publishing pg_upgrade scripts failed'
8383
SLACK_FOOTER: ''
84-
8584
publish-prod:
8685
needs: prepare
8786
runs-on: ubuntu-latest
@@ -95,11 +94,13 @@ jobs:
9594
steps:
9695
- name: Checkout Repo
9796
uses: actions/checkout@v3
98-
97+
98+
- uses: DeterminateSystems/nix-installer-action@main
99+
99100
- name: Grab release version
100101
id: process_release_version
101102
run: |
102-
VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
103+
VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
103104
VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
104105
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
105106
VERSION=${{ inputs.postgresVersion }}

.github/workflows/test.yml

Lines changed: 24 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
name: Test Database
2-
32
on:
43
push:
54
branches:
65
- develop
76
pull_request:
87
workflow_dispatch:
9-
108
jobs:
119
prepare:
1210
runs-on: ubuntu-latest
@@ -15,150 +13,72 @@ jobs:
1513
steps:
1614
- name: Checkout Repo
1715
uses: actions/checkout@v4
18-
19-
- uses: DeterminateSystems/nix-installer-action@main
2016

17+
- name: Clear Nix cache
18+
run: |
19+
sudo rm -rf /home/runner/.cache/nix
20+
21+
- uses: DeterminateSystems/nix-installer-action@main
22+
with:
23+
extra-conf: |
24+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
25+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
2126
- name: Set PostgreSQL versions
2227
id: set-versions
2328
run: |
24-
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
29+
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[] | select(. != "orioledb-17")' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
2530
echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT
26-
2731
build:
2832
needs: prepare
2933
strategy:
3034
matrix:
3135
postgres_version: ${{ fromJson(needs.prepare.outputs.postgres_versions) }}
3236
include:
33-
- runner: [self-hosted, X64]
37+
- runner: ubuntu-22.04
3438
arch: amd64
35-
- runner: arm-runner
39+
- runner: ubuntu-22.04
3640
arch: arm64
3741
runs-on: ${{ matrix.runner }}
3842
timeout-minutes: 180
3943
env:
4044
POSTGRES_PORT: 5478
4145
POSTGRES_PASSWORD: password
4246
steps:
43-
- uses: actions/checkout@v3
44-
47+
- uses: actions/checkout@v4
48+
- name: Clear Nix cache
49+
run: |
50+
sudo rm -rf /home/runner/.cache/nix
4551
- uses: DeterminateSystems/nix-installer-action@main
46-
52+
with:
53+
extra-conf: |
54+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
55+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
4756
- name: Set PostgreSQL version environment variable
4857
run: echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
49-
5058
- name: Strip quotes from pg major and set env var
5159
run: |
5260
stripped_version=$(echo ${{ matrix.postgres_version }} | sed 's/^"\(.*\)"$/\1/')
5361
echo "PGMAJOR=$stripped_version" >> $GITHUB_ENV
54-
5562
- name: Generate common-nix.vars.pkr.hcl
5663
run: |
57-
PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
64+
PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
5865
PG_VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
5966
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
60-
# Ensure there's a newline at the end of the file
6167
echo "" >> common-nix.vars.pkr.hcl
62-
6368
- id: settings
64-
# Remove spaces and quotes to get the raw version string
6569
run: sed -r 's/(\s|\")+//g' common-nix.vars.pkr.hcl >> $GITHUB_OUTPUT
66-
6770
- name: Generate args
6871
id: args
6972
run: |
70-
ARGS=$(sudo nix run nixpkgs#yq -- 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' ansible/vars.yml)
73+
ARGS=$(nix run nixpkgs#yq -- 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' ansible/vars.yml)
7174
echo "result<<EOF" >> $GITHUB_OUTPUT
7275
echo "$ARGS" >> $GITHUB_OUTPUT
7376
echo "EOF" >> $GITHUB_OUTPUT
74-
75-
- run: docker context create builders
76-
- uses: docker/setup-buildx-action@v3
77-
with:
78-
endpoint: builders
79-
- uses: docker/build-push-action@v5
80-
with:
81-
load: true
82-
context: .
83-
file: Dockerfile-${{ env.PGMAJOR }}
84-
target: production
85-
build-args: |
86-
${{ steps.args.outputs.result }}
87-
tags: supabase/postgres:${{ steps.settings.outputs.postgres-version }},supabase_postgres
88-
cache-from: |
89-
type=gha,scope=${{ github.ref_name }}-${{ steps.settings.outputs.postgres-version }}-${{ matrix.arch }}
90-
type=gha,scope=${{ github.base_ref }}-${{ steps.settings.outputs.postgres-version }}-${{ matrix.arch }}
91-
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-${{ steps.settings.outputs.postgres-version }}-${{ matrix.arch }}
92-
93-
- name: Start Postgres
94-
run: |
95-
docker run --rm --pull=never \
96-
-e POSTGRES_PASSWORD=${{ env.POSTGRES_PASSWORD }} \
97-
-p ${{ env.POSTGRES_PORT }}:5432 \
98-
--name supabase_postgres \
99-
-d supabase/postgres:${{ steps.settings.outputs.postgres-version }}
100-
101-
- name: Install psql
102-
run: |
103-
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
104-
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
105-
sudo apt update
106-
sudo apt install -y --no-install-recommends postgresql-client-${{ env.PGMAJOR }}
107-
108-
- name: Install pg_prove
109-
run: sudo cpan -T TAP::Parser::SourceHandler::pgTAP
110-
env:
111-
SHELL: /bin/bash
112-
113-
- name: Wait for healthy database
114-
run: |
115-
count=0
116-
until [ "$(docker inspect -f '{{.State.Health.Status}}' "$container")" == "healthy" ]; do
117-
exit=$?
118-
count=$((count + 1))
119-
if [ $count -ge "$retries" ]; then
120-
echo "Retry $count/$retries exited $exit, no more retries left."
121-
docker stop -t 2 "$container"
122-
return $exit
123-
fi
124-
sleep 1;
125-
done;
126-
echo "$container container is healthy"
127-
env:
128-
retries: 20
129-
container: supabase_postgres
130-
131-
- name: Run tests
132-
run: pg_prove migrations/tests/test.sql
133-
env:
134-
PGHOST: localhost
135-
PGPORT: ${{ env.POSTGRES_PORT }}
136-
PGDATABASE: postgres
137-
PGUSER: supabase_admin
138-
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
139-
140-
- name: Check migrations are idempotent
141-
run: |
142-
for sql in ./migrations/db/migrations/*.sql; do
143-
echo "$0: running $sql"
144-
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -f "$sql"
145-
done
146-
env:
147-
PGHOST: localhost
148-
PGPORT: ${{ env.POSTGRES_PORT }}
149-
PGDATABASE: postgres
150-
PGUSER: supabase_admin
151-
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
152-
153-
- name: Update Dockerfile.dbmate version
154-
run: |
155-
sed -i 's/%VERSION%/${{ env.PGMAJOR }}/g' migrations/Dockerfile.dbmate
156-
15777
- name: verify schema.sql is committed
15878
run: |
159-
docker compose -f migrations/docker-compose.yaml up db dbmate --abort-on-container-exit
79+
nix run github:supabase/postgres/${{ github.sha }}#dbmate-tool -- --version ${{ env.PGMAJOR }}
16080
if ! git diff --exit-code --quiet migrations/schema-${{ env.PGMAJOR }}.sql; then
16181
echo "Detected changes in schema.sql:"
16282
git diff migrations/schema-${{ env.PGMAJOR }}.sql
16383
exit 1
164-
fi
84+
fi

.github/workflows/testinfra-nix.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Set PostgreSQL versions
1919
id: set-versions
2020
run: |
21-
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
21+
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
2222
echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT
2323
2424
test-ami-nix:
@@ -61,6 +61,7 @@ jobs:
6161

6262
- name: Set PostgreSQL version environment variable
6363
run: echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
64+
6465

6566
- name: Generate common-nix.vars.pkr.hcl
6667
run: |

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ result*
2222
#IDE
2323
.idea/
2424
.vscode/
25+
26+
db
Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
11
#!/bin/bash
22

3+
check_orioledb_enabled() {
4+
local pg_conf="/etc/postgresql/postgresql.conf"
5+
if [ ! -f "$pg_conf" ]; then
6+
return 0
7+
fi
8+
grep "^shared_preload_libraries" "$pg_conf" | grep -c "orioledb" || return 0
9+
}
10+
11+
get_shared_buffers() {
12+
local opt_conf="/etc/postgresql-custom/generated-optimizations.conf"
13+
if [ ! -f "$opt_conf" ]; then
14+
return 0
15+
fi
16+
grep "^shared_buffers = " "$opt_conf" | cut -d "=" -f2 | tr -d ' ' || return 0
17+
}
18+
19+
update_orioledb_buffers() {
20+
local pg_conf="/etc/postgresql/postgresql.conf"
21+
local value="$1"
22+
if grep -q "^orioledb.main_buffers = " "$pg_conf"; then
23+
sed -i "s/^orioledb.main_buffers = .*/orioledb.main_buffers = $value/" "$pg_conf"
24+
else
25+
echo "orioledb.main_buffers = $value" >> "$pg_conf"
26+
fi
27+
}
28+
29+
main() {
30+
local has_orioledb=$(check_orioledb_enabled)
31+
if [ "$has_orioledb" -lt 1 ]; then
32+
return 0
33+
fi
34+
local shared_buffers_value=$(get_shared_buffers)
35+
if [ ! -z "$shared_buffers_value" ]; then
36+
update_orioledb_buffers "$shared_buffers_value"
37+
fi
38+
}
39+
40+
# Initial locale setup
341
if [ $(cat /etc/locale.gen | grep -c en_US.UTF-8) -eq 0 ]; then
4-
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
42+
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
543
fi
644

745
if [ $(locale -a | grep -c en_US.utf8) -eq 0 ]; then
8-
locale-gen
46+
locale-gen
947
fi
48+
49+
main

ansible/tasks/setup-postgres.yml

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,49 @@
204204
ansible_command_timeout: 60
205205
when: debpkg_mode
206206

207-
- name: Initialize the database stage2_nix
208-
become: yes
209-
become_user: postgres
210-
shell: source /var/lib/postgresql/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access" -o "--username=supabase_admin"
211-
args:
212-
executable: /bin/bash
213-
environment:
214-
LANG: en_US.UTF-8
215-
LANGUAGE: en_US.UTF-8
216-
LC_ALL: en_US.UTF-8
217-
LC_CTYPE: en_US.UTF-8
218-
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
219-
vars:
220-
ansible_command_timeout: 60
221-
# Circumvents the following error:
222-
# "Timeout (12s) waiting for privilege escalation prompt"
223-
when: stage2_nix
207+
- name: Check psql_version and modify supautils.conf and postgresql.conf if necessary
208+
block:
209+
- name: Check if psql_version is psql_orioledb
210+
set_fact:
211+
is_psql_oriole: "{{ psql_version in ['psql_orioledb-16', 'psql_orioledb-17'] }}"
212+
213+
- name: Initialize the database stage2_nix (non-orioledb)
214+
become: yes
215+
become_user: postgres
216+
shell: source /var/lib/postgresql/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access" -o "--username=supabase_admin"
217+
args:
218+
executable: /bin/bash
219+
environment:
220+
LANG: en_US.UTF-8
221+
LANGUAGE: en_US.UTF-8
222+
LC_ALL: en_US.UTF-8
223+
LC_CTYPE: en_US.UTF-8
224+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
225+
vars:
226+
ansible_command_timeout: 60
227+
when: stage2_nix and not is_psql_oriole
228+
229+
- name: Initialize the database stage2_nix (orioledb)
230+
become: yes
231+
become_user: postgres
232+
shell: >
233+
source /var/lib/postgresql/.bashrc && initdb -D /var/lib/postgresql/data
234+
--allow-group-access
235+
--username=supabase_admin
236+
--locale-provider=icu
237+
--encoding=UTF-8
238+
--icu-locale=en_US.UTF-8
239+
args:
240+
executable: /bin/bash
241+
environment:
242+
LANG: en_US.UTF-8
243+
LANGUAGE: en_US.UTF-8
244+
LC_ALL: en_US.UTF-8
245+
LC_CTYPE: en_US.UTF-8
246+
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
247+
vars:
248+
ansible_command_timeout: 60
249+
when: stage2_nix and is_psql_oriole
224250

225251
- name: copy PG systemd unit
226252
template:

0 commit comments

Comments
 (0)