Skip to content

Arda-cards/postgres-database-initializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postgres-database-initializer

version semantic versioning ci

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

Command line argument

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.

values.properties

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.

.pgenv

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.

.pgpass

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.

How to build

docker buildx build src/main/docker --tag arda-cards/postgres-database-initializer

Alternative:

make build

How to test

docker compose -f src/test/docker/compose.yaml up --renew-anon-volumes

Alternative:

make test

This 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.sh

The command purges the local docker installation from any temporary images, volumes, ...

How to use

docker run postgres-database-

Debug the image

docker run -it --entrypoint bash postgres:16

Cleanup

docker system prune --volumes
docker rmi arda-cards/postgres-database-initializer

About

Init container to create a Postgres database

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors