Skip to content

Latest commit

 

History

History
75 lines (65 loc) · 2.58 KB

File metadata and controls

75 lines (65 loc) · 2.58 KB

embedded-postgresql

Maven dependency

pom.xml
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-postgresql</artifactId>
    <scope>test</scope>
</dependency>

Consumes (via bootstrap.properties)

  • embedded.postgresql.enabled (true|false, default is true)

  • embedded.postgresql.reuseContainer (true|false, default is false)

  • embedded.postgresql.dockerImage (default is 'postgres:17-alpine')

  • embedded.postgresql.waitTimeoutInSeconds (default is 60 seconds)

  • embedded.postgresql.database

  • embedded.postgresql.user

  • embedded.postgresql.password

  • embedded.postgresql.initScriptPath (default is null)

  • embedded.postgresql.startupLogCheckRegex (default is null)

  • embedded.postgresql.mountVolumes (default is empty list)

  • embedded.toxiproxy.proxies.postgresql.enabled Enables both creation of the container with ToxiProxy TCP proxy and a proxy to the embedded-postgresql container.

Produces

  • embedded.postgresql.port

  • embedded.postgresql.host

  • embedded.postgresql.schema

  • embedded.postgresql.user

  • embedded.postgresql.password

  • embedded.postgresql.toxiproxy.host

  • embedded.postgresql.toxiproxy.port

  • embedded.postgresql.networkAlias

  • embedded.postgresql.internalPort

  • Bean ToxiproxyContainer.ContainerProxy postgresqlContainerProxy

Example (Spring Boot)

bootstrap-test.yml

embedded:
  postgresql:
    enabled: true
    docker-image: 'postgres:16-alpine'
    wait-timeout-in-seconds: 40
    command: '/opt/bitnami/scripts/postgresql/run.sh'
    startupLogCheckRegex: '.*database system is ready to accept connections.*'
    mountVolumes:
      -
        hostPath: 'pgdata'  # local directory to store database files
        containerPath: '/bitnami/postgresql'  # /var/lib/postgresql/data for https://hub.docker.com/_/postgres
        mode: READ_WRITE  # persist data locally between container restarts
      -
        hostPath: 'src/main/resources/my-postgresql.conf'  # local file
        containerPath: '/bitnami/postgresql/conf/postgresql.conf' # /etc/postgresql/postgresql.conf for https://hub.docker.com/_/postgres
        mode: READ_ONLY  # prevent container from changing file contents (default)

application-test.yml

spring:
  datasource:
    url: "jdbc:postgresql://${embedded.postgresql.host}:${embedded.postgresql.port}/${embedded.postgresql.schema}"
    username: ${embedded.postgresql.user}
    password: ${embedded.postgresql.password}