Skip to content

Commit c29c2e1

Browse files
committed
Merge branch 'develop' into revoke-history
2 parents c685387 + e99753e commit c29c2e1

File tree

108 files changed

+5321
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+5321
-75
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
* @supabase/backend
22
migrations/ @supabase/cli @supabase/backend
3-
docker/orioledb @supabase/postgres
3+
docker/orioledb @supabase/postgres @supabase/backend
44
common.vars.pkr.hcl @supabase/postgres @supabase/backend

.github/workflows/dockerhub-release-aio.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ on:
1313
- develop
1414
types:
1515
- completed
16+
workflow_dispatch:
17+
inputs:
18+
baseDockerVersion:
19+
description: 'Base Docker Version. E.g., 15.1.1.27'
20+
required: false
1621

1722
jobs:
1823
settings:
1924
runs-on: ubuntu-latest
2025
outputs:
26+
base_docker_version: ${{ steps.base_docker.outputs.base-docker-version }}
2127
docker_version: ${{ steps.settings.outputs.postgres-version }}
2228
image_tag: supabase/postgres:aio-${{ steps.settings.outputs.postgres-version }}
2329
fly_image_tag: supabase-postgres-image:aio-${{ steps.settings.outputs.postgres-version }}
@@ -27,6 +33,13 @@ jobs:
2733
- id: settings
2834
# Remove spaces and quotes to get the raw version string
2935
run: sed -r 's/(\s|\")+//g' common.vars.pkr.hcl >> $GITHUB_OUTPUT
36+
- id: base_docker
37+
run: |
38+
if [[ "${{ inputs.baseDockerVersion }}" != "" ]]; then
39+
echo "base-docker-version=${{ inputs.baseDockerVersion }}" >> $GITHUB_OUTPUT
40+
else
41+
echo "base-docker-version=${{ steps.settings.outputs.postgres-version }}" >> $GITHUB_OUTPUT
42+
fi
3043
- id: args
3144
uses: mikefarah/yq@master
3245
with:
@@ -60,7 +73,7 @@ jobs:
6073
file: docker/all-in-one/Dockerfile
6174
push: true
6275
build-args: |
63-
postgres_version=${{ needs.settings.outputs.docker_version }}
76+
postgres_version=${{ needs.settings.outputs.base_docker_version }}
6477
${{ needs.settings.outputs.build_args }}
6578
target: production
6679
tags: ${{ needs.settings.outputs.image_tag }}_${{ matrix.arch }}

