Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract first boot portion of script #11468

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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
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
Loading