Copy the .sample.env file into a new .env file,
cp .sample.env .env
The .env file configures environment variables necessary for this project to work. For more information on the pgadmin environment variables, see here. For more information on the postgres environment variables, see here
In order for the application cluster to work, you will need to adjust POSTGRES_HOST (for containers, the host should be set equal to the name of the database service defined in the docker-compose.yml), POSTGRES_USER, POSTGRES_PASSWORD, PGADMIN_DEFAULT_USER, PGADMIN_DEFAULT_EMAIL and for each application whose database server you want to be able to see in pgadmin, you will need to adjust _DB_NAME (name of database), _DB_USER (user with permissions to access database) and _DB_PASSWORD (the password for the user just defined) variables. You can create more application database connections by adding them to the .env file and then adding those environment variables to the arrays defined in the BASH entrypoint script entrypoint.sh. Specifically, add your newly created database variables to lines 7 - 9,
dbs=($CCDA_DB_NAME $SOLUTIONID_DB_NAME $CALC_DB_NAME)
users=($CCDA_DB_USER $SOLUTIONID_DB_USER $CALC_DB_USER)
passwords=($CCDA_DB_PASSWORD $SOLUTIONID_DB_PASSWORD $CALC_DB_PASSWORD)
To start the application, from the project root execute,
docker-compose up -d
A pgadmin server will then be available at localhost:5050. You will need to login with the credentials defined in the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD. The databases defined by the (_DB_NAME, _DB_USER, _DB_PASSWORD)-tuples will be populated in the pgadmin server list during initialization and should be available when you log in. The server group with the database connections is only initialized when the configuration databases for postgres and pgadmin are first created. If a deployment doesn't finish initializing or gets interrupted, you may not see the server group when you log in. If you do not, you will need to take down the application cluster and remove the volumes associated with it so the application cluster can be deployed within a fresh environment.
Along those lines, if you can't login with the username/password combo defined in the .env file, then you may need to delete the pgadmin volume and recreate it. See the following stack for more information
IMPORTANT! Due to the way MCaaS is setup, the database creation script has to be run after the pod is healthy. The script init-dbs needs to be executed inside of the pgadmin container after the pod launches to initialize the databases within the postgres server. Remember, we do not have access to the postgres service, so all database initialize has to be done with in the pgadmin container.
To create the databases after the container is spun up, start a shell session inside of the container and execute the necessary script,
docker exec -it dx-pgadmin_pgadmin_1 bash
/init-dbs.sh
On the MCaaS environment, the admins will need to manually exec into the pod to execute this script. This process must be done everytime a database is initialized in a new environment.
If you need to launch the application fresh, i.e. recreate the pgadmin and postgres configuration databases, recreate databases, etc, then you need to make sure you wipe the Docker volumes mounted through the docker-compose.yml; docker-compose down is not sufficient. You can use the /scripts/detonate.sh to purge your local Docker of all traces of this application. After invoking the script, the next docker-compose up will recreate the images, volumes and network.
This is especially important if you happen to change the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD, as the retained volumes will persist the old values of these environment variables until the volume is pruned.
- Postgres Environment Variables
- PGPASSFILE
- How to use PGPASSFILE
- Pass SQL Scripts Parameters from Command Line
- Pass Dynamic Variables to PSQL
- Create Database With User And Password
- Create Postgres DB if None Exists
- Postgres Syntax Error At Or Near IF
- Postgres If Statement
- PGAdmin4 Docker Repo
- PGAdmin4 Container Git Repo
- PGAdmin Container Deployment
- Provisioning PGAdmin Container With Connections and Passwords
- PGAdmin4 Import/Export Servers
- PGAdmin Helm Chart Example
- pg_restore file not found
- Preferences