Skip to content

Commit

Permalink
Migrate to Compose V2 for dev branch (#8817)
Browse files Browse the repository at this point in the history
* Migrate to Compose V2

* Migrate to Compose V2

* Migrate to Compose V2

* Migrate to Compose V2

* Update README.md

Co-authored-by: Charles Neill <[email protected]>

* Update README.md

Co-authored-by: Charles Neill <[email protected]>

* Update dc-build.sh

Co-authored-by: Charles Neill <[email protected]>

* Update README.md

Co-authored-by: Charles Neill <[email protected]>

* Migrate to Compose V2

Co-authored-by: Charles Neill <[email protected]>

* Migrate to Compose V2

Co-authored-by: Charles Neill <[email protected]>

* Migrate to Compose V2

Co-authored-by: Charles Neill <[email protected]>

* Migrate to Compose V2

Co-authored-by: Charles Neill <[email protected]>

* Migrate to Compose V2

Co-authored-by: Charles Neill <[email protected]>

* Update README.md

Co-authored-by: Charles Neill <[email protected]>

* Remove Comments

---------

Co-authored-by: Charles Neill <[email protected]>
  • Loading branch information
trnayan and cneill authored Oct 16, 2023
1 parent 674dc8d commit b73e58f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 22 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ Try out the demo server at [demo.defectdojo.org](https://demo.defectdojo.org)

Log in with `admin / 1Defectdojo@demo#appsec`. Please note that the demo is publicly accessible and regularly reset. Do not put sensitive data in the demo.

## Quick Start
## Quick Start for Compose V2
From July 2023 Compose V1 [stopped receiving updates](https://docs.docker.com/compose/reference/).

Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using `docker compose`, instead of `docker-compose`.

```sh
git clone https://github.com/DefectDojo/django-DefectDojo
Expand All @@ -52,9 +55,23 @@ cd django-DefectDojo
./dc-up.sh postgres-redis
# obtain admin credentials. the initializer can take up to 3 minutes to run
# use docker-compose logs -f initializer to track progress
docker-compose logs initializer | grep "Admin password:"
docker compose logs initializer | grep "Admin password:"
```
## For Docker Compose V1
You can run Compose V1 by editing the below files to add the hyphen (-) between `docker compose`.
```sh
dc-build.sh
dc-down.sh
dc-stop.sh
dc-unittest.sh
dc-up-d.sh
dc-up.sh
docker/docker-compose-check.sh
docker/entrypoint-initializer.sh
docker/setEnv.sh
```


Navigate to <http://localhost:8080>.


Expand Down
4 changes: 3 additions & 1 deletion dc-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ fi

# Building images for all configurations
# The docker build doesn't supply any environment variables to the Dockerfile, so we can use any profile.
docker-compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env build $1

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env build $1
4 changes: 3 additions & 1 deletion dc-down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ fi

# Stopping containers for all configurations
# The environment must be provided but it doesn't make a difference which one
docker-compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env down $1

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env down $1
4 changes: 3 additions & 1 deletion dc-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ fi

# Stopping containers for all configurations
# The environment must be provided but it doesn't make a difference which one
docker-compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env stop $1

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/postgres-redis.env stop $1
4 changes: 3 additions & 1 deletion dc-unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ then
fi

echo "Running docker compose unit tests with profile $PROFILE and test case $TEST_CASE ..."
docker-compose --profile $PROFILE --env-file ./docker/environments/$PROFILE.env exec uwsgi bash -c "python manage.py test $TEST_CASE -v2 --keepdb"

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile $PROFILE --env-file ./docker/environments/$PROFILE.env exec uwsgi bash -c "python manage.py test $TEST_CASE -v2 --keepdb"
4 changes: 3 additions & 1 deletion dc-up-d.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ else
fi

echo "Starting docker compose with profile $PROFILE in the background ..."
docker-compose --profile $PROFILE --env-file ./docker/environments/$PROFILE.env up --no-deps -d

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile $PROFILE --env-file ./docker/environments/$PROFILE.env up --no-deps -d
4 changes: 3 additions & 1 deletion dc-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ else
fi

echo "Starting docker compose with profile $PROFILE in the foreground ..."
docker-compose --profile $PROFILE --env-file ./docker/environments/$PROFILE.env up --no-deps

# Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
docker compose --profile $PROFILE --env-file ./docker/environments/$PROFILE.env up --no-deps
14 changes: 7 additions & 7 deletions docker/docker-compose-check.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash

main=`docker-compose version --short | cut -d '.' -f 1`
minor=`docker-compose version --short | cut -d '.' -f 2`
current=`docker-compose version --short`
main=`docker compose version --short | cut -d '.' -f 1`
minor=`docker compose version --short | cut -d '.' -f 2`
current=`docker compose version --short`

echo 'Checking docker-compose version'
if [[ $main -lt 1 ]]; then
echo "$current is not supported docker-compose version, please upgrade to minimal supported version:1.28"
echo 'Checking docker compose version'
if [[ $main -lt 2 ]]; then
echo "$current is not a supported docker-compose version, please upgrade to the minimum supported version: 2.0"
exit 1
elif [[ $main -eq 1 ]]; then
if [[ $minor -lt 28 ]]; then
Expand All @@ -15,4 +15,4 @@ elif [[ $main -eq 1 ]]; then
fi
fi

echo 'Supported docker-compose version'
echo 'Supported docker compose version'
2 changes: 1 addition & 1 deletion docker/entrypoint-initializer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if [ ! -z "$ADMIN_EXISTS" ]
then
echo "Admin password: Initialization detected that the admin user ${DD_ADMIN_USER} already exists in your database."
echo "If you don't remember the ${DD_ADMIN_USER} password, you can create a new superuser with:"
echo "$ docker-compose exec uwsgi /bin/bash -c 'python manage.py createsuperuser'"
echo "$ docker compose exec uwsgi /bin/bash -c 'python manage.py createsuperuser'"
create_announcement_banner
initialize_data
exit
Expand Down
12 changes: 6 additions & 6 deletions docker/setEnv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function set_release {
get_current
if [ "${current_env}" != release ]
then
docker-compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
# In release configuration there is no override file
rm ${override_link}
echo "Now using 'release' configuration."
Expand All @@ -67,7 +67,7 @@ function set_dev {
get_current
if [ "${current_env}" != dev ]
then
docker-compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
rm -f ${override_link}
ln -s ${override_file_dev} ${override_link}
echo "Now using 'dev' configuration."
Expand All @@ -80,7 +80,7 @@ function set_debug {
get_current
if [ "${current_env}" != debug ]
then
docker-compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
rm -f ${override_link}
ln -s ${override_file_debug} ${override_link}
echo "Now using 'debug' configuration."
Expand All @@ -93,7 +93,7 @@ function set_unit_tests {
get_current
if [ "${current_env}" != unit_tests ]
then
docker-compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
rm -f ${override_link}
ln -s ${override_file_unit_tests} ${override_link}
echo "Now using 'unit_tests' configuration."
Expand All @@ -106,7 +106,7 @@ function set_unit_tests_cicd {
get_current
if [ "${current_env}" != unit_tests_cicd ]
then
docker-compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
rm -f ${override_link}
ln -s ${override_file_unit_tests_cicd} ${override_link}
echo "Now using 'unit_tests_cicd' configuration."
Expand All @@ -119,7 +119,7 @@ function set_integration_tests {
get_current
if [ "${current_env}" != integration_tests ]
then
docker-compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
docker compose --profile mysql-rabbitmq --profile postgres-redis --env-file ./docker/environments/mysql-rabbitmq.env down
rm -f ${override_link}
ln -s ${override_file_integration_tests} ${override_link}
echo "Now using 'integration_tests' configuration."
Expand Down

0 comments on commit b73e58f

Please sign in to comment.