From eae4fa8339a098e19bf6f6d789f7364f635f9f43 Mon Sep 17 00:00:00 2001 From: Navarr Date: Tue, 4 Apr 2023 09:31:12 -0400 Subject: [PATCH 1/2] Replace `docker compose` with overrideable `${DOCKER_COMPOSE_COMMAND}` env variable Resolves comment made by @tdgroot in #638 --- bin/warden | 12 ++++++++---- commands/env.cmd | 4 ++-- commands/env.help | 2 +- commands/sign-certificate.cmd | 2 +- commands/svc.cmd | 2 +- commands/svc.help | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/bin/warden b/bin/warden index 355850b3..c46a365f 100755 --- a/bin/warden +++ b/bin/warden @@ -14,6 +14,7 @@ readonly WARDEN_DIR="$( )" export readonly WARDEN_BIN="${WARDEN_DIR}/bin/warden" +export readonly DOCKER_COMPOSE_COMMAND="${DOCKER_COMPOSE_COMMAND:-"docker compose"}" source "${WARDEN_DIR}/utils/core.sh" source "${WARDEN_DIR}/utils/env.sh" @@ -24,10 +25,13 @@ if ! which docker >/dev/null; then fi ## verify docker compose meets version constraint -DOCKER_COMPOSE_REQUIRE="2.2.3" -DOCKER_COMPOSE_VERSION="$(docker compose version | grep -oE '[0-9\.]+' | head -n1)" -if ! test $(version ${DOCKER_COMPOSE_VERSION}) -ge $(version ${DOCKER_COMPOSE_REQUIRE}); then - fatal "docker compose version should be ${DOCKER_COMPOSE_REQUIRE} or higher (${DOCKER_COMPOSE_VERSION} installed)" +if [[ "${DOCKER_COMPOSE_COMMAND}" eq "docker compose" ]]; then + # Disable version check for experimental stuff + DOCKER_COMPOSE_REQUIRE="2.2.3" + DOCKER_COMPOSE_VERSION="$(${DOCKER_COMPOSE_COMMAND} version | grep -oE '[0-9\.]+' | head -n1)" + if ! test $(version ${DOCKER_COMPOSE_VERSION}) -ge $(version ${DOCKER_COMPOSE_REQUIRE}); then + fatal "docker compose version should be ${DOCKER_COMPOSE_REQUIRE} or higher (${DOCKER_COMPOSE_VERSION} installed)" + fi fi ## define and export global shared directory paths diff --git a/commands/env.cmd b/commands/env.cmd index 75a8a10f..b5f67a38 100644 --- a/commands/env.cmd +++ b/commands/env.cmd @@ -145,7 +145,7 @@ fi if [[ "${WARDEN_PARAMS[0]}" == "up" ]]; then ## create environment network for attachments if it does not already exist if [[ $(docker network ls -f "name=$(renderEnvNetworkName)" -q) == "" ]]; then - docker compose \ + ${DOCKER_COMPOSE_COMMAND} \ --project-directory "${WARDEN_ENV_PATH}" -p "${WARDEN_ENV_NAME}" \ "${DOCKER_COMPOSE_ARGS[@]}" up --no-start fi @@ -192,7 +192,7 @@ then fi ## pass ochestration through to docker compose -docker compose \ +${DOCKER_COMPOSE_COMMAND} \ --project-directory "${WARDEN_ENV_PATH}" -p "${WARDEN_ENV_NAME}" \ "${DOCKER_COMPOSE_ARGS[@]}" "${WARDEN_PARAMS[@]}" "$@" diff --git a/commands/env.help b/commands/env.help index 8a92390a..322531d8 100755 --- a/commands/env.help +++ b/commands/env.help @@ -1,7 +1,7 @@ #!/usr/bin/env bash [[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1 -COMPOSE_USAGE=$(docker compose "${WARDEN_PARAMS[@]}" "$@" \ +COMPOSE_USAGE=$(${DOCKER_COMPOSE_COMMAND} "${WARDEN_PARAMS[@]}" "$@" \ | grep -vE '(--file|--project-name|--project-directory|default: docker-compose.yml|default: directory name)' \ | sed '1d;2d;s/docker-compose/env/' \ | sed -E "s/^(Usage|Options|Commands):/$(echo -e "\033[33m\\1:\033[0m")/g" diff --git a/commands/sign-certificate.cmd b/commands/sign-certificate.cmd index c75ef839..32f500b4 100644 --- a/commands/sign-certificate.cmd +++ b/commands/sign-certificate.cmd @@ -51,7 +51,7 @@ openssl x509 -req -days 365 -sha256 -extensions v3_req \ -in "${WARDEN_SSL_DIR}/certs/${CERTIFICATE_NAME}.csr.pem" \ -out "${WARDEN_SSL_DIR}/certs/${CERTIFICATE_NAME}.crt.pem" -if [[ "$(cd "${WARDEN_HOME_DIR}" && docker compose -p warden -f "${WARDEN_DIR}/docker/docker-compose.yml" ps -q traefik)" ]] +if [[ "$(cd "${WARDEN_HOME_DIR}" && ${DOCKER_COMPOSE_COMMAND} -p warden -f "${WARDEN_DIR}/docker/docker-compose.yml" ps -q traefik)" ]] then echo "==> Updating traefik" "$WARDEN_BIN" svc up traefik diff --git a/commands/svc.cmd b/commands/svc.cmd index 2b607c1b..ca6769ae 100644 --- a/commands/svc.cmd +++ b/commands/svc.cmd @@ -87,7 +87,7 @@ if [[ "${WARDEN_PARAMS[0]}" == "up" ]]; then fi ## pass ochestration through to docker compose -WARDEN_SERVICE_DIR=${WARDEN_DIR} docker compose \ +WARDEN_SERVICE_DIR=${WARDEN_DIR} ${DOCKER_COMPOSE_COMMAND} \ --project-directory "${WARDEN_HOME_DIR}" -p warden \ "${DOCKER_COMPOSE_ARGS[@]}" "${WARDEN_PARAMS[@]}" "$@" diff --git a/commands/svc.help b/commands/svc.help index 9846e0b6..980fa514 100755 --- a/commands/svc.help +++ b/commands/svc.help @@ -1,7 +1,7 @@ #!/usr/bin/env bash [[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1 -COMPOSE_USAGE=$(docker compose "${WARDEN_PARAMS[@]}" "$@" \ +COMPOSE_USAGE=$(${DOCKER_COMPOSE_COMMAND} "${WARDEN_PARAMS[@]}" "$@" \ | grep -vE '(--file|--project-name|--project-directory|default: docker-compose.yml|default: directory name)' \ | sed '1d;2d;s/docker-compose/svc/' \ | sed -E "s/^(Usage|Options|Commands):/$(echo -e "\033[33m\\1:\033[0m")/g" From 4bdf597af01a011be000b5e0c1626ab09f96b12e Mon Sep 17 00:00:00 2001 From: Navarr Date: Tue, 4 Apr 2023 09:33:54 -0400 Subject: [PATCH 2/2] Fix comparison for triggering docker compose version check --- bin/warden | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/warden b/bin/warden index c46a365f..014031b4 100755 --- a/bin/warden +++ b/bin/warden @@ -25,7 +25,7 @@ if ! which docker >/dev/null; then fi ## verify docker compose meets version constraint -if [[ "${DOCKER_COMPOSE_COMMAND}" eq "docker compose" ]]; then +if [[ "${DOCKER_COMPOSE_COMMAND}" == "docker compose" ]]; then # Disable version check for experimental stuff DOCKER_COMPOSE_REQUIRE="2.2.3" DOCKER_COMPOSE_VERSION="$(${DOCKER_COMPOSE_COMMAND} version | grep -oE '[0-9\.]+' | head -n1)"