Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace docker compose with overrideable ${DOCKER_COMPOSE_COMMAND} env variable #639

Merged
merged 2 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions bin/warden
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}" == "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
Expand Down
4 changes: 2 additions & 2 deletions commands/env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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[@]}" "$@"

Expand Down
2 changes: 1 addition & 1 deletion commands/env.help
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion commands/sign-certificate.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion commands/svc.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}" "$@"

Expand Down
2 changes: 1 addition & 1 deletion commands/svc.help
Original file line number Diff line number Diff line change
@@ -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"
Expand Down