.github/workflows/nix-build.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Nix CI
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
id-token: write
12+
13+
jobs:
14+
build-run-image:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- runner: larger-runner-4cpu
20+
arch: amd64
21+
- runner: arm-runner
22+
arch: arm64
23+
runs-on: ${{ matrix.runner }}
24+
25+
steps:
26+
27+
- name: Check out code
28+
uses: actions/checkout@v3
29+
- name: aws-creds
30+
uses: aws-actions/configure-aws-credentials@v4
31+
with:
32+
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
33+
aws-region: "us-east-1"
34+
output-credentials: true
35+
- name: write secret key
36+
# use python so we don't interpolate the secret into the workflow logs, in case of bugs
37+
run: |
38+
python -c "import os; file = open('nix-secret-key', 'w'); file.write(os.environ['NIX_SIGN_SECRET_KEY']); file.close()"
39+
env:
40+
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
41+
42+
- name: Build docker images
43+
run: docker build -t base_nix -f docker/nix/Dockerfile .
44+
- name: Run build psql bundle
45+
run: docker run -e AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} -e AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} -e AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }} base_nix bash -c "./workspace/docker/nix/build.sh"
46+
name: build psql bundle on ${{ matrix.arch }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Nix Cache upload
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
id-token: write
12+
13+
jobs:
14+
build:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- runner: [self-hosted, X64]
20+
arch: amd64
21+
- runner: arm-runner
22+
arch: arm64
23+
runs-on: ${{ matrix.runner }}
24+
name: nix-build
25+
steps:
26+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
27+
with:
28+
fetch-depth: 0
29+
- uses: DeterminateSystems/nix-installer-action@65d7c888b2778e8cf30a07a88422ccb23499bfb8
30+
- uses: DeterminateSystems/magic-nix-cache-action@749fc5bbc9fa49d60c2b93f6c4bc867b82e1d295
31+
- name: configure aws credentials for s3
32+
uses: aws-actions/configure-aws-credentials@v1
33+
with:
34+
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
35+
aws-region: "us-east-1"
36+
kvm: true
37+
extra-conf: |
38+
system-features = kvm
39+
40+
- name: write secret key
41+
# use python so we don't interpolate the secret into the workflow logs, in case of bugs
42+
run: |
43+
python -c "import os; file = open('nix-secret-key', 'w'); file.write(os.environ['NIX_SIGN_SECRET_KEY']); file.close()"
44+
env:
45+
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
46+
47+
- name: build and copy to S3
48+
run: |
49+
for x in 15 16 orioledb_16; do
50+
nix build .#psql_$x/bin -o result-$x
51+
done
52+
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./result*

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ ansible/image-manifest*.json
1010
__pycache__/
1111
*.py[cod]
1212
*$py.class
13+
14+
#nix related
15+
result*
16+
.env-local
17+
.history

Dockerfile

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ ARG pg_repack_release=1.4.8
3131
ARG vault_release=0.2.8
3232
ARG groonga_release=12.0.8
3333
ARG pgroonga_release=2.4.0
34-
ARG wrappers_release=0.2.0
34+
ARG wrappers_release=0.3.0
3535
ARG hypopg_release=1.3.1
3636
ARG pgvector_release=0.4.0
3737
ARG pg_tle_release=1.3.2
38-
ARG supautils_release=2.1.0
38+
ARG index_advisor_release=0.2.0
39+
ARG supautils_release=2.2.0
3940
ARG wal_g_release=2.0.1
4041

4142
####################
@@ -556,7 +557,7 @@ FROM ccache as libsodium
556557
ARG libsodium_release
557558
ARG libsodium_release_checksum
558559
ADD --checksum=${libsodium_release_checksum} \
559-
"https://download.libsodium.org/libsodium/releases/libsodium-${libsodium_release}.tar.gz" \
560+
"https://supabase-public-artifacts-bucket.s3.amazonaws.com/libsodium/libsodium-${libsodium_release}.tar.gz" \
560561
/tmp/libsodium.tar.gz
561562
RUN tar -xvf /tmp/libsodium.tar.gz -C /tmp && \
562563
rm -rf /tmp/libsodium.tar.gz
@@ -803,6 +804,24 @@ RUN --mount=type=cache,target=/ccache,from=public.ecr.aws/supabase/postgres:ccac
803804
# Create debian package
804805
RUN checkinstall -D --install=no --fstrans=no --backup=no --pakdir=/tmp --nodoc
805806

807+
######################
808+
# 30-index_advisor.yml
809+
######################
810+
FROM ccache as index_advisor
811+
ARG index_advisor_release
812+
ARG index_advisor_release_checksum
813+
ADD --checksum=${index_advisor_release_checksum} \
814+
"https://github.com/olirice/index_advisor/archive/refs/tags/v${index_advisor_release}.tar.gz" \
815+
/tmp/index_advisor.tar.gz
816+
RUN tar -xvf /tmp/index_advisor.tar.gz -C /tmp && \
817+
rm -rf /tmp/index_advisor.tar.gz
818+
# Build from source
819+
WORKDIR /tmp/index_advisor-${index_advisor_release}
820+
RUN --mount=type=cache,target=/ccache,from=public.ecr.aws/supabase/postgres:ccache \
821+
make -j$(nproc)
822+
# Create debian package
823+
RUN checkinstall -D --install=no --fstrans=no --backup=no --pakdir=/tmp --nodoc
824+
806825
####################
807826
# internal/supautils.yml
808827
####################
@@ -857,6 +876,7 @@ COPY --from=hypopg-source /tmp/*.deb /tmp/
857876
COPY --from=pg_repack-source /tmp/*.deb /tmp/
858877
COPY --from=pgvector-source /tmp/*.deb /tmp/
859878
COPY --from=pg_tle-source /tmp/*.deb /tmp/
879+
COPY --from=index_advisor /tmp/*.deb /tmp/
860880
COPY --from=supautils /tmp/*.deb /tmp/
861881

862882
####################
@@ -927,6 +947,7 @@ RUN sed -i \
927947

928948
# Include schema migrations
929949
COPY migrations/db /docker-entrypoint-initdb.d/
950+
COPY ansible/files/pgbouncer_config/pgbouncer_auth_schema.sql /docker-entrypoint-initdb.d/init-scripts/00-schema.sql
930951
COPY ansible/files/stat_extension.sql /docker-entrypoint-initdb.d/migrations/00-extension.sql
931952

932953
# Add upstream entrypoint script

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,12 @@ $ time packer build -timestamp-ui \
109109
We are building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves.
110110

111111
[![New Sponsor](https://user-images.githubusercontent.com/10214025/90518111-e74bbb00-e198-11ea-8f88-c9e3c1aa4b5b.png)](https://github.com/sponsors/supabase)
112+
113+
114+
## Experimental Nix Packaging of resources
115+
116+
There is a `/nix` folder in this repo, plus a `flake.nix` and `flake.lock` that facilitate using the Nix package management system to package supabase/postgres, and all of our extensions and wrappers. A user will need nix installed on their machine. As of 4/1/2024 the package set only builds on target machines (`x86_64-linux` and `aarch64-linux`), however work is under way to also support building and using directly on `aarch64-darwin` (macOs). As of 4/1/2024, versions of packages and extensions are synced from `/ansible/vars.yml` via a utility that can be run by executing `nix run .#sync-exts-versions` (you must have nix installed and be on the supported `x86_64-linux` and `aarch64-linux` for this command to work). The short term goal is to sync these versions as they are updated by our infrastructure and postgres teams, then to see the nix packaged versions build successfully in parallel over time, along with tests of the nix packaged versions passing.
117+
118+
The supabase/postgres repo will continue to source it's dependencies from ansible for the short term, while we stabilize this nix build.
119+
120+
Forthcoming PR's will include: integrating the nix work into our ansible/packer builds, building natively on aarch64-darwin (macOs), more testing

ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ EOF
4848

4949
run_sql -c "$PG_NET_GRANT_QUERY"
5050
fi
51+
52+
# Patching pg_cron ownership as it resets during upgrade
53+
HAS_PG_CRON_OWNED_BY_POSTGRES=$(run_sql -A -t -c "select count(*) > 0 from pg_extension where extname = 'pg_cron' and extowner::regrole::text = 'postgres';")
54+
55+
if [ "$HAS_PG_CRON_OWNED_BY_POSTGRES" = "t" ]; then
56+
RECREATE_PG_CRON_QUERY=$(cat <<EOF
57+
begin;
58+
create temporary table cron_job as select * from cron.job;
59+
create temporary table cron_job_run_details as select * from cron.job_run_details;
60+
drop extension pg_cron;
61+
create extension pg_cron schema pg_catalog;
62+
insert into cron.job select * from cron_job;
63+
insert into cron.job_run_details select * from cron_job_run_details;
64+
select setval('cron.jobid_seq', coalesce(max(jobid), 0) + 1, false) from cron.job;
65+
select setval('cron.runid_seq', coalesce(max(runid), 0) + 1, false) from cron.job_run_details;
66+
update cron.job set username = 'postgres' where username = 'supabase_admin';
67+
commit;
68+
EOF
69+
)
70+
71+
run_sql -c "$RECREATE_PG_CRON_QUERY"
72+
fi
5173
}
5274

5375
function complete_pg_upgrade {

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ EOF
306306
echo "11. Copying custom configurations"
307307
mkdir -p "$MOUNT_POINT/conf"
308308
cp -R /etc/postgresql-custom/* "$MOUNT_POINT/conf/"
309+
# removing supautils config as to allow the latest one provided by the latest image to be used
310+
rm -f "$MOUNT_POINT/conf/supautils.conf" || true
309311

310312
# removing wal-g config as to allow it to be explicitly enabled on the new instance
311313
rm -f "$MOUNT_POINT/conf/wal-g.conf"

ansible/files/postgresql_config/supautils.conf.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
supautils.extensions_parameter_overrides = '{"pg_cron":{"schema":"pg_catalog"}}'
2-
# full list: address_standardizer, address_standardizer_data_us, adminpack, amcheck, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, file_fdw, fuzzystrmatch, hstore, http, hypopg, insert_username, intagg, intarray, isn, lo, ltree, moddatetime, old_snapshot, orioledb, pageinspect, pg_buffercache, pg_cron, pg_freespacemap, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_surgery, pg_tle, pg_trgm, pg_visibility, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers, xml2
2+
supautils.policy_grants = '{"postgres":["auth.audit_log_entries","auth.identities","auth.refresh_tokens","auth.sessions","auth.users","realtime.broadcasts","realtime.channels","realtime.presences","storage.buckets","storage.migrations","storage.objects"]}'
3+
# full list: address_standardizer, address_standardizer_data_us, adminpack, amcheck, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, file_fdw, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intagg, intarray, isn, lo, ltree, moddatetime, old_snapshot, orioledb, pageinspect, pg_buffercache, pg_cron, pg_freespacemap, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_surgery, pg_tle, pg_trgm, pg_visibility, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers, xml2
34
# omitted because may be unsafe: adminpack, amcheck, file_fdw, lo, old_snapshot, pageinspect, pg_buffercache, pg_freespacemap, pg_surgery, pg_visibility
45
# omitted because deprecated: intagg, xml2
5-
supautils.privileged_extensions = 'address_standardizer, address_standardizer_data_us, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, fuzzystrmatch, hstore, http, hypopg, insert_username, intarray, isn, ltree, moddatetime, orioledb, pg_cron, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_repack, pg_stat_monitor, pg_stat_statements, pg_tle, pg_trgm, pg_walinspect, pgaudit, pgcrypto, pgjwt, pg_prewarm, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgstattuple, pgsodium, pgtap, plcoffee, pljava, plls, plpgsql, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers'
6+
supautils.privileged_extensions = 'address_standardizer, address_standardizer_data_us, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intarray, isn, ltree, moddatetime, orioledb, pg_cron, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_repack, pg_stat_monitor, pg_stat_statements, pg_tle, pg_trgm, pg_walinspect, pgaudit, pgcrypto, pgjwt, pg_prewarm, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgstattuple, pgsodium, pgtap, plcoffee, pljava, plls, plpgsql, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers'
67
supautils.privileged_extensions_custom_scripts_path = '/etc/postgresql-custom/extension-custom-scripts'
78
supautils.privileged_extensions_superuser = 'supabase_admin'
89
supautils.privileged_role = 'postgres'

0 commit comments

Comments
 (0)