[go: nahoru, domu]

Skip to content

Commit

Permalink
Docker dev compose improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronweaver committed Apr 8, 2019
1 parent 6d4cc0f commit a08a8f8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
4 changes: 3 additions & 1 deletion DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ docker logs $container_id 2>&1 | grep "Admin password:"

If you ran DefectDojo with compose before and you want to prevent the
initializer container from running again, define an environment variable
DD_INITIALIZE=false to prevent re-initialization.
`DD_INITIALIZE=false` to prevent re-initialization.

### Develop with Docker Compose

For developing the easiset way to make changes is to startup DefectDojo in debug by running `docker-compose -f docker-compose.yml up`. This starts the DefectDojo (uwsgi) container with manage.py and shares the local source directory so that changes to the code immediately restart the process.

Navigate to the container directly, <http://localhost:8000>

Build the containers locally: `docker-compose build`

The initializer container can be disabled by exporting: `export DD_INITIALIZE=false`

### Build Images Locally
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.django
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ COPY \
docker/entrypoint-celery-worker.sh \
docker/entrypoint-initializer.sh \
docker/entrypoint-uwsgi.sh \
docker/entrypoint-uwsgi-dev.sh \
docker/entrypoint-unit-tests.sh \
docker/wait-for-it.sh \
/
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ services:
protocol: tcp
mode: host
uwsgi:
image: defectdojo/defectdojo-django:latest
build:
context: ./
dockerfile: Dockerfile.django
depends_on:
- mysql
entrypoint: ['/wait-for-it.sh', 'mysql:3306', '-t', '30', '--', 'python', 'manage.py', 'runserver 0.0.0.0:8000']
entrypoint: ['/wait-for-it.sh', 'mysql:3306', '-t', '30', '--', '/entrypoint-uwsgi-dev.sh']
volumes:
- '.:/app'
ports:
Expand Down
30 changes: 18 additions & 12 deletions docker/entrypoint-initializer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ done
echo

python manage.py migrate

ADMIN_EXISTS=$(echo "SELECT * from auth_user;" | python manage.py dbshell | grep admin)

if [ -z "${ADMIN_EXISTS}" ]
then
cat <<EOD | python manage.py shell
import os
from django.contrib.auth.models import User
Expand All @@ -39,15 +44,16 @@ User.objects.create_superuser(
)
EOD

python manage.py loaddata product_type
python manage.py loaddata test_type
python manage.py loaddata development_environment
python manage.py loaddata system_settings
python manage.py loaddata benchmark_type
python manage.py loaddata benchmark_category
python manage.py loaddata benchmark_requirement
python manage.py loaddata language_type
python manage.py loaddata objects_review
python manage.py loaddata regulation
python manage.py installwatson
exec python manage.py buildwatson
python manage.py loaddata product_type
python manage.py loaddata test_type
python manage.py loaddata development_environment
python manage.py loaddata system_settings
python manage.py loaddata benchmark_type
python manage.py loaddata benchmark_category
python manage.py loaddata benchmark_requirement
python manage.py loaddata language_type
python manage.py loaddata objects_review
python manage.py loaddata regulation
python manage.py installwatson
exec python manage.py buildwatson
fi
21 changes: 21 additions & 0 deletions docker/entrypoint-uwsgi-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

umask 0002

# Copy settings.py (settings.py copied to allow for legacy installs and customizations)
cd /app
TARGET_SETTINGS_FILE=dojo/settings/settings.py
if [ ! -f ${TARGET_SETTINGS_FILE} ]; then
echo "Creating settings.py"
cp dojo/settings/settings.dist.py dojo/settings/settings.py
fi

while ping -c1 initializer 1>/dev/null 2>/dev/null
do {
echo "Waiting for initializer to complete"
sleep 3
}
done;
echo "Starting DefectDojo: http://localhost:8000"

python manage.py runserver 0.0.0.0:8000
2 changes: 1 addition & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ http {
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
client_max_body_size 8m;
client_max_body_size 800m;
sendfile on;
keepalive_timeout 65;
upstream uwsgi_server {
Expand Down

0 comments on commit a08a8f8

Please sign in to comment.