Skip to content

Commit 287b2b2

Browse files
author
Thomas Noe
committed
Merge remote-tracking branch 'upstream/master'
2 parents 608d46a + 5706e30 commit 287b2b2

40 files changed

+1274
-125066
lines changed

.travis.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ env:
1414

1515
matrix:
1616
allow_failures:
17-
- env: TEST=bandit
17+
- env: TEST=bandit
1818
- env: TEST=sourceclear
1919
- env: TEST=pep8
2020

@@ -32,17 +32,17 @@ script:
3232
case "$TEST" in
3333
smoke-test)
3434
travis_fold start "smoke-test"
35-
bash ./scripts/travis-smoke-test.sh || exit 1
35+
bash entrypoint_scripts/test/travis-smoke-test.sh || exit 1
3636
travis_fold end "smoke-test"
3737
;;
3838
unit-test)
3939
travis_fold start "unit-test"
40-
bash ./scripts/travis-unit-test.sh || exit 1
40+
bash entrypoint_scripts/test/travis-unit-test.sh || exit 1
4141
travis_fold end "unit-test"
4242
;;
4343
integration-test)
4444
travis_fold start "integration-test"
45-
bash ./scripts/travis-integration-test.sh || exit 1
45+
bash entrypoint_scripts/test/travis-integration-test.sh || exit 1
4646
travis_fold end "integration-test"
4747
;;
4848
sourceclear)
@@ -52,7 +52,7 @@ script:
5252
bandit)
5353
# install bandit
5454
pip install bandit
55-
55+
5656
## Run Bandit python static code
5757
bandit -r * -x venv,tests,ansible
5858
;;
@@ -72,10 +72,9 @@ script:
7272
7373
after_success:
7474
#Push to docker repo
75-
- docker tag $REPO $REPO:$TAG
76-
- docker tag $REPO $REPO:travis-$TRAVIS_BUILD_NUMBER
7775
- |
78-
if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TEST" == "integration-test" ] && [ "$DOCKER_USER" != "" ] && [ "$DOCKER_PASS" != "" ]; then
76+
if [ "$TRAVIS_TAG" != "" ] && [ "$DOCKER_USER" != "" ] && [ "$DOCKER_PASS" != "" ]; then
77+
docker tag $REPO $REPO:$TRAVIS_TAG
7978
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS";
8079
docker push $REPO ;
8180
fi

Dockerfile

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
FROM ubuntu:16.04
22
MAINTAINER Matt Tesauro <[email protected]>
33

4-
# Create a single Docker running DefectDojo and all dependencies
4+
# # # Create a single Docker image running DefectDojo and all dependencies
55

6-
ADD . /opt/django-DefectDojo
6+
# Update and install basic requirements;
7+
# Install mysql-server already at this place, since we want to avoid
8+
# interactivity when creating a Docker image;
9+
# Also: create the application user;
10+
RUN apt-get update \
11+
&& apt-get install -y sudo git expect wget \
12+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server \
13+
&& adduser --disabled-password --gecos "DefectDojo" dojo
714

8-
RUN apt update \
9-
&& DEBIAN_FRONTEND=noninteractive apt install -y mysql-server sudo git expect wget \
10-
&& usermod -d /var/lib/mysql/ mysql \
11-
&& service mysql start \
12-
&& cd /opt \
13-
&& export AUTO_DOCKER=yes \
14-
&& /opt/django-DefectDojo/setup.bash \
15-
&& cd /tmp \
16-
&& wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz \
17-
&& tar xvfJ wkhtmltox-0.12.4_linux-generic-amd64.tar.xz \
18-
&& sudo chown root:root wkhtmltox/bin/wkhtmltopdf \
19-
&& sudo cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf \
20-
&& service mysql stop
15+
# Give the app user sudo permissions and switch executing user
16+
ADD ./docker/etc/dojo_sudo /etc/sudoers.d/
17+
USER dojo:dojo
2118

19+
# Add the application files and start the setup
20+
ADD --chown=dojo:dojo . /opt/django-DefectDojo
2221
WORKDIR /opt/django-DefectDojo
22+
# Add the -y option to avoid interactive prompts
23+
RUN ./setup.bash -y
2324

