From 07ba67ce41a38767517ad1bb50bf4687553069fc Mon Sep 17 00:00:00 2001 From: trivialkettle <126059809+trivialkettle@users.noreply.github.com> Date: Wed, 19 Jun 2024 14:45:08 +0200 Subject: [PATCH] Simplify postgres setup If POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DB are set, the postgres container automatically creates the database and role with the set name and password. --- ...irpstack_extensions.sh => 001-chirpstack_extensions.sh} | 2 +- configuration/postgresql/initdb/001-init-chirpstack.sh | 7 ------- docker-compose.yml | 4 +++- 3 files changed, 4 insertions(+), 9 deletions(-) rename configuration/postgresql/initdb/{002-chirpstack_extensions.sh => 001-chirpstack_extensions.sh} (50%) delete mode 100755 configuration/postgresql/initdb/001-init-chirpstack.sh diff --git a/configuration/postgresql/initdb/002-chirpstack_extensions.sh b/configuration/postgresql/initdb/001-chirpstack_extensions.sh similarity index 50% rename from configuration/postgresql/initdb/002-chirpstack_extensions.sh rename to configuration/postgresql/initdb/001-chirpstack_extensions.sh index 67ef172e..4028a2db 100755 --- a/configuration/postgresql/initdb/002-chirpstack_extensions.sh +++ b/configuration/postgresql/initdb/001-chirpstack_extensions.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname="chirpstack" <<-EOSQL +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname="$POSTGRES_DB" <<-EOSQL create extension pg_trgm; create extension hstore; EOSQL diff --git a/configuration/postgresql/initdb/001-init-chirpstack.sh b/configuration/postgresql/initdb/001-init-chirpstack.sh deleted file mode 100755 index 602f77f4..00000000 --- a/configuration/postgresql/initdb/001-init-chirpstack.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -e - -psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL - create role chirpstack with login password 'chirpstack'; - create database chirpstack with owner chirpstack; -EOSQL diff --git a/docker-compose.yml b/docker-compose.yml index 49035a28..6cfc0472 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -60,7 +60,9 @@ services: - ./configuration/postgresql/initdb:/docker-entrypoint-initdb.d - postgresqldata:/var/lib/postgresql/data environment: - - POSTGRES_PASSWORD=root + - POSTGRES_USER=chirpstack + - POSTGRES_PASSWORD=chirpstack + - POSTGRES_DB=chirpstack redis: image: redis:7-alpine