Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' for release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalger committed Jun 27, 2019
2 parents 422cc86 + fd4782f commit 612e30d
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 150 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.1.0
===============

* Changed the env type setup to automatically include additional configuration based on $OSTYPE.
* Changed the environment template structure to utilize per-OSTYPE docker-compose config additions where environments differ from one host OS to another (such as `magento2` env type, which uses plain mounts on `linux-gnu` but sync sessions on `darwin`)
* Fixed a few error messages so they won't change shell text color permanently when they output.
* Fixed sync command to output error message when any sub-command is run on an env lacking a mutagen configuration.

0.1.0-beta7
===============

Expand Down
11 changes: 3 additions & 8 deletions commands/env-init.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@ WARDEN_ENV_PATH="$(pwd)"
# TODO: Provide argument (and prompt user) for environment type instead of assuming magento2 flavors

WARDEN_ENV_NAME="${WARDEN_PARAMS[0]:-}"
WARDEN_ENV_CLASS="${WARDEN_PARAMS[1]:-magento2}"
WARDEN_ENV_TYPE="${WARDEN_PARAMS[1]:-magento2}"

# Require the user inputs the required environment name parameter
[[ ! ${WARDEN_ENV_NAME} ]] && >&2 echo -e "\033[31mMissing required argument. Please use --help to to print usage." && exit 1

# Set type for magento2 class to auto-select type when starting based on current OS type
WARDEN_ENV_TYPE=${WARDEN_ENV_CLASS}
[[ "${WARDEN_ENV_CLASS}" = "magento2" ]] \
&& WARDEN_ENV_TYPE='magento2-mutagen && [ "$OSTYPE" = "linux-gnu" ] && WARDEN_ENV_TYPE=magento2-native || true'

