Skip to content

Commit

Permalink
Merge pull request #631 from wardenenv/docker-compose-plugin
Browse files Browse the repository at this point in the history
Move from docker-compose standalone to `docker compose` commands
  • Loading branch information
navarr authored Mar 31, 2023
2 parents c0c130e + c93c398 commit a32cb41
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## UNRELEASED [x.y.z](https://github.com/davidalger/warden/tree/x.y.z) (yyyy-mm-dd)
[All Commits](https://github.com/davidalger/warden/compare/0.13.1..develop)

**Dependency Changes:**
* All commands now use the Docker Compose plugin (`docker compose`) instead of the standalone command (`docker-compose`)
Please be aware that this will change your container names from using underscores to using dashes (e.g. vanilla_db_1 becomes vanilla-db-1).

**Enhancements**
* ElasticSearch 8.7 images are available

Expand Down
21 changes: 7 additions & 14 deletions bin/warden
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,16 @@ export readonly WARDEN_BIN="${WARDEN_DIR}/bin/warden"
source "${WARDEN_DIR}/utils/core.sh"
source "${WARDEN_DIR}/utils/env.sh"

## verify docker-compose is installed
if ! which docker-compose >/dev/null; then
fatal "docker-compose could not be found; please install and try again."
## verify docker is installed
if ! which docker >/dev/null; then
fatal "docker could not be found; please install and try again."
fi

## verify docker-compose meets version constraint
DOCKER_COMPOSE_REQUIRE="1.25.0"
DOCKER_COMPOSE_REQUIRE_V2="2.2.3"
DOCKER_COMPOSE_VERSION="$(docker-compose --version | grep -oE '[0-9\.]+' | head -n1)"
## 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)"
fi

if test $(version ${DOCKER_COMPOSE_VERSION}) -ge $(version "2.0.0") \
&& ! test $(version ${DOCKER_COMPOSE_VERSION}) -ge $(version ${DOCKER_COMPOSE_REQUIRE_V2})
then
fatal "docker-compose version should be ${DOCKER_COMPOSE_REQUIRE_V2} or higher (${DOCKER_COMPOSE_VERSION} installed)"
fatal "docker compose version should be ${DOCKER_COMPOSE_REQUIRE} or higher (${DOCKER_COMPOSE_VERSION} installed)"
fi

## define and export global shared directory paths
Expand Down
2 changes: 1 addition & 1 deletion commands/env-init.help
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WARDEN_USAGE=$(cat <<EOF
-h, --help Display this help menu
\033[33mEnvironment Types:\033[0m
local Declares the docker-compose version and labels the project
local Declares the docker compose version and labels the project
network allowing Warden to recognize it. Must be coupled with
per-project configuration. See documentation for details:
https://docs.warden.dev/environments/types.html#local
Expand Down
8 changes: 4 additions & 4 deletions commands/env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if [[ ${WARDEN_ENV_SUBT} == "linux" && $UID == 1000 ]]; then
export SSH_AUTH_SOCK_PATH_ENV=/run/host-services/ssh-auth.sock
fi

## configure docker-compose files
## configure docker compose files
DOCKER_COMPOSE_ARGS=()

appendEnvPartialIfExists "networks"
Expand Down 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 \
--project-directory "${WARDEN_ENV_PATH}" -p "${WARDEN_ENV_NAME}" \
"${DOCKER_COMPOSE_ARGS[@]}" up --no-start
fi
Expand Down Expand Up @@ -191,8 +191,8 @@ then
$WARDEN_BIN sync pause
fi

## pass ochestration through to docker-compose
docker-compose \
## pass ochestration through to docker compose
docker compose \
--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 "${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 -p warden -f "${WARDEN_DIR}/docker/docker-compose.yml" ps -q traefik)" ]]
then
echo "==> Updating traefik"
"$WARDEN_BIN" svc up traefik
Expand Down
6 changes: 3 additions & 3 deletions commands/svc.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi
## allow return codes from sub-process to bubble up normally
trap '' ERR

## configure docker-compose files
## configure docker compose files
DOCKER_COMPOSE_ARGS=()

DOCKER_COMPOSE_ARGS+=("-f")
Expand Down Expand Up @@ -86,8 +86,8 @@ if [[ "${WARDEN_PARAMS[0]}" == "up" ]]; then
fi
fi

## pass ochestration through to docker-compose
WARDEN_SERVICE_DIR=${WARDEN_DIR} docker-compose \
## pass ochestration through to docker compose
WARDEN_SERVICE_DIR=${WARDEN_DIR} docker compose \
--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 "${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
2 changes: 1 addition & 1 deletion commands/usage.help
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Warden version $(cat ${WARDEN_DIR}/version)
-h, --help Display this help menu
\033[33mCommands:\033[0m
svc Orchestrates global services such as traefik, portainer and dnsmasq via docker-compose
svc Orchestrates global services such as traefik, portainer and dnsmasq via docker compose
env-init Configure environment by adding '.env' file to the current working directory
env Controls an environment from any point within the root project directory
db Interacts with the db service on an environment (see 'warden db -h' for details)
Expand Down

0 comments on commit a32cb41

Please sign in to comment.