Skip to content

Commit ca07e63

Browse files
samroseencima
andauthored
pg bouncer upgrade (#1572)
* feat: upgrade pgbouncer * feat: remove pgbouncer from vars.yml * chore: fix missing flag * feat: restore build-essential dep, but in nginx * chore: cleanup commit * switch nix profile install to add * add pgbouncer to flake * remove pgbouncer tests to confirm build * tested locally. update vars for testing pgbouncer in staging * update pgbouncer to 1.25.1 * update ansible vars * add pandoc to build reqs * chore: add build deps to ansible task for bouncer * chore: fmt pgbouncer file --------- Co-authored-by: Chris Gwilliams <517923+encima@users.noreply.github.com>
1 parent 02f3d83 commit ca07e63

6 files changed

Lines changed: 89 additions & 4 deletions

File tree

ansible/playbook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
tags:
3535
- install-pgbouncer
3636
- install-supabase-internal
37-
when: debpkg_mode or nixpkg_mode
37+
when: debpkg_mode or nixpkg_mode or stage2_nix
3838

3939
- name: Install WAL-G
4040
import_tasks: tasks/setup-wal-g.yml

ansible/tasks/setup-pgbouncer.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- libssl-dev
88
- libsystemd-dev
99
- pkg-config
10+
- pandoc
11+
- python3
1012
update_cache: true
1113

1214
- name: PgBouncer - download latest release
@@ -75,6 +77,7 @@
7577
- 'custom-overrides.ini'
7678
- 'generated-optimizations.ini'
7779
- 'ssl-config.ini'
80+
when: nixpkg_mode
7881

7982
- name: PgBouncer - adjust pgbouncer.ini
8083
ansible.builtin.copy:

ansible/vars.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ postgres_release:
1515
postgres15: "15.14.1.072"
1616

1717
# Non Postgres Extensions
18-
pgbouncer_release: 1.19.0
19-
pgbouncer_release_checksum: sha256:af0b05e97d0e1fd9ad45fe00ea6d2a934c63075f67f7e2ccef2ca59e3d8ce682
18+
pgbouncer_release: 1.25.1
19+
pgbouncer_release_checksum: sha256:6e566ae92fe3ef7f6a1b9e26d6049f7d7ca39c40e29e7b38f6d5500ae15d8465
2020

2121
# The checksum can be found under "Assets", in the GitHub release page for each version.
2222
# The binaries used are: ubuntu-aarch64 and linux-static.

nix/packages/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
cleanup-ami = pkgs.callPackage ./cleanup-ami.nix { };
3939
dbmate-tool = pkgs.callPackage ./dbmate-tool.nix { inherit (self.supabase) defaults; };
4040
docs = pkgs.callPackage ./docs.nix { };
41+
pgbouncer = pkgs.callPackage ../pgbouncer.nix { };
4142
github-matrix = pkgs.callPackage ./github-matrix {
4243
nix-eval-jobs = inputs'.nix-eval-jobs.packages.default;
4344
};

nix/pgbouncer.nix

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchurl,
5+
openssl,
6+
libevent,
7+
c-ares,
8+
pkg-config,
9+
systemd,
10+
nixosTests,
11+
pandoc,
12+
python3,
13+
}:
14+
15+
stdenv.mkDerivation rec {
16+
pname = "pgbouncer";
17+
version = "1.25.1";
18+
19+
src = fetchurl {
20+
url = "https://www.pgbouncer.org/downloads/files/${version}/${pname}-${version}.tar.gz";
21+
hash = "sha256-blZq6S/j739qG54m1gSffXyjnEDinns49tVQCuFdhGU=";
22+
};
23+
24+
nativeBuildInputs = [
25+
pkg-config
26+
pandoc
27+
python3
28+
];
29+
buildInputs = [
30+
libevent
31+
openssl
32+
c-ares
33+
]
34+
++ lib.optional stdenv.hostPlatform.isLinux systemd;
35+
enableParallelBuilding = true;
36+
configureFlags = lib.optional stdenv.hostPlatform.isLinux "--with-systemd";
37+
38+
passthru.tests = {
39+
pgbouncer = nixosTests.pgbouncer;
40+
};
41+
42+
meta = with lib; {
43+
homepage = "https://www.pgbouncer.org/";
44+
mainProgram = "pgbouncer";
45+
description = "Lightweight connection pooler for PostgreSQL";
46+
changelog = "https://github.com/pgbouncer/pgbouncer/releases/tag/pgbouncer_${
47+
replaceStrings [ "." ] [ "_" ] version
48+
}";
49+
license = licenses.isc;
50+
maintainers = with maintainers; [ _1000101 ];
51+
platforms = platforms.all;
52+
};
53+
}

testinfra/test_ami_nix.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,34 @@
145145
anon_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFhYWFhYWFhYWFhYWFhYWFhYWFhIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTYyMjQ5NjYsImV4cCI6MjAxMTgwMDk2Nn0.QW95aRPA-4QuLzuvaIeeoFKlJP9J2hvAIpJ3WJ6G5zo"
146146
service_role_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFhYWFhYWFhYWFhYWFhYWFhYWFhIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTY5NjIyNDk2NiwiZXhwIjoyMDExODAwOTY2fQ.Om7yqv15gC3mLGitBmvFRB3M4IsLsX9fXzTQnFM7lu0"
147147
supabase_admin_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFhYWFhYWFhYWFhYWFhYWFhYWFhIiwicm9sZSI6InN1cGFiYXNlX2FkbWluIiwiaWF0IjoxNjk2MjI0OTY2LCJleHAiOjIwMTE4MDA5NjZ9.jrD3j2rBWiIx0vhVZzd1CXFv7qkAP392nBMadvXxk1c"
148+
149+
150+
def load_expected_pgbouncer_version() -> str:
151+
repo_root = Path(__file__).resolve().parent.parent
152+
ansible_vars = repo_root / "ansible" / "vars.yml"
153+
if ansible_vars.exists():
154+
with ansible_vars.open() as f:
155+
for raw_line in f:
156+
line = raw_line.strip()
157+
if line.startswith("pgbouncer_release:"):
158+
return line.split(":", 1)[1].strip().strip('"')
159+
160+
nix_file = repo_root / "nix" / "pgbouncer.nix"
161+
if nix_file.exists():
162+
with nix_file.open() as f:
163+
for raw_line in f:
164+
line = raw_line.strip()
165+
if line.startswith("version ="):
166+
value = line.split("=", 1)[1].strip()
167+
return value.strip(";").strip('"')
168+
169+
raise RuntimeError(
170+
"Could not determine expected PgBouncer version from configuration files"
171+
)
172+
173+
174+
EXPECTED_PGBOUNCER_VERSION = load_expected_pgbouncer_version()
175+
PGBOUNCER_BINARY = "/nix/var/nix/profiles/per-user/pgbouncer/profile/bin/pgbouncer"
148176
init_json_content = f"""
149177
{{
150178
"jwt_secret": "my_jwt_secret_which_is_not_so_secret",
@@ -200,7 +228,7 @@ def get_ssh_connection(instance_ip, ssh_identity_file, max_retries=10):
200228
else:
201229
raise Exception("SSH test command failed")
202230

203-
except Exception as e:
231+
except Exception:
204232
if attempt == max_retries - 1:
205233
raise
206234
logger.warning(

0 commit comments

Comments
 (0)