24-
ENTRYPOINT chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \
25-
&& service mysql start \
26-
&& su - dojo -c "cd /opt/django-DefectDojo && celery -A dojo worker -l info --concurrency 3 >> /opt/django-DefectDojo/worker.log 2>&1 &" \
27-
&& su - dojo -c "cd /opt/django-DefectDojo && celery beat -A dojo -l info >> /opt/django-DefectDojo/beat.log 2>&1 &" \
28-
&& su - dojo -c "cd /opt/django-DefectDojo && python manage.py runserver 0.0.0.0:8000 >> /opt/django-DefectDojo/dojo.log 2>&1"
25+
# Install wkhtmltopdf
26+
RUN wget -O /tmp/wkhtmltox.tar.xz https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz \
27+
&& tar xvfJ /tmp/wkhtmltox.tar.xz -C /tmp \
28+
&& sudo chown root:root /tmp/wkhtmltox/bin/wkhtmltopdf \
29+
&& sudo cp /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
30+
31+
# Start the DB server and rund the app
32+
ENTRYPOINT sudo chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \
33+
&& sudo service mysql start \
34+
&& (celery -A dojo worker -l info --concurrency 3 >> /opt/django-DefectDojo/worker.log 2>&1 &) \
35+
&& (celery beat -A dojo -l info >> /opt/django-DefectDojo/beat.log 2>&1 &) \
36+
&& (python manage.py runserver 0.0.0.0:8000 >> /opt/django-DefectDojo/dojo.log 2>&1)

docker/docker-startup.bash

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
#!/bin/sh
2+
# This script can be used as an entrypoint to get the Docker image started as
3+
# follows:
4+
#
5+
# ``docker run -it -p 8000:8000 appsecpipeline/django-defectdojo bash -c "export LOAD_SAMPLE_DATA=True && bash /opt/django-DefectDojo/docker/docker-startup.bash"``
6+
#
7+
# Run it at the application root
8+
#
9+
10+
source entrypoint_scripts/common/dojo-shared-resources.sh
11+
12+
# This function invocation ensures we're running the script at the right place
13+
verify_cwd
14+
215
#Set the SQL variables
316
SQLUSER=$MYSQL_USER
417
SQLPWD=$MYSQL_PASSWORD
518
SQLHOST=$DOJO_MYSQL_HOST
619
DBNAME=$MYSQL_DATABASE
720

8-
source /django-DefectDojo/scripts/dojo-shared-functions.bash
9-
1021
########### Setup and Run Entry #############
1122
if [ "$1" == "setup" ]; then
1223
setupdojo
13-
chown -R dojo:dojo /django-DefectDojo
24+
chown -R dojo:dojo $DOJO_ROOT_DIR
1425
else
1526
echo "=============================================================================="
1627
echo "Starting DefectDojo"
@@ -20,8 +31,7 @@ else
2031
PORT=8000
2132
fi
2233

23-
cd /django-DefectDojo/
24-
source venv/bin/activate
34+
source $DOJO_VENV_NAME/bin/activate
2535

2636
#Check to see if Dojo has been setup by checking the settings.py file
2737
if [ ! -f dojo/settings/settings.py ];
@@ -37,28 +47,28 @@ else
3747
cp dojo/settings/settings.dist.py dojo/settings/settings.py
3848

3949
# Save MySQL details in settings file
40-
sed -i "s/MYSQLUSER/$SQLUSER/g" dojo/settings/settings.py
41-
sed -i "s/MYSQLPWD/$SQLPWD/g" dojo/settings/settings.py
42-
sed -i "s/MYSQLDB/$DBNAME/g" dojo/settings/settings.py
43-
sed -i "s/MYSQLHOST/$DOJO_MYSQL_HOST/g" dojo/settings/settings.py
44-
sed -i "s/MYSQLPORT/$DOJO_MYSQL_PORT/g" dojo/settings/settings.py
45-
sed -i "s#DOJODIR#$PWD/dojo#g" dojo/settings/settings.py
46-
sed -i "s/DOJOSECRET/$SECRET/g" dojo/settings/settings.py
47-
sed -i "s#DOJOURLPREFIX#$DOJO_URL_PREFIX#g" dojo/settings/settings.py
48-
sed -i "s#BOWERDIR#$PWD/components#g" dojo/settings/settings.py
49-
sed -i "s#DOJO_MEDIA_ROOT#$PWD/media/#g" dojo/settings/settings.py
50-
sed -i "s#DOJO_STATIC_ROOT#$PWD/static/#g" dojo/settings/settings.py
50+
sed -i "s/MYSQLUSER/$SQLUSER/g" dojo/settings/settings.py
51+
sed -i "s/MYSQLPWD/$SQLPWD/g" dojo/settings/settings.py
52+
sed -i "s/MYSQLDB/$DBNAME/g" dojo/settings/settings.py
53+
sed -i "s/MYSQLHOST/$DOJO_MYSQL_HOST/g" dojo/settings/settings.py
54+
sed -i "s/MYSQLPORT/$DOJO_MYSQL_PORT/g" dojo/settings/settings.py
55+
sed -i "s#DOJODIR#$PWD/dojo#g" dojo/settings/settings.py
56+
sed -i "s/DOJOSECRET/$SECRET/g" dojo/settings/settings.py
57+
sed -i "s#DOJOURLPREFIX#$DOJO_URL_PREFIX#g" dojo/settings/settings.py
58+
sed -i "s#BOWERDIR#$PWD/components#g" dojo/settings/settings.py
59+
sed -i "s#DOJO_MEDIA_ROOT#$PWD/media/#g" dojo/settings/settings.py
60+
sed -i "s#DOJO_STATIC_ROOT#$PWD/static/#g" dojo/settings/settings.py
5161

