diff --git a/Dockerfile b/Dockerfile index ee9c3d0..5801186 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,2 @@ -FROM postgres:9.6 +FROM postgres:latest COPY create-multiple-postgresql-databases.sh /docker-entrypoint-initdb.d/ diff --git a/README.md b/README.md index d4b6a15..7486925 100644 --- a/README.md +++ b/README.md @@ -20,34 +20,16 @@ mechanism. Clone the repository, mount its directory as a volume into `/docker-entrypoint-initdb.d` and declare database names separated by commas in `POSTGRES_MULTIPLE_DATABASES` environment variable as follows -(`docker-compose` syntax): +(`github actions` syntax): - myapp-postgresql: - image: postgres:9.6.2 + postgres: + image: postgres:12 volumes: - - ../docker-postgresql-multiple-databases:/docker-entrypoint-initdb.d - environment: - - POSTGRES_MULTIPLE_DATABASES: db1,db2 - - POSTGRES_USER: myapp - - POSTGRES_PASSWORD: - -### By building a custom image - -Clone the repository, build and push the image to your Docker repository, -for example for Google Private Repository do the following: - - docker build --tag=eu.gcr.io/your-project/postgres-multi-db . - gcloud docker -- push eu.gcr.io/your-project/postgres-multi-db - -You still need to pass the `POSTGRES_MULTIPLE_DATABASES` environment variable -to the container: - - myapp-postgresql: - image: eu.gcr.io/your-project/postgres-multi-db - environment: - - POSTGRES_MULTIPLE_DATABASES: db1,db2 - - POSTGRES_USER: myapp - - POSTGRES_PASSWORD: + - docker-postgresql-multiple-databases:/docker-entrypoint-initdb.d + env: + POSTGRES_MULTIPLE_DATABASES: db1,db2 + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres ### Non-standard database names diff --git a/create-multiple-postgresql-databases.sh b/create-multiple-postgresql-databases.sh index aa665fa..7aa5abc 100755 --- a/create-multiple-postgresql-databases.sh +++ b/create-multiple-postgresql-databases.sh @@ -5,11 +5,10 @@ set -u function create_user_and_database() { local database=$1 - echo " Creating user and database '$database'" + echo " Creating database '$database'" psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL - CREATE USER $database; CREATE DATABASE $database; - GRANT ALL PRIVILEGES ON DATABASE $database TO $database; + GRANT ALL PRIVILEGES ON DATABASE $database TO $POSTGRES_USER; EOSQL }