From 03ee9a1d669aecbd75a3329a7361c7d4aa1db6b6 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Wed, 3 Apr 2024 10:19:30 +1300 Subject: [PATCH] feat: Init pg bouncer/cron locally and in test --- docker-compose.yml | 4 ++-- postgres.Dockerfile => postgres/Dockerfile | 2 +- {init-scripts/postgres => postgres}/init.sql | 4 ++++ runner/tests/testcontainers/postgres.ts | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) rename postgres.Dockerfile => postgres/Dockerfile (71%) rename {init-scripts/postgres => postgres}/init.sql (90%) diff --git a/docker-compose.yml b/docker-compose.yml index 6c78d3cd5..a609209c4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -79,10 +79,10 @@ services: - "6379:6379" postgres: - image: postgres:14 + build: + context: ./postgres restart: always volumes: - - ./init-scripts/postgres:/docker-entrypoint-initdb.d - postgres:/var/lib/postgresql/data environment: POSTGRES_PASSWORD: postgrespassword diff --git a/postgres.Dockerfile b/postgres/Dockerfile similarity index 71% rename from postgres.Dockerfile rename to postgres/Dockerfile index 81851c84d..07796e6c3 100644 --- a/postgres.Dockerfile +++ b/postgres/Dockerfile @@ -4,7 +4,7 @@ RUN apt-get update && apt-get install -y postgresql-14-cron RUN echo "shared_preload_libraries = 'pg_cron'" >> /usr/share/postgresql/postgresql.conf.sample -RUN echo "CREATE EXTENSION pg_cron;" > /docker-entrypoint-initdb.d/init-pg-cron.sql +COPY ./init.sql /docker-entrypoint-initdb.d/ EXPOSE 5432 diff --git a/init-scripts/postgres/init.sql b/postgres/init.sql similarity index 90% rename from init-scripts/postgres/init.sql rename to postgres/init.sql index ffc461d02..6d1101992 100644 --- a/init-scripts/postgres/init.sql +++ b/postgres/init.sql @@ -1,3 +1,4 @@ +-- pgbouncer CREATE ROLE pgbouncer LOGIN; ALTER ROLE pgbouncer WITH PASSWORD 'pgbouncer'; CREATE OR REPLACE FUNCTION public.user_lookup(in i_username text, out uname text, out phash text) @@ -10,3 +11,6 @@ END; $$ LANGUAGE plpgsql SECURITY DEFINER; REVOKE ALL ON FUNCTION public.user_lookup(text) FROM public; GRANT EXECUTE ON FUNCTION public.user_lookup(text) TO pgbouncer; + +-- pg_cron +CREATE EXTENSION pg_cron; diff --git a/runner/tests/testcontainers/postgres.ts b/runner/tests/testcontainers/postgres.ts index 658989dea..c36a88d79 100644 --- a/runner/tests/testcontainers/postgres.ts +++ b/runner/tests/testcontainers/postgres.ts @@ -17,7 +17,7 @@ export class PostgreSqlContainer { } public static async build (): Promise { - const container = await GenericContainer.fromDockerfile('../', 'postgres.Dockerfile').build(); + const container = await GenericContainer.fromDockerfile('../postgres').build(); return new PostgreSqlContainer(container); }