# Verify the auto-select and/or type path resolves correctly before setting it
[[ ! -f "${WARDEN_DIR}/environments/$(eval "WARDEN_ENV_TYPE=${WARDEN_ENV_TYPE}"; echo ${WARDEN_ENV_TYPE}).yml" ]] \
[[ ! -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.base.yml" ]] \
&& >&2 echo -e "\033[31mInvalid environment type \"${WARDEN_ENV_TYPE}\" specified." && exit 1

# Write the .env file to current working directory
cat > "${WARDEN_ENV_PATH}/.env" <<EOF
WARDEN_ENV_NAME=${WARDEN_ENV_NAME}
WARDEN_ENV_TYPE=${WARDEN_ENV_TYPE}
TRAEFIK_DOMAIN=${WARDEN_ENV_NAME}.test
TRAEFIK_SUBDOMAIN=${WARDEN_ENV_CLASS}
TRAEFIK_SUBDOMAIN=${WARDEN_ENV_TYPE}
EOF
10 changes: 7 additions & 3 deletions commands/env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ fi
trap '' ERR

## configure docker-compose files
DOCKER_COMPOSE_ARGS=-f\ "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.yml"
DOCKER_COMPOSE_ARGS=-f\ "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.base.yml"

if [[ -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.${WARDEN_ENV_SUBT}.yml" ]]; then
DOCKER_COMPOSE_ARGS+=\ -f\ "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.${WARDEN_ENV_SUBT}.yml"
fi

if [[ -f "${WARDEN_ENV_PATH}/.warden/warden-env.yml" ]]; then
DOCKER_COMPOSE_ARGS+=\ -f\ "${WARDEN_ENV_PATH}/.warden/warden-env.yml"
fi

if [[ -f "${WARDEN_ENV_PATH}/.warden/warden-env.${WARDEN_ENV_TYPE}.yml" ]]; then
DOCKER_COMPOSE_ARGS+=\ -f\ "${WARDEN_ENV_PATH}/.warden/warden-env.${WARDEN_ENV_TYPE}.yml"
if [[ -f "${WARDEN_ENV_PATH}/.warden/warden-env.${WARDEN_ENV_SUBT}.yml" ]]; then
DOCKER_COMPOSE_ARGS+=\ -f\ "${WARDEN_ENV_PATH}/.warden/warden-env.${WARDEN_ENV_SUBT}.yml"
fi

## anything not caught above is simply passed through to docker-compose to orchestrate
Expand Down
20 changes: 14 additions & 6 deletions commands/sync.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ WARDEN_ENV_PATH="$(locateEnvPath)" || exit $?
loadEnvConfig "${WARDEN_ENV_PATH}" || exit $?

if (( ${#WARDEN_PARAMS[@]} == 0 )); then
echo -e "\033[33mThis command has required params, please use --help for details."
echo -e "\033[33mThis command has required params, please use --help for details.\033[0m"
exit 1
fi

## disable sync command on non-darwin environments where it should not be used
if [[ ${WARDEN_ENV_SUBT} != "darwin" ]]; then
>&2 echo -e "\033[31mMutagen sync sessions are not used on \"${WARDEN_ENV_SUBT}\" host environments\033[0m"
exit 1
fi

Expand All @@ -16,21 +22,23 @@ if ! which mutagen >/dev/null; then
brew install havoc-io/mutagen/mutagen
fi

## if no mutagen configuration file exists for the environment type, exit with error
if [[ ! -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.mutagen.toml" ]]; then
>&2 echo -e "\033[31mMutagen configuration does not exist for environment type \"${WARDEN_ENV_TYPE}\"\033[0m"
exit 1
fi

## sub-command execution
case "${WARDEN_PARAMS[0]}" in
start)
## if no mutagen configuration file exists for the environment type, exit with error
[[ ! -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.toml" ]] \
&& >&2 echo -e "\033[31mMutagen configuration does not exist for environment type \"${WARDEN_ENV_TYPE}\"" && exit 1

## start mutagen daemon if not already running
mutagen daemon start

## terminate any existing sessions with matching env label
mutagen terminate --label-selector "warden-sync=${WARDEN_ENV_NAME}"

## create sync session based on environment type configuration
mutagen create -c "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.toml" \
mutagen create -c "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.mutagen.toml" \
--label "warden-sync=${WARDEN_ENV_NAME}" \
"${WARDEN_ENV_PATH}${WARDEN_WEB_ROOT:-}" "docker://$(warden env ps -q php-fpm)/var/www/html"

Expand Down
2 changes: 1 addition & 1 deletion commands/usage.help
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ WARDEN_HEADER='

WARDEN_USAGE=$(cat <<EOF
${WARDEN_HEADER:1}
Warden version 0.1.0-beta7
Warden version 0.1.0
\033[33mUsage:\033[0m
command [options] [arguments]
Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions environments/magento1.yml → environments/magento1.base.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
version: "3"

version: "3.5"
services:

nginx:
hostname: nginx
image: davidalger/warden:nginx-${NGINX_VERSION:-1.16}-alpine
environment:
- NGINX_TEMPLATE=magento1.conf
- XDEBUG_CONNECT_BACK_HOST=${XDEBUG_CONNECT_BACK_HOST:-host.docker.internal}
depends_on:
- db
- php-fpm
Expand Down
5 changes: 5 additions & 0 deletions environments/magento1.darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: "3.5"
services:
nginx:
environment:
- XDEBUG_CONNECT_BACK_HOST=${XDEBUG_CONNECT_BACK_HOST:-host.docker.internal}
115 changes: 0 additions & 115 deletions environments/magento2-mutagen.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
version: "3.5"

services:

nginx:
hostname: nginx
image: davidalger/warden:nginx-${NGINX_VERSION:-1.16}-alpine
depends_on:
- db
- php-fpm
volumes:
- .${WARDEN_WEB_ROOT:-}/:/var/www/html:delegated

varnish:
hostname: varnish
Expand All @@ -28,9 +24,6 @@ services:
image: davidalger/warden:mage2-fpm-${PHP_VERSION:-7.2}-alpine
depends_on:
- db
volumes:
- ~/.composer:/home/www-data/.composer:delegated
- .${WARDEN_WEB_ROOT:-}/:/var/www/html:delegated

php-debug:
hostname: php-debug
Expand All @@ -39,9 +32,6 @@ services:
- PHP_IDE_CONFIG=serverName=${WARDEN_ENV_NAME}-docker
depends_on:
- db
volumes:
- ~/.composer:/home/www-data/.composer:delegated
- .${WARDEN_WEB_ROOT:-}/:/var/www/html:delegated

db:
hostname: mariadb
Expand Down
23 changes: 23 additions & 0 deletions environments/magento2.darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.5"
services:
nginx:
environment:
- XDEBUG_CONNECT_BACK_HOST=${XDEBUG_CONNECT_BACK_HOST:-host.docker.internal}
volumes:
- .${WARDEN_WEB_ROOT:-}/pub/media:/var/www/html/pub/media:delegated
- appdata:/var/www/html

php-fpm:
volumes:
- ~/.composer:/home/www-data/.composer:delegated
- .${WARDEN_WEB_ROOT:-}/pub/media:/var/www/html/pub/media:delegated
- appdata:/var/www/html

php-debug:
volumes:
- ~/.composer:/home/www-data/.composer:delegated
- .${WARDEN_WEB_ROOT:-}/pub/media:/var/www/html/pub/media:delegated
- appdata:/var/www/html

volumes:
appdata:
15 changes: 15 additions & 0 deletions environments/magento2.linux-gnu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.5"
services:
nginx:
volumes:
- .${WARDEN_WEB_ROOT:-}/:/var/www/html

php-fpm:
volumes:
- ~/.composer:/home/www-data/.composer
- .${WARDEN_WEB_ROOT:-}/:/var/www/html

php-debug:
volumes:
- ~/.composer:/home/www-data/.composer
- .${WARDEN_WEB_ROOT:-}/:/var/www/html
File renamed without changes.
11 changes: 8 additions & 3 deletions utils/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function locateEnvPath () {
done

if [[ "${WARDEN_ENV_PATH}" = "/" ]]; then
>&2 echo -e "\033[31mEnvironment config could not be found. Please run \"warden env-init\" and try again!"
>&2 echo -e "\033[31mEnvironment config could not be found. Please run \"warden env-init\" and try again!\033[0m"
return 1
fi

Expand All @@ -28,8 +28,13 @@ function loadEnvConfig () {
WARDEN_ENV_NAME="${WARDEN_ENV_NAME:-}"
WARDEN_ENV_TYPE="${WARDEN_ENV_TYPE:-}"

if [[ ! -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.yml" ]]; then
>&2 echo -e "\033[31mInvalid environment type \"${WARDEN_ENV_TYPE}\" specified."
WARDEN_ENV_SUBT="${OSTYPE:-undefined}"
if [[ ${WARDEN_ENV_SUBT} =~ ^darwin ]]; then
WARDEN_ENV_SUBT=darwin
fi

if [[ ! -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.base.yml" ]]; then
>&2 echo -e "\033[31mInvalid environment type \"${WARDEN_ENV_TYPE}\" specified.\033[0m"
return 1
fi
}

0 comments on commit 612e30d

Please sign in to comment.