From b73e58f9e9cfe382056d7e0f3ec72b4abea6dbce Mon Sep 17 00:00:00 2001 From: T R Nayan <40191905+trnayan@users.noreply.github.com> Date: Tue, 17 Oct 2023 04:48:25 +0600 Subject: [PATCH] Migrate to Compose V2 for dev branch (#8817) * Migrate to Compose V2 * Migrate to Compose V2 * Migrate to Compose V2 * Migrate to Compose V2 * Update README.md Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Update README.md Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Update dc-build.sh Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Update README.md Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Migrate to Compose V2 Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Migrate to Compose V2 Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Migrate to Compose V2 Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Migrate to Compose V2 Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Migrate to Compose V2 Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Update README.md Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> * Remove Comments --------- Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com> --- README.md | 21 +++++++++++++++++++-- dc-build.sh | 4 +++- dc-down.sh | 4 +++- dc-stop.sh | 4 +++- dc-unittest.sh | 4 +++- dc-up-d.sh | 4 +++- dc-up.sh | 4 +++- docker/docker-compose-check.sh | 14 +++++++------- docker/entrypoint-initializer.sh | 2 +- docker/setEnv.sh | 12 ++++++------ 10 files changed, 51 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index bb6eb828881..3eb26774ce6 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 . diff --git a/dc-build.sh b/dc-build.sh index 365b620fc4d..8793ee97463 100755 --- a/dc-build.sh +++ b/dc-build.sh @@ -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 diff --git a/dc-down.sh b/dc-down.sh index 1f096bad0df..13dd5006364 100755 --- a/dc-down.sh +++ b/dc-down.sh @@ -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 diff --git a/dc-stop.sh b/dc-stop.sh index 2b4648ab36a..c1bbdd5b61e 100755 --- a/dc-stop.sh +++ b/dc-stop.sh @@ -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 diff --git a/dc-unittest.sh b/dc-unittest.sh index 38762730d3e..0a566e9f760 100755 --- a/dc-unittest.sh +++ b/dc-unittest.sh @@ -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" diff --git a/dc-up-d.sh b/dc-up-d.sh index 4e1816cd1cb..2ad26c12c01 100755 --- a/dc-up-d.sh +++ b/dc-up-d.sh @@ -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 diff --git a/dc-up.sh b/dc-up.sh index 9a2c8a14296..2b07d9addb3 100755 --- a/dc-up.sh +++ b/dc-up.sh @@ -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 diff --git a/docker/docker-compose-check.sh b/docker/docker-compose-check.sh index 2d86ce76d2c..6f705ffcab2 100755 --- a/docker/docker-compose-check.sh +++ b/docker/docker-compose-check.sh @@ -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 @@ -15,4 +15,4 @@ elif [[ $main -eq 1 ]]; then fi fi -echo 'Supported docker-compose version' \ No newline at end of file +echo 'Supported docker compose version' \ No newline at end of file diff --git a/docker/entrypoint-initializer.sh b/docker/entrypoint-initializer.sh index 19738bcd31b..2a59c12235b 100755 --- a/docker/entrypoint-initializer.sh +++ b/docker/entrypoint-initializer.sh @@ -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 diff --git a/docker/setEnv.sh b/docker/setEnv.sh index c6f998cdcb2..f7d7316f7e6 100755 --- a/docker/setEnv.sh +++ b/docker/setEnv.sh @@ -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." @@ -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." @@ -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." @@ -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." @@ -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." @@ -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."