Skip to content

Commit

Permalink
extract first boot portion of script
Browse files Browse the repository at this point in the history
  • Loading branch information
hblankenship committed Dec 24, 2024
1 parent 85fe160 commit 4e3da95
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
1 change: 1 addition & 0 deletions .dryrunsecurity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sensitiveCodepaths:
- 'docker/entrypoint-celery-beat.sh'
- 'docker/entrypoint-celery-worker.sh'
- 'docker/entrypoint-initializer.sh'
- 'docker/entrypoint-first-boot.sh'
- 'docker/entrypoint-nginx.sh'
- 'docker/entrypoint-uwsgi.sh'
- 'docker/wait-for-it.sh'
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.django-debian
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ COPY \
docker/entrypoint-celery-beat.sh \
docker/entrypoint-celery-worker.sh \
docker/entrypoint-initializer.sh \
docker/entrypoint-first-boot.sh \
docker/entrypoint-uwsgi.sh \
docker/entrypoint-uwsgi-dev.sh \
docker/entrypoint-unit-tests.sh \
Expand Down
35 changes: 35 additions & 0 deletions docker/entrypoint-first-boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# called from entrypoint-initializer.sh when no admin user exists (first boot)
cat <<EOD | python manage.py shell
import os
from django.contrib.auth.models import User
User.objects.create_superuser(
os.getenv('DD_ADMIN_USER'),
os.getenv('DD_ADMIN_MAIL'),
os.getenv('DD_ADMIN_PASSWORD'),
first_name=os.getenv('DD_ADMIN_FIRST_NAME'),
last_name=os.getenv('DD_ADMIN_LAST_NAME')
)
EOD

# load surveys all at once as that's much faster
echo "Importing fixtures all at once"
python3 manage.py loaddata system_settings initial_banner_conf product_type test_type \
development_environment benchmark_type benchmark_category benchmark_requirement \
language_type objects_review regulation initial_surveys role sla_configurations

echo "UPDATE dojo_system_settings SET jira_webhook_secret='$DD_JIRA_WEBHOOK_SECRET'" | python manage.py dbshell

echo "Importing extra fixtures"
# If there is extra fixtures, load them
for i in $(find dojo/fixtures/extra_*.json | sort -n 2>/dev/null) ; do
echo "Loading $i"
python3 manage.py loaddata "${i%.*}"
done

echo "Installing watson search index"
python3 manage.py installwatson

# surveys fixture needs to be modified as it contains an instance dependant polymorphic content id
echo "Migration of textquestions for surveys"
python3 manage.py migrate_textquestions
36 changes: 2 additions & 34 deletions docker/entrypoint-initializer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,40 +138,8 @@ fi

if [ -z "${ADMIN_EXISTS}" ]
then
cat <<EOD | python manage.py shell
import os
from django.contrib.auth.models import User
User.objects.create_superuser(
os.getenv('DD_ADMIN_USER'),
os.getenv('DD_ADMIN_MAIL'),
os.getenv('DD_ADMIN_PASSWORD'),
first_name=os.getenv('DD_ADMIN_FIRST_NAME'),
last_name=os.getenv('DD_ADMIN_LAST_NAME')
)
EOD

# load surveys all at once as that's much faster
echo "Importing fixtures all at once"
python3 manage.py loaddata system_settings initial_banner_conf product_type test_type \
development_environment benchmark_type benchmark_category benchmark_requirement \
language_type objects_review regulation initial_surveys role sla_configurations

echo "UPDATE dojo_system_settings SET jira_webhook_secret='$DD_JIRA_WEBHOOK_SECRET'" | python manage.py dbshell

echo "Importing extra fixtures"
# If there is extra fixtures, load them
for i in $(find dojo/fixtures/extra_*.json | sort -n 2>/dev/null) ; do
echo "Loading $i"
python3 manage.py loaddata "${i%.*}"
done

echo "Installing watson search index"
python3 manage.py installwatson

# surveys fixture needs to be modified as it contains an instance dependant polymorphic content id
echo "Migration of textquestions for surveys"
python3 manage.py migrate_textquestions

./entrypoint-first-boot.sh

create_announcement_banner
initialize_data
fi

0 comments on commit 4e3da95

Please sign in to comment.