5262
if [ "$RUN_TIERED" = True ]; then
5363
echo "Setting dojo settings for tiered docker-compose."
54-
sed -i "s/TEMPLATE_DEBUG = DEBUG/TEMPLATE_DEBUG = False/g" dojo/settings/settings.py
55-
sed -i "s/DEBUG = True/DEBUG = False/g" dojo/settings/settings.py
56-
sed -i "s/ALLOWED_HOSTS = \[]/ALLOWED_HOSTS = ['localhost', '127.0.0.1']/g" dojo/settings/settings.py
64+
sed -i "s/TEMPLATE_DEBUG = DEBUG/TEMPLATE_DEBUG = False/g" dojo/settings/settings.py
65+
sed -i "s/DEBUG = True/DEBUG = False/g" dojo/settings/settings.py
66+
sed -i "s/ALLOWED_HOSTS = \[]/ALLOWED_HOSTS = ['localhost', '127.0.0.1']/g" dojo/settings/settings.py
5767
else
5868
echo "Setting dojo settings for SQLLITEDB."
5969
SQLLITEDB="'NAME': os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'db.sqlite3')"
60-
sed -i "s/django.db.backends.mysql/django.db.backends.sqlite3/g" dojo/settings/settings.py
61-
sed -i "s/'NAME': '$DBNAME'/$SQLLITEDB/g" dojo/settings/settings.py
70+
sed -i "s/django.db.backends.mysql/django.db.backends.sqlite3/g" dojo/settings/settings.py
71+
sed -i "s/'NAME': '$DBNAME'/$SQLLITEDB/g" dojo/settings/settings.py
6272
fi
6373
fi
6474

@@ -69,7 +79,7 @@ else
6979
echo "=============================================================================="
7080
echo
7181
#Make sure MySQL is up and running, run the mysql script to check the port and report back
72-
bash /django-DefectDojo/docker/wait-for-it.sh $DOJO_MYSQL_HOST:$DOJO_MYSQL_PORT
82+
bash $DOCKER_DIR/wait-for-it.sh $DOJO_MYSQL_HOST:$DOJO_MYSQL_PORT
7383

7484
if [ $? -eq 0 ]; then
7585
echo "Database server is up and running."
@@ -86,7 +96,7 @@ else
8696
echo "=============================================================================="
8797
echo
8898
#Start gunicorn
89-
cd /django-DefectDojo/
99+
cd $DOJO_ROOT_DIR
90100
gunicorn --env DJANGO_SETTINGS_MODULE=dojo.settings dojo.wsgi:application --bind 0.0.0.0:$PORT --workers 3 & celery -A dojo worker -l info --concurrency 3
91101
else
92102
echo "MySQL server is down or dojo can't access mysql"
@@ -98,7 +108,7 @@ else
98108
if [ ! -f setupcomplete ];
99109
then
100110
createadmin
101-
bash /django-DefectDojo/docker/dojo-data.bash load
111+
bash $DOCKER_DIR/dojo-data.bash load
102112
touch setupcomplete
103113
fi
104114

@@ -111,8 +121,8 @@ else
111121
echo "Starting Python Server"
112122
echo "=============================================================================="
113123
echo
114-
cd /django-DefectDojo/
115-
source venv/bin/activate
124+
125+
source $DOJO_VENV_NAME/bin/activate
116126
pip freeze
117127
python manage.py runserver 0.0.0.0:$PORT & celery -A dojo worker -l info --concurrency 3
118128
echo

docker/dojo-base-build-push.bash

Lines changed: 0 additions & 17 deletions
This file was deleted.

docker/dojo-base.docker

Lines changed: 0 additions & 18 deletions
This file was deleted.

docker/dojo-container-build-push.bash

Lines changed: 0 additions & 14 deletions
This file was deleted.

docker/dojo-data.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ if [ $# > 1 ]
55
then
66
if [[ "$1" = "load" ]]
77
then
8-
python /django-DefectDojo/manage.py loaddata /django-DefectDojo/docker/sample_data/initial_dojo_data.json
8+
python manage.py loaddata docker/sample_data/initial_dojo_data.json
99
echo "Data imported from: sample_data/initial_dojo_data.json"
1010
elif [[ "$1" = "export" ]]; then
11-
python /django-DefectDojo/manage.py dumpdata --exclude auth.user > /django-DefectDojo/docker/sample_data/initial_dojo_data.json
11+
python manage.py dumpdata --exclude auth.user > docker/sample_data/initial_dojo_data.json
1212
echo "Data exported to: sample_data/initial_dojo_data.json"
1313
fi
1414
else

docker/etc/dojo_sudo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# User privilege specification
2+
dojo ALL=(ALL:ALL) NOPASSWD: ALL

docker/readme.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)