Skip to content

Latest commit

 

History

History
68 lines (59 loc) · 2.21 KB

File metadata and controls

68 lines (59 loc) · 2.21 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:13-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)

Produces

  • embedded.postgresql.port

  • embedded.postgresql.host

  • embedded.postgresql.schema

  • embedded.postgresql.user

  • embedded.postgresql.password

Example (Spring Boot)

bootstrap-test.yml

embedded:
  postgresql:
    enabled: true
    docker-image: 'bitnami/postgresql:13.3.0'
    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}