Skip to content

Commit

Permalink
feat: Init pg bouncer/cron locally and in test
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Apr 2, 2024
1 parent f09776d commit 03ee9a1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion postgres.Dockerfile → postgres/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions init-scripts/postgres/init.sql → postgres/init.sql
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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;
2 changes: 1 addition & 1 deletion runner/tests/testcontainers/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class PostgreSqlContainer {
}

public static async build (): Promise<PostgreSqlContainer> {
const container = await GenericContainer.fromDockerfile('../', 'postgres.Dockerfile').build();
const container = await GenericContainer.fromDockerfile('../postgres').build();

return new PostgreSqlContainer(container);
}
Expand Down

0 comments on commit 03ee9a1

Please sign in to comment.