diff --git a/postgres.Dockerfile b/postgres.Dockerfile new file mode 100644 index 000000000..81851c84d --- /dev/null +++ b/postgres.Dockerfile @@ -0,0 +1,11 @@ +FROM postgres:14 + +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 + +EXPOSE 5432 + +CMD ["postgres"] diff --git a/runner/tests/integration.test.ts b/runner/tests/integration.test.ts index b07090ac9..0342827e2 100644 --- a/runner/tests/integration.test.ts +++ b/runner/tests/integration.test.ts @@ -13,7 +13,7 @@ import { PostgreSqlContainer, type StartedPostgreSqlContainer } from './testcont import block1 from './blocks/00115185108/streamer_message.json'; describe('Indexer integration', () => { - jest.setTimeout(600000); + jest.setTimeout(300_000); let network: StartedNetwork; let postgresContainer: StartedPostgreSqlContainer; @@ -21,7 +21,7 @@ describe('Indexer integration', () => { beforeAll(async () => { network = await new Network().start(); - postgresContainer = await new PostgreSqlContainer() + postgresContainer = await (await PostgreSqlContainer.build()) .withNetwork(network) .start(); hasuraContainer = await (await HasuraGraphQLContainer.build()) @@ -54,7 +54,16 @@ describe('Indexer integration', () => { database: postgresContainer.getDatabase(), }); - const provisioner = new Provisioner(hasuraClient, pgClient, pgClient); + const provisioner = new Provisioner( + hasuraClient, + pgClient, + pgClient, + { + cronDatabase: postgresContainer.getDatabase(), + postgresHost: postgresContainer.getIpAddress(), + postgresPort: Number(postgresContainer.getPort()), + } + ); const indexer = new Indexer( { diff --git a/runner/tests/testcontainers/postgres.ts b/runner/tests/testcontainers/postgres.ts index 635ccda97..658989dea 100644 --- a/runner/tests/testcontainers/postgres.ts +++ b/runner/tests/testcontainers/postgres.ts @@ -1,23 +1,32 @@ -import { AbstractStartedContainer, GenericContainer, type StartedTestContainer, Wait } from 'testcontainers'; +import { AbstractStartedContainer, GenericContainer, type StartedTestContainer, Wait, type StartedNetwork } from 'testcontainers'; import { logConsumer } from './utils'; -export class PostgreSqlContainer extends GenericContainer { - private database = 'test'; - private username = 'test'; - private password = 'test'; +export class PostgreSqlContainer { + private database = 'postgres'; + private username = 'postgres'; + private password = 'postgres'; private readonly PORT = 5432; - constructor (image = 'postgres:14') { - super(image); - - this.withExposedPorts(this.PORT) + private constructor (private readonly container: GenericContainer) { + container.withExposedPorts(this.PORT) .withWaitStrategy(Wait.forLogMessage(/.*database system is ready to accept connections.*/, 2)) .withLogConsumer(logConsumer) .withStartupTimeout(120_000); } + public static async build (): Promise { + const container = await GenericContainer.fromDockerfile('../', 'postgres.Dockerfile').build(); + + return new PostgreSqlContainer(container); + } + + public withNetwork (network: StartedNetwork): this { + this.container.withNetwork(network); + return this; + } + public withDatabase (database: string): this { this.database = database; return this; @@ -33,13 +42,13 @@ export class PostgreSqlContainer extends GenericContainer { return this; } - public override async start (): Promise { - this.withEnvironment({ + public async start (): Promise { + this.container.withEnvironment({ POSTGRES_DB: this.database, POSTGRES_USER: this.username, POSTGRES_PASSWORD: this.password, }); - return new StartedPostgreSqlContainer(await super.start(), this.database, this.username, this.password, this.PORT); + return new StartedPostgreSqlContainer(await this.container.start(), this.database, this.username, this.password, this.PORT); } }