Skip to content

Commit

Permalink
Merge branch 'wardenenv:main' into pimcore-env
Browse files Browse the repository at this point in the history
  • Loading branch information
dudzio12 authored Nov 21, 2023
2 parents 5b62f8b + 9548566 commit 0fb08c6
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 23 deletions.
22 changes: 19 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
# Change Log

## 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)
[All Commits](https://github.com/davidalger/warden/compare/0.14.1..main)

**Enhancements:**
* Project and Local Warden commands will now take precedence over built-in warden commands ([#676](https://github.com/wardenenv/warden/pull/676) by @flpandre)

## Version [0.14.1](https://github.com/wardenenv/warden/tree/0.14.1) (2023-07-10)
[All Commits](https://github.com/wardenenv/warden/compoare/0.14.0..0.14.1)

**Enhancements:**
* `warden status` command added that shows running Warden environments ([#669](https://github.com/wardenenv/warden/pull/669) by @bap14)

**Bug Fixes:**
* Updated Mutagen connection detection so that Mutagen doesn't resync every time in versions >= 0.15.0

## Version [0.14.0](https://github.com/wardenenv/warden/tree/0.14.0) (2023-06-19)
[All Commits](https://github.com/wardenenv/warden/compare/0.13.1..0.14.0)

**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).
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). This is configured through the environment variable `DOCKER_COMPOSE_COMMAND` which defaults to `docker compose`.

**Enhancements**
* ElasticSearch 8.7 images are available
* ElasticSearch 8.7 and 8.8 images are available
* Drupal environment type added ([#646](https://github.com/wardenenv/warden/pull/646) by @bap14)

## Version [0.13.1](https://github.com/wardenenv/warden/tree/0.13.1) (2023-03-21)
[All Commits](https://github.com/wardenenv/warden/compare/0.13.0..0.13.1)
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,24 @@ All contributions to the Warden project are welcome: use-cases, documentation, c

Please note that by submitting a pull request or otherwise contributing to the Warden project, you warrant that each of your contributions is an original work and that you have full authority to grant rights to said contribution and by so doing you grant the owners of the Warden project, and those who receive the contribution directly or indirectly, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license to make, have made, use, offer to sell, sell and import or otherwise dispose of the contributions alone or with the Warden project in it's entirety.

## Where to Contribute

* [warden](https://github.com/wardenenv/warden) - `warden` commands and docker-compose files
* [images](https://github.com/wardenenv/images) - Docker images to be used by the docker-compose files
* [docs](https://github.com/wardenenv/docs) - Documentation (docs.warden.dev)
* [homebrew-warden](https://github.com/wardenenv/homebrew-warden) - Mac's Homebrew installation instructions and requirements

## License

This work is licensed under the MIT license. See [LICENSE](https://github.com/davidalger/warden/blob/develop/LICENSE) file for details.

## Author Information

This project was started in 2019 by [David Alger](https://davidalger.com/).

# Gold Sponsors
[![SwiftOtter](https://warden.dev/img/sponsors/swiftotter.svg)](https://www.swiftotter.com/)
[![Sansec.io](https://warden.dev/img/sponsors/sansec.svg)](https://www.sansec.io/)
[![Hyvä](https://user-images.githubusercontent.com/145128/226427529-53483968-c9ab-484a-9ae3-c6abb58f81c9.png)](https://www.hyva.io/)

Support Warden Development on <a href="https://opencollective.com/warden" rel="me" class="link">OpenCollective</a> or <a href="https://github.com/sponsors/wardenenv" rel="me" class="link">Github Sponsors</a>
12 changes: 6 additions & 6 deletions bin/warden
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ if (( "$#" )); then
## local project directory if running within one; don't fail if it can't be found
WARDEN_ENV_PATH="$(locateEnvPath 2>/dev/null)" || true

if [[ -f "${WARDEN_DIR}/commands/${1}.cmd" ]]; then
WARDEN_CMD_VERB="$1"
WARDEN_CMD_EXEC="${WARDEN_DIR}/commands/${1}.cmd"
WARDEN_CMD_HELP="${WARDEN_DIR}/commands/${1}.help"
shift
elif [[ -f "${WARDEN_ENV_PATH}/.warden/commands/${1}.cmd" ]]; then
if [[ -f "${WARDEN_ENV_PATH}/.warden/commands/${1}.cmd" ]]; then
WARDEN_CMD_VERB="$1"
WARDEN_CMD_ANYARGS+=("$1")
WARDEN_CMD_EXEC="${WARDEN_ENV_PATH}/.warden/commands/${1}.cmd"
Expand All @@ -69,6 +64,11 @@ if (( "$#" )); then
WARDEN_CMD_EXEC="${WARDEN_HOME_DIR}/commands/${1}.cmd"
WARDEN_CMD_HELP="${WARDEN_HOME_DIR}/commands/${1}.help"
shift
elif [[ -f "${WARDEN_DIR}/commands/${1}.cmd" ]]; then
WARDEN_CMD_VERB="$1"
WARDEN_CMD_EXEC="${WARDEN_DIR}/commands/${1}.cmd"
WARDEN_CMD_HELP="${WARDEN_DIR}/commands/${1}.help"
shift
else
WARDEN_HELP=1
fi
Expand Down
39 changes: 25 additions & 14 deletions commands/env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ loadEnvConfig "${WARDEN_ENV_PATH}" || exit $?
assertDockerRunning

if (( ${#WARDEN_PARAMS[@]} == 0 )) || [[ "${WARDEN_PARAMS[0]}" == "help" ]]; then
# shellcheck disable=SC2153
$WARDEN_BIN env --help || exit $? && exit $?
fi

Expand All @@ -14,7 +15,7 @@ trap '' ERR

## define source repository
if [[ -f "${WARDEN_HOME_DIR}/.env" ]]; then
eval "$(cat "${WARDEN_HOME_DIR}/.env" | sed 's/\r$//g' | grep "^WARDEN_")"
eval "$(sed 's/\r$//g' < "${WARDEN_HOME_DIR}/.env" | grep "^WARDEN_")"
fi
export WARDEN_IMAGE_REPOSITORY="${WARDEN_IMAGE_REPOSITORY:-"docker.io/wardenenv"}"

Expand Down Expand Up @@ -43,7 +44,8 @@ fi
export CHOWN_DIR_LIST=${WARDEN_CHOWN_DIR_LIST:-}

if [[ ${WARDEN_ENV_TYPE} == "magento1" && -f "${WARDEN_ENV_PATH}/.modman/.basedir" ]]; then
export NGINX_PUBLIC='/'$(cat "${WARDEN_ENV_PATH}/.modman/.basedir")
NGINX_PUBLIC='/'$(cat "${WARDEN_ENV_PATH}/.modman/.basedir")
export NGINX_PUBLIC
fi

if [[ ${WARDEN_ENV_TYPE} == "magento2" ]]; then
Expand Down Expand Up @@ -161,12 +163,13 @@ if [[ "${WARDEN_PARAMS[0]}" == "up" ]]; then
fi

## lookup address of traefik container on environment network
export TRAEFIK_ADDRESS="$(docker container inspect traefik \
TRAEFIK_ADDRESS="$(docker container inspect traefik \
--format '
{{- $network := index .NetworkSettings.Networks "'"$(renderEnvNetworkName)"'" -}}
{{- if $network }}{{ $network.IPAddress }}{{ end -}}
' 2>/dev/null || true
)"
export TRAEFIK_ADDRESS;

if [[ $OSTYPE =~ ^darwin ]]; then
export MUTAGEN_SYNC_FILE="${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}/${WARDEN_ENV_TYPE}.mutagen.yml"
Expand All @@ -191,30 +194,38 @@ then
$WARDEN_BIN sync pause
fi

## pass ochestration through to docker compose
## pass orchestration through to docker compose
${DOCKER_COMPOSE_COMMAND} \
--project-directory "${WARDEN_ENV_PATH}" -p "${WARDEN_ENV_NAME}" \
"${DOCKER_COMPOSE_ARGS[@]}" "${WARDEN_PARAMS[@]}" "$@"

## resume mutagen sync if available and php-fpm container id hasn't changed
if ([[ "${WARDEN_PARAMS[0]}" == "up" ]] || [[ "${WARDEN_PARAMS[0]}" == "start" ]]) \
if { [[ "${WARDEN_PARAMS[0]}" == "up" ]] || [[ "${WARDEN_PARAMS[0]}" == "start" ]]; } \
&& [[ $OSTYPE =~ ^darwin ]] && [[ -f "${MUTAGEN_SYNC_FILE}" ]] \
&& [[ $($WARDEN_BIN sync list | grep -i 'Status: \[Paused\]' | wc -l | awk '{print $1}') == "1" ]] \
&& [[ $($WARDEN_BIN sync list | grep -ci 'Status: \[Paused\]' | awk '{print $1}') == "1" ]] \
&& [[ $($WARDEN_BIN env ps -q php-fpm) ]] \
&& [[ $(docker container inspect $($WARDEN_BIN env ps -q php-fpm) --format '{{ .State.Status }}') = "running" ]] \
&& [[ $(docker container inspect "$($WARDEN_BIN env ps -q php-fpm)" --format '{{ .State.Status }}') = "running" ]] \
&& [[ $($WARDEN_BIN env ps -q php-fpm) = $($WARDEN_BIN sync list | grep -i 'URL: docker' | awk -F'/' '{print $3}') ]]
then
$WARDEN_BIN sync resume
fi

## start mutagen sync if needed
if ([[ "${WARDEN_PARAMS[0]}" == "up" ]] || [[ "${WARDEN_PARAMS[0]}" == "start" ]]) \
&& [[ $OSTYPE =~ ^darwin ]] && [[ -f "${MUTAGEN_SYNC_FILE}" ]] \
&& [[ $($WARDEN_BIN sync list | grep -i 'Connection state: Connected' | wc -l | awk '{print $1}') != "2" ]] \
&& [[ $($WARDEN_BIN env ps -q php-fpm) ]] \
&& [[ $(docker container inspect $($WARDEN_BIN env ps -q php-fpm) --format '{{ .State.Status }}') = "running" ]]
if [[ $OSTYPE =~ ^darwin ]] && [[ -f "${MUTAGEN_SYNC_FILE}" ]] # If we're using Mutagen
then
$WARDEN_BIN sync start
MUTAGEN_VERSION=$(mutagen version)
CONNECTION_STATE_STRING='Connected state: Connected'
if [[ $(version "${MUTAGEN_VERSION}") -ge $(version '0.15.0') ]]; then
CONNECTION_STATE_STRING='Connected: Yes'
fi

## start mutagen sync if needed
if { [[ "${WARDEN_PARAMS[0]}" == "up" ]] || [[ "${WARDEN_PARAMS[0]}" == "start" ]]; } \
&& [[ $($WARDEN_BIN sync list | grep -c "${CONNECTION_STATE_STRING}" | awk '{print $1}') != "2" ]] \
&& [[ $($WARDEN_BIN env ps -q php-fpm) ]] \
&& [[ $(docker container inspect "$($WARDEN_BIN env ps -q php-fpm)" --format '{{ .State.Status }}') = "running" ]]
then
$WARDEN_BIN sync start
fi
fi

## stop mutagen sync if needed
Expand Down
60 changes: 60 additions & 0 deletions commands/status.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
[[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1

assertDockerRunning

wardenNetworkName=$(cat ${WARDEN_DIR}/docker/docker-compose.yml | grep -A3 'networks:' | tail -n1 | sed -e 's/[[:blank:]]*name:[[:blank:]]*//g')
wardenNetworkId=$(docker network ls -q --filter name="${wardenNetworkName}")

if [[ -z "${wardenNetworkId}" ]]; then
echo -e "[\033[33;1m!!\033[0m] \033[31mWarden is not currently running.\033[0m Run \033[36mwarden svc up\033[0m to start Warden core services."
fi

OLDIFS="$IFS";
IFS=$'\n'
projectNetworkList=( $(docker network ls --format '{{.Name}}' -q --filter "label=dev.warden.environment.name") )
IFS="$OLDIFS"

messageList=()
for projectNetwork in "${projectNetworkList[@]}"; do
# Skip empty names and the Warden core services network
test -z "${projectNetwork}" -o "${projectNetwork}" = "${wardenNetworkName}" && continue

prefix="${projectNetwork%_default}"
prefixLen="${#prefix}"
((prefixLen+=1))
projectContainers=$(docker network inspect --format '{{ range $k,$v := .Containers }}{{ $nameLen := len $v.Name }}{{ if gt $nameLen '"${prefixLen}"' }}{{ $prefix := slice $v.Name 0 '"${prefixLen}"' }}{{ if eq $prefix "'"${prefix}-"'" }}{{ println $v.Name }}{{end}}{{end}}{{end}}' "${projectNetwork}")
container=$(echo "$projectContainers" | head -n1)

[[ -z "${container}" ]] && continue # Project is not running, skip it

projectDir=$(docker container inspect --format '{{ index .Config.Labels "com.docker.compose.project.working_dir"}}' "$container")
projectName=$(cat "${projectDir}/.env" | grep '^WARDEN_ENV_NAME=' | sed -e 's/WARDEN_ENV_NAME=[[:space:]]*//g')
projectType=$(cat "${projectDir}/.env" | grep '^WARDEN_ENV_TYPE=' | sed -e 's/WARDEN_ENV_TYPE=[[:space:]]*//g')
traefikDomain=$(cat "${projectDir}/.env" | grep '^TRAEFIK_DOMAIN=' | sed -e 's/TRAEFIK_DOMAIN=[[:space:]]*//g')
traefikSubdomain=$(cat "${projectDir}/.env" | grep '^TRAEFIK_SUBDOMAIN=' | sed -e 's/TRAEFIK_SUBDOMAIN=[[:space:]]*//g')

fullDomain="${traefikDomain}"
if test -n "${traefikSubdomain}"; then
fullDomain="${traefikSubdomain}.${traefikDomain}"
fi

messageList+=(" \033[1;35m${projectName}\033[0m a \033[36m${projectType}\033[0m project")
messageList+=(" Project Directory: \033[33m${projectDir}\033[0m")
messageList+=(" Project URL: \033[94mhttps://${fullDomain}\033[0m")

[[ "$projectNetwork" != "${projectNetworkList[@]: -1:1}" ]] && messageList+=()
done

if [[ "${#messageList[@]}" > 0 ]]; then
if [[ -z "${wardenNetworkId}" ]]; then
echo -e "Found the following \033[32mrunning\033[0m projects; however, \033[31mWarden core services are currently not running\033[0m:"
else
echo -e "Found the following \033[32mrunning\033[0m environments:"
fi
for line in "${messageList[@]}"; do
echo -e "$line"
done
else
echo "No running environments found."
fi
4 changes: 4 additions & 0 deletions commands/status.help
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
[[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1

WARDEN_USAGE="Provides listing of projects that are currently running that Warden has been used to start"
1 change: 1 addition & 0 deletions commands/usage.help
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Warden version $(cat ${WARDEN_DIR}/version)
redis Interacts with the redis service on an environment (see 'warden redis -h' for details)
install Initializes or updates warden configuration on host machine
shell Launches into a shell within the current project environment
status Display list of all running Warden project environments
debug Launches debug enabled shell within current project environment
sign-certificate Signs a wildcard certificate including all passed hostnames on the SAN list
version Show version information
Expand Down

0 comments on commit 0fb08c6

Please sign in to comment.