moved db check to docker compose file
This commit is contained in:
parent
3c1681caa8
commit
2a36ce3ece
|
@ -15,13 +15,21 @@ services:
|
||||||
- DEMO_IDHUB_PREDEFINED_TOKEN=${IDHUB_PREDEFINED_TOKEN:-}
|
- DEMO_IDHUB_PREDEFINED_TOKEN=${IDHUB_PREDEFINED_TOKEN:-}
|
||||||
- PREDEFINED_TOKEN=${PREDEFINED_TOKEN:-}
|
- PREDEFINED_TOKEN=${PREDEFINED_TOKEN:-}
|
||||||
- DPP=${DPP:-false}
|
- DPP=${DPP:-false}
|
||||||
|
- DB_PORT=${DB_PORT:-5432}
|
||||||
|
- DB_HOST=${DB_HOST:-devicehub-postgres}
|
||||||
|
- DB_NAME=${DB_NAME}
|
||||||
|
- DB_USER=${DB_USER}
|
||||||
|
- DB_PASSWORD=${DB_PASSWORD}
|
||||||
# TODO manage volumes dev vs prod
|
# TODO manage volumes dev vs prod
|
||||||
volumes:
|
volumes:
|
||||||
- .:/opt/devicehub-django
|
- .:/opt/devicehub-django
|
||||||
ports:
|
ports:
|
||||||
- ${DEVICEHUB_PORT:-8000}:${DEVICEHUB_PORT:-8000}
|
- ${DEVICEHUB_PORT:-8000}:${DEVICEHUB_PORT:-8000}
|
||||||
|
#https://docs.docker.com/compose/how-tos/startup-order/
|
||||||
depends_on:
|
depends_on:
|
||||||
- devicehub-postgres
|
devicehub-postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
restart: true
|
||||||
|
|
||||||
devicehub-postgres:
|
devicehub-postgres:
|
||||||
image: postgres:17
|
image: postgres:17
|
||||||
|
@ -31,6 +39,13 @@ services:
|
||||||
- POSTGRES_PASSWORD=${DB_PASSWORD}
|
- POSTGRES_PASSWORD=${DB_PASSWORD}
|
||||||
volumes:
|
volumes:
|
||||||
- pg_data:/var/lib/postgresql/data
|
- pg_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
# https://docs.docker.com/compose/how-tos/startup-order/
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
|
||||||
|
start_period: 1s
|
||||||
|
interval: 1s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 10
|
||||||
#ports:
|
#ports:
|
||||||
# - ${DB_PORT}:${DB_PORT}
|
# - ${DB_PORT}:${DB_PORT}
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,6 @@ set -u
|
||||||
# DEBUG
|
# DEBUG
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
program_dir='/opt/devicehub-django'
|
|
||||||
#source .env
|
|
||||||
. "${program_dir}/.env"
|
|
||||||
|
|
||||||
wait_for_postgres() {
|
|
||||||
# thanks https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
|
|
||||||
while ! nc -z "$DB_HOST" "$DB_PORT" ; do
|
|
||||||
sleep 0.5
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# TODO there is a conflict between two shared vars
|
# TODO there is a conflict between two shared vars
|
||||||
# 1. from the original docker compose devicehub-teal
|
# 1. from the original docker compose devicehub-teal
|
||||||
# 2. from the new docker compose that integrates all dpp services
|
# 2. from the new docker compose that integrates all dpp services
|
||||||
|
@ -46,12 +34,6 @@ gen_env_vars() {
|
||||||
ADMIN='True'
|
ADMIN='True'
|
||||||
PREDEFINED_TOKEN="${PREDEFINED_TOKEN:-}"
|
PREDEFINED_TOKEN="${PREDEFINED_TOKEN:-}"
|
||||||
|
|
||||||
DB_NAME="${DB_NAME:-devicehub}"
|
|
||||||
DB_USER="${DB_USER:-ereuse}"
|
|
||||||
DB_PASSWORD="${DB_PASSWORD:-ereuse}"
|
|
||||||
DB_HOST="${DB_HOST:-localhost}"
|
|
||||||
DB_PORT="${DB_PORT:-5432}"
|
|
||||||
|
|
||||||
# specific dpp env vars
|
# specific dpp env vars
|
||||||
if [ "${DPP:-}" = 'true' ]; then
|
if [ "${DPP:-}" = 'true' ]; then
|
||||||
# fill env vars in this docker entrypoint
|
# fill env vars in this docker entrypoint
|
||||||
|
@ -260,9 +242,10 @@ runserver() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
|
||||||
|
program_dir='/opt/devicehub-django'
|
||||||
cd "${program_dir}"
|
cd "${program_dir}"
|
||||||
gen_env_vars
|
gen_env_vars
|
||||||
wait_for_postgres
|
|
||||||
deploy
|
deploy
|
||||||
runserver
|
runserver
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue