Skip to content

Commit

Permalink
[Issue 617] Rename app and db in docker-compose (#622)
Browse files Browse the repository at this point in the history
[Issue-617] Rename app and db in docker-compose
  • Loading branch information
chouinar authored Oct 31, 2023
1 parent b877679 commit 5ffe55b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Constants
##################################################

APP_NAME := main-api
APP_NAME := grants-api

# Adding this to the end of a script that outputs JSON will convert
# it to a readable format with timestamps and color-coding.
Expand Down Expand Up @@ -118,7 +118,7 @@ check: format-check lint test
init-db: start-db db-migrate

start-db:
docker-compose up --detach main-db
docker-compose up --detach grants-db
./bin/wait-for-local-db.sh

## Destroy current DB, setup new one
Expand Down
6 changes: 3 additions & 3 deletions api/bin/wait-for-local-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ WAIT_TIME=0
# Use pg_isready to wait for the DB to be ready to accept connections
# We check every 3 seconds and consider it failed if it gets to 30+
# https://www.postgresql.org/docs/current/app-pg-isready.html
until pg_isready -h localhost -d main-db -q;
until pg_isready -h localhost -d grants-db -q;
do
echo "waiting on Postgres DB to initialize..."
sleep 3

WAIT_TIME=$(($WAIT_TIME+3))
if [ $WAIT_TIME -gt $MAX_WAIT_TIME ]
then
echo -e "${RED}ERROR: Database appears to not be starting up, running \"docker logs main-db\" to troubleshoot.${NO_COLOR}"
docker logs main-db
echo -e "${RED}ERROR: Database appears to not be starting up, running \"docker logs grants-db\" to troubleshoot.${NO_COLOR}"
docker logs grants-db
exit 1
fi
done
Expand Down
2 changes: 1 addition & 1 deletion api/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ POSTGRES_USER=app
POSTGRES_PASSWORD=secret123

# Set DB_HOST to localhost if accessing a non-dockerized database
DB_HOST=main-db
DB_HOST=grants-db
DB_NAME=app
DB_USER=app
DB_SCHEMA=public
Expand Down
14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ version: '3'

services:

main-db:
grants-db:
image: postgres:14-alpine
container_name: main-db
container_name: grants-db
command: postgres -c "log_lock_waits=on" -N 1000 -c "fsync=off"
env_file: ./api/local.env
ports:
- "5432:5432"
volumes:
- dbdata:/var/lib/postgresql/data
- grantsdbdata:/var/lib/postgresql/data

main-api:
grants-api:
build:
context: ./api
target: dev
args:
- RUN_UID=${RUN_UID:-4000}
- RUN_USER=${RUN_USER:-api}
command: ["poetry", "run", "flask", "--app", "src.app", "run", "--host", "0.0.0.0", "--port", "8080", "--reload"]
container_name: main-api
container_name: grants-api
env_file: ./api/local.env
ports:
- 8080:8080
volumes:
- ./api:/api
depends_on:
- main-db
- grants-db

nextjs:
container_name: next-dev
Expand Down Expand Up @@ -62,4 +62,4 @@ services:
- 6006:6006

volumes:
dbdata:
grantsdbdata:

0 comments on commit 5ffe55b

Please sign in to comment.