From 442f7e0453fa380e4e3c7148e7d302c9c350d513 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 23 May 2022 16:29:10 +0200 Subject: [PATCH] (bug) fix #355 compatibility with the new docker-compose CLI --- CHANGELOG.md | 1 + doc/production_readme.md | 26 +++++++++++++------------- scripts/pg-analyzers.sh | 17 ++++++++++++++++- scripts/run.sh | 15 +++++++++++++++ setup/setup.sh | 19 ++++++++++++++++++- setup/upgrade.sh | 15 +++++++++++++++ 6 files changed, 78 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1418a46c..0ed0b81e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Fix a bug: Missing of description of PlanCategory migration - Fix a bug: Unable to create plans for all group - Fix a bug: backPrevLocation button on Notification Center opens reset password page (#348) +- Fix a bug: compatibility with the new docker-compose CLI (#355) - Fix a security issue: updated moment.js to 2.29.2. to fix [CVE-2022-24785](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24785) - Fix a security issue: updated nokogiri to 1.13.6 to fix [CVE-2022-298240](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-298240) - Fix a security issue: updated async to 2.6.4 to fix [CVE-2021-43138](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-43138) diff --git a/doc/production_readme.md b/doc/production_readme.md index 856d37e50..f19640193 100644 --- a/doc/production_readme.md +++ b/doc/production_readme.md @@ -106,7 +106,7 @@ In order to remove ElasticSearch, you must **first** disable the statistics modu Then, you can remove the `elasticsearch` service from the [docker-compose.yml](../setup/docker-compose.yml) file and restart the whole application: ```bash -docker-compose down && docker-compose up -d +docker compose down && docker compose up -d ``` Disabling ElasticSearch will save up to 800 Mb of memory. @@ -118,11 +118,11 @@ Before using any of these commands, you must first `cd` into the app directory. - Read again the environment variables and restart ```bash -docker-compose down && docker-compose up -d +docker compose down && docker compose up -d ``` - Open a bash prompt inside the app container ```bash -docker-compose exec fabmanager bash +docker compose exec fabmanager bash ``` - Open the ruby console in the application ```bash @@ -130,11 +130,11 @@ docker-compose exec fabmanager bash ``` - Show services status ```bash -docker-compose ps +docker compose ps ``` - Run a command and provide it environment variables ```bash -docker-compose run --rm -e VAR1=xxx -e VAR2=xxx fabmanager bundle exec rails my:command +docker compose run --rm -e VAR1=xxx -e VAR2=xxx fabmanager bundle exec rails my:command ``` ## Update Fab-manager @@ -192,11 +192,11 @@ Then, you'll need to perform the upgrade with the following command: 2. Pull last docker images - `docker-compose pull` + `docker compose pull` 3. Stop the app - `docker-compose stop fabmanager` + `docker compose stop fabmanager` 4. Remove old assets @@ -204,7 +204,7 @@ Then, you'll need to perform the upgrade with the following command: 5. Compile new assets - `docker-compose run --rm fabmanager bundle exec rails assets:precompile` + `docker compose run --rm fabmanager bundle exec rails assets:precompile` 6. Run specific commands @@ -212,23 +212,23 @@ Then, you'll need to perform the upgrade with the following command: are always specified in the [CHANGELOG](https://github.com/sleede/fab-manager/blob/master/CHANGELOG.md) and prefixed by **[TODO DEPLOY]**. Those commands execute specific tasks and have to be run manually. - You must prefix the commands starting by `rails...` or `rake...` with: `docker-compose run --rm fabmanager bundle exec`. + You must prefix the commands starting by `rails...` or `rake...` with: `docker compose run --rm fabmanager bundle exec`. In any other cases, the other commands (like those invoking curl `\curl -sSL... | bash`) must not be prefixed. You can also ignore commands only applicable to development environnement, which are prefixed by `(dev)` in the CHANGELOG. 7. Restart all containers ```bash - docker-compose down - docker-compose up -d + docker compose down + docker compose up -d ``` -You can check that all containers are running with `docker-compose ps`. +You can check that all containers are running with `docker compose ps`. ### Upgrade to the last version -It's the default behaviour as `docker-compose pull` command will fetch the latest versions of the docker images. +It's the default behaviour as `docker compose pull` command will fetch the latest versions of the docker images. Be sure to run all the specific commands listed in the [CHANGELOG](https://github.com/sleede/fab-manager/blob/master/CHANGELOG.md) between your actual, and the new version in sequential order. __Example:__ to update from v2.4.0 to v2.4.3, you will run the specific commands for the v2.4.1, v2.4.2 and v2.4.3. diff --git a/scripts/pg-analyzers.sh b/scripts/pg-analyzers.sh index 7fac40058..3d2861859 100755 --- a/scripts/pg-analyzers.sh +++ b/scripts/pg-analyzers.sh @@ -1,3 +1,18 @@ #!/usr/bin/env bash -docker-compose exec -T postgres psql -Upostgres -c \\dFd | head -n -2 | tail -n +3 | awk '{ print gensub(/([a-z]+)_stem/,"\\1","g",$3); }' \ No newline at end of file +docker-compose() +{ + if ! docker compose version 1>/dev/null 2>/dev/null + then + if ! \docker-compose version 1>/dev/null 2>/dev/null + then + echo -e "\e[91m[ ❌ ] docker-compose was not found, exiting...\e[39m" && exit 1 + else + \docker-compose "$@" + fi + else + docker compose "$@" + fi +} + +docker-compose exec -T postgres psql -Upostgres -c \\dFd | head -n -2 | tail -n +3 | awk '{ print gensub(/([a-z]+)_stem/,"\\1","g",$3); }' diff --git a/scripts/run.sh b/scripts/run.sh index 2ebb674e3..09e49c9ce 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -8,6 +8,21 @@ config() { SERVICE="$(yq eval '.services.*.image | select(. == "sleede/fab-manager*") | path | .[-2]' docker-compose.yml)" } +docker-compose() +{ + if ! docker compose version 1>/dev/null 2>/dev/null + then + if ! \docker-compose version 1>/dev/null 2>/dev/null + then + echo -e "\e[91m[ ❌ ] docker-compose was not found, exiting...\e[39m" && exit 1 + else + \docker-compose "$@" + fi + else + docker compose "$@" + fi +} + run() { config diff --git a/setup/setup.sh b/setup/setup.sh index 2a15f77b3..e37db3066 100755 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -45,7 +45,7 @@ system_requirements() fi done fi - local _commands=("sudo" "curl" "sed" "openssl" "docker" "docker-compose" "systemctl") + local _commands=("sudo" "curl" "sed" "openssl" "docker" "systemctl") for _command in "${_commands[@]}"; do echo "detecting $_command..." if ! command -v "$_command" @@ -54,9 +54,26 @@ system_requirements() echo -e "\e[91m[ ❌ ] $_command was not found, exiting...\e[39m" && exit 1 fi done + echo "detecting docker-compose..." + docker-compose version printf "\e[92m[ ✔ ] All requirements successfully checked.\e[39m \n\n" } +docker-compose() +{ + if ! docker compose version 1>/dev/null 2>/dev/null + then + if ! \docker-compose version 1>/dev/null 2>/dev/null + then + echo -e "\e[91m[ ❌ ] docker-compose was not found, exiting...\e[39m" && exit 1 + else + \docker-compose "$@" + fi + else + docker compose "$@" + fi +} + is_root() { return $(id -u) diff --git a/setup/upgrade.sh b/setup/upgrade.sh index ba4e6cf67..f3e48e451 100644 --- a/setup/upgrade.sh +++ b/setup/upgrade.sh @@ -43,6 +43,21 @@ jq() { docker run --rm -i -v "${PWD}:/data" imega/jq "$@" } +docker-compose() +{ + if ! docker compose version 1>/dev/null 2>/dev/null + then + if ! \docker-compose version 1>/dev/null 2>/dev/null + then + echo -e "\e[91m[ ❌ ] docker-compose was not found, exiting...\e[39m" && exit 1 + else + \docker-compose "$@" + fi + else + docker compose "$@" + fi +} + # set $SERVICE and $YES_ALL config() {