Skip to content

Commit

Permalink
feat(db-checker): Extension of "db reachable"
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Jan 26, 2025
1 parent b9fa253 commit ac089d0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ services:
source: ./docker/extra_settings
target: /app/docker/extra_settings
postgres:
image: postgres:17.2-alpine@sha256:0bcc5bbbb2aa9c9b4c6505845918c7eb55d783cf5c1f434fac33012579fb149d
image: postgres:11-alpine
# image: postgres:17.2-alpine@sha256:0bcc5bbbb2aa9c9b4c6505845918c7eb55d783cf5c1f434fac33012579fb149d
environment:
POSTGRES_DB: ${DD_DATABASE_NAME:-defectdojo}
POSTGRES_USER: ${DD_DATABASE_USER:-defectdojo}
Expand Down
1 change: 1 addition & 0 deletions docker/entrypoint-celery-beat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -e # needed to handle "exit" correctly

. /secret-file-loader.sh
. /reach_database.sh

umask 0002
Expand Down
3 changes: 3 additions & 0 deletions docker/entrypoint-uwsgi-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
set -e # needed to handle "exit" correctly

. /secret-file-loader.sh
. /reach_database.sh

wait_for_database_to_be_reachable
echo

cd /app || exit

Expand Down
4 changes: 4 additions & 0 deletions docker/entrypoint-uwsgi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e # needed to handle "exit" correctly

. /secret-file-loader.sh
. /reach_database.sh

# Allow for bind-mount multiple settings.py overrides
FILES=$(ls /app/docker/extra_settings/* 2>/dev/null || true)
Expand All @@ -17,6 +18,9 @@ if [ "$NUM_FILES" -gt 0 ]; then
rm -f /app/dojo/settings/README.md
fi

wait_for_database_to_be_reachable
echo

umask 0002

# do the check with Django stack
Expand Down
19 changes: 13 additions & 6 deletions docker/reach_database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ wait_for_database_to_be_reachable() {
DD_DATABASE_READINESS_TIMEOUT=${DD_DATABASE_READINESS_TIMEOUT:-30}
until echo "select 1;" | python3 manage.py dbshell > /dev/null
do
echo -n "."
failure_count=$((failure_count + 1))
sleep 1
if [ $DD_DATABASE_READINESS_TIMEOUT = $failure_count ]; then
exit 1
fi
echo -n "."
failure_count=$((failure_count + 1))
sleep 1
if [ $DD_DATABASE_READINESS_TIMEOUT = $failure_count ]; then
exit 1
fi
done
cat <<EOD | python manage.py shell
from django.db import connections
from django.db.utils import OperationalError
db_conn = connections['default']
c = db_conn.cursor()
EOD
exit $?
}

0 comments on commit ac089d0

Please sign in to comment.