Skip to content

Commit 4514e99

Browse files
authored
dc command improvements (DefectDojo#6227)
* Add: option to check docker-compose version * Add: default profile if not specified * refactoring * Update doc
1 parent 4441a32 commit 4514e99

File tree

8 files changed

+67
-8
lines changed

8 files changed

+67
-8
lines changed

dc-build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#/bin/bash
22

3+
bash ./docker/docker-compose-check.sh
4+
if [[ $? -eq 1 ]]; then exit 1; fi
5+
36
if [ $# -eq 0 ]
47
then
58
echo "Building docker compose"

dc-down.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#/bin/bash
22

3+
bash ./docker/docker-compose-check.sh
4+
if [[ $? -eq 1 ]]; then exit 1; fi
5+
36
if [ $# -eq 0 ]
47
then
58
echo "Stopping docker compose and removing containers"

dc-stop.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#/bin/bash
22

3+
bash ./docker/docker-compose-check.sh
4+
if [[ $? -eq 1 ]]; then exit 1; fi
5+
36
if [ $# -eq 0 ]
47
then
58
echo "Stopping docker compose"

dc-unittest.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
unset PROFILE
44
unset TEST_CASE
55

6+
bash ./docker/docker-compose-check.sh
7+
if [[ $? -eq 1 ]]; then exit 1; fi
8+
69
usage() {
710
echo
811
echo "This script helps with running unit tests."

dc-up-d.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22

33
unset PROFILE
44

5+
bash ./docker/docker-compose-check.sh
6+
if [[ $? -eq 1 ]]; then exit 1; fi
7+
58
if [ $# -eq 0 ]
69
then
710
if [ -z $DD_PROFILE ]
811
then
9-
echo "No profile supplied"
10-
exit 1
12+
echo "No profile supplied, running default: mysql-rabbitmq"
13+
PROFILE="mysql-rabbitmq"
14+
echo "Other supported profiles:
15+
mysql-rabbitmq*
16+
mysql-redis
17+
postgres-rabbitmq
18+
postgres-redis
19+
20+
Usage example: ./dc-up-d.sh mysql-redis
21+
"
1122
else
1223
PROFILE=$DD_PROFILE
1324
fi

dc-up.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22

33
unset PROFILE
44

5-
if [ $# -eq 0 ]
6-
then
5+
bash ./docker/docker-compose-check.sh
6+
if [[ $? -eq 1 ]]; then exit 1; fi
7+
8+
if [ $# -eq 0 ]; then
79
if [ -z $DD_PROFILE ]
810
then
9-
echo "No profile supplied"
10-
exit 1
11+
echo "No profile supplied, running default: mysql-rabbitmq"
12+
PROFILE="mysql-rabbitmq"
13+
echo "Other supported profiles:
14+
mysql-rabbitmq*
15+
mysql-redis
16+
postgres-rabbitmq
17+
postgres-redis
18+
19+
Usage example: ./dc-up.sh mysql-redis
20+
"
1121
else
1222
PROFILE=$DD_PROFILE
1323
fi

docker/docker-compose-check.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#/bin/bash
2+
3+
main=`docker-compose version --short | cut -d '.' -f 1`
4+
minor=`docker-compose version --short | cut -d '.' -f 2`
5+
current=`docker-compose version --short`
6+
7+
echo 'Checking docker-compose version'
8+
if [[ $main -lt 1 ]]; then
9+
echo "$current is not supported docker-compose version, please upgrade to minimal supported version:1.28"
10+
exit 1
11+
elif [[ $main -eq 1 ]]; then
12+
if [[ $minor -lt 28 ]]; then
13+
echo "$current is not supported docker-compose version, please upgrade to minimal supported version:1.28"
14+
exit 1
15+
fi
16+
fi
17+
18+
echo 'Supported docker-compose version'

readme-docs/DOCKER.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,20 @@ When running the application without building images, the application will run b
3636

3737
The Docker Compose setup supports 2 different databases (MySQL and PostgreSQL) and 2 different celery brokers (RabbitMQ and Redis). To make this possible, docker-compose needs to be started with the parameter `--profile` with one of these choices:
3838

39-
- mysql-rabbitmq
39+
- mysql-rabbitmq*
4040
- mysql-redis
4141
- postgres-rabbitmq
4242
- postgres-redis
4343

44+
e.g.
45+
```zsh
46+
./dc-up.sh mysql-redis
47+
```
48+
49+
A default profile can be set with the environment variable `DD_PROFILE`. If this environment variable is set when starting the containers, the parameter for the profile needs not to be given for the start scripts.
50+
51+
When DD_PROFILE or command-line profile is not specified, the command will run "mysql-rabbitmq" as the default profile.
52+
4453
The environment variables needed for the different profiles are prepared in files, which need to be included additionally with the parameter `--env-file` with a choices that fits to the profile:
4554

4655
- ./docker/environments/mysql-rabbitmq.env
@@ -59,7 +68,6 @@ The environment variables needed for the different profiles are prepared in file
5968
- `./dc-down.sh` - Stop and remove the docker containers, it can take one additional parameter to be used in the stop and remove process.
6069
- `./dc-unittest.sh` - Utility script to aid in running a specific unit test class. Requires a profile and test case as parameters.
6170

62-
A default profile can be set with the environment variable `DD_PROFILE`. If this environment variable is set when starting the containers, the parameter for the profile needs not to be given for the start scripts .
6371

6472
# Setup via Docker Compose - Building and running the application
6573

0 commit comments

Comments
 (0)