Init container to create a Postgres database
Given a Postgres connection string, values.properties and one of the two files .pgenv or .pgpass
When the container runs with the two files mounted
Then a database is created as configured by the values.properties
postgres-init-container takes a optional command followed by the require postgresql URI.
The optional command is up to create the database and its supporting roles, and down to destroy database and roles.
See compose.yaml for examples.
A property file, it contains un-escaped values to define the database to be created.
Keys and values are separated with a =. Comment lines, starting with a #, are ignored.
| Property | Required | Description |
|---|---|---|
| database_name | yes | Name of the database |
| database_owner | yes | Name of the database owner |
| database_owner_password | yes | Password for the database owner |
| connection_limit | no | Initial connection count limit, defaults to 100 |
| extensions | no | Comma-separated names of Postgres extensions to create; pg_trgm and btree_gin are always included |
Mount the file at /home/values.properties.
A property file, it contains un-escaped values for the master user name and password.
entrypoint.sh will generate a correct .pgpass at run time.
Keys and values are separated with a =. Comment lines, starting with a #, are ignored.
| Property | Required | Description |
|---|---|---|
| PGUSER | yes | Name of the master user |
| PGPASSWORD | yes | Password for the master user |
Mount the file at /home/.pgenv.
A standard postgres password file, it needs only specify the master user and master user password and can use wildcard for the host, port and database. Note thay it must apply the escaping rules.
Mount the file at /home/.pgpass.
docker buildx build src/main/docker --tag arda-cards/postgres-database-initializerAlternative:
make builddocker compose -f src/test/docker/compose.yaml up --renew-anon-volumesAlternative:
make testThis will build the image if not present.
Then inspect the log.
The script tests.sh runs all the integration tests.
The clean build command is
docker system prune --volumes --force; ./tests.shThe command purges the local docker installation from any temporary images, volumes, ...
docker run postgres-database-docker run -it --entrypoint bash postgres:16docker system prune --volumes
docker rmi arda-cards/postgres-database-initializer