From 833a33eb56290dc3d092acbc46fb13c3313dfc8e Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 27 Jun 2019 09:06:21 -0500 Subject: [PATCH 1/7] Changed the env type setup to automatically include additional configuration based on $OSTYPE --- commands/env-init.cmd | 11 +- commands/env.cmd | 10 +- commands/sync.cmd | 2 +- environments/{local.yml => local.base.yml} | 0 .../{magento1.yml => magento1.base.yml} | 5 +- environments/magento1.darwin.yml | 5 + environments/magento2-mutagen.yml | 115 ------------------ ...{magento2-native.yml => magento2.base.yml} | 10 -- environments/magento2.darwin.yml | 23 ++++ environments/magento2.linux-gnu.yml | 15 +++ ...to2-mutagen.toml => magento2.mutagen.toml} | 0 utils/env.sh | 7 +- 12 files changed, 61 insertions(+), 142 deletions(-) rename environments/{local.yml => local.base.yml} (100%) rename environments/{magento1.yml => magento1.base.yml} (94%) create mode 100644 environments/magento1.darwin.yml delete mode 100644 environments/magento2-mutagen.yml rename environments/{magento2-native.yml => magento2.base.yml} (88%) create mode 100644 environments/magento2.darwin.yml create mode 100644 environments/magento2.linux-gnu.yml rename environments/{magento2-mutagen.toml => magento2.mutagen.toml} (100%) diff --git a/commands/env-init.cmd b/commands/env-init.cmd index 2fbf3a87..059b73be 100644 --- a/commands/env-init.cmd +++ b/commands/env-init.cmd @@ -7,18 +7,13 @@ 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 @@ -26,5 +21,5 @@ cat > "${WARDEN_ENV_PATH}/.env" <&2 echo -e "\033[31mMutagen configuration does not exist for environment type \"${WARDEN_ENV_TYPE}\"" && exit 1 ## start mutagen daemon if not already running diff --git a/environments/local.yml b/environments/local.base.yml similarity index 100% rename from environments/local.yml rename to environments/local.base.yml diff --git a/environments/magento1.yml b/environments/magento1.base.yml similarity index 94% rename from environments/magento1.yml rename to environments/magento1.base.yml index ad5c8660..26592774 100644 --- a/environments/magento1.yml +++ b/environments/magento1.base.yml @@ -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 diff --git a/environments/magento1.darwin.yml b/environments/magento1.darwin.yml new file mode 100644 index 00000000..63e6c418 --- /dev/null +++ b/environments/magento1.darwin.yml @@ -0,0 +1,5 @@ +version: "3.5" +services: + nginx: + environment: + - XDEBUG_CONNECT_BACK_HOST=${XDEBUG_CONNECT_BACK_HOST:-host.docker.internal} diff --git a/environments/magento2-mutagen.yml b/environments/magento2-mutagen.yml deleted file mode 100644 index ad5b5e36..00000000 --- a/environments/magento2-mutagen.yml +++ /dev/null @@ -1,115 +0,0 @@ -version: "3.5" - -services: - - nginx: - hostname: nginx - image: davidalger/warden:nginx-${NGINX_VERSION:-1.16}-alpine - environment: - - XDEBUG_CONNECT_BACK_HOST=${XDEBUG_CONNECT_BACK_HOST:-host.docker.internal} - depends_on: - - db - - php-fpm - volumes: - - .${WARDEN_WEB_ROOT:-}/pub/media:/var/www/html/pub/media:delegated - - appdata:/var/www/html - - varnish: - hostname: varnish - image: davidalger/warden:varnish-${VARNISH_VERSION:-4.1}-alpine - depends_on: - - nginx - labels: - - traefik.enable=true - - traefik.frontend.rule=Host:${TRAEFIK_SUBDOMAIN:-www}.${TRAEFIK_DOMAIN} - networks: - - warden - - default - - php-fpm: - hostname: php-fpm - image: davidalger/warden:mage2-fpm-${PHP_VERSION:-7.2}-alpine - depends_on: - - db - volumes: - - ~/.composer:/home/www-data/.composer:delegated - - .${WARDEN_WEB_ROOT:-}/pub/media:/var/www/html/pub/media:delegated - - appdata:/var/www/html - - php-debug: - hostname: php-debug - image: davidalger/warden:mage2-fpm-${PHP_VERSION:-7.2}-debug-alpine - environment: - - PHP_IDE_CONFIG=serverName=${WARDEN_ENV_NAME}-docker - depends_on: - - db - volumes: - - ~/.composer:/home/www-data/.composer:delegated - - .${WARDEN_WEB_ROOT:-}/pub/media:/var/www/html/pub/media:delegated - - appdata:/var/www/html - - db: - hostname: mariadb - image: mariadb:${MARIADB_VERSION:-10.3} - environment: - - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-magento} - - MYSQL_DATABASE=${MYSQL_DATABASE:-magento} - - MYSQL_USER=${MYSQL_USER:-magento} - - MYSQL_PASSWORD=${MYSQL_PASSWORD:-magento} - volumes: - - dbdata:/var/lib/mysql - networks: - - warden - - default - - elasticsearch: - hostname: elasticsearch - image: davidalger/warden:elasticsearch-${ELASTICSEARCH_VERSION:-5.6} - labels: - - traefik.enable=true - - traefik.port=9200 - - traefik.frontend.rule=Host:elasticsearch.${TRAEFIK_DOMAIN} - environment: - - discovery.type=single-node - - xpack.security.enabled=false - - "ES_JAVA_OPTS=-Xms64m -Xmx512m" - volumes: - - esdata:/usr/share/elasticsearch/data - networks: - - warden - - default - - redis: - hostname: redis - image: redis:${REDIS_VERSION:-5.0}-alpine - - rabbitmq: - hostname: rabbitmq - image: rabbitmq:${RABBITMQ_VERSION:-3.7.14}-management-alpine - labels: - - traefik.enable=true - - traefik.port=15672 - - traefik.frontend.rule=Host:rabbitmq.${TRAEFIK_DOMAIN} - networks: - - warden - - default - - mailhog: - hostname: mailhog - image: mailhog/mailhog:${MAILHOG_VERSION:-v1.0.0} - labels: - - traefik.enable=true - - traefik.port=8025 - - traefik.frontend.rule=Host:mailhog.${TRAEFIK_DOMAIN} - networks: - - warden - - default - -volumes: - appdata: - dbdata: - esdata: - -networks: - warden: - external: true diff --git a/environments/magento2-native.yml b/environments/magento2.base.yml similarity index 88% rename from environments/magento2-native.yml rename to environments/magento2.base.yml index d6f59a41..6996b203 100644 --- a/environments/magento2-native.yml +++ b/environments/magento2.base.yml @@ -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 @@ -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 @@ -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 diff --git a/environments/magento2.darwin.yml b/environments/magento2.darwin.yml new file mode 100644 index 00000000..83d82c33 --- /dev/null +++ b/environments/magento2.darwin.yml @@ -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: diff --git a/environments/magento2.linux-gnu.yml b/environments/magento2.linux-gnu.yml new file mode 100644 index 00000000..29e3f495 --- /dev/null +++ b/environments/magento2.linux-gnu.yml @@ -0,0 +1,15 @@ +version: "3.5" +services: + nginx: + volumes: + - .${WARDEN_WEB_ROOT:-}/:/var/www/html:delegated + + php-fpm: + volumes: + - ~/.composer:/home/www-data/.composer:delegated + - .${WARDEN_WEB_ROOT:-}/:/var/www/html:delegated + + php-debug: + volumes: + - ~/.composer:/home/www-data/.composer:delegated + - .${WARDEN_WEB_ROOT:-}/:/var/www/html:delegated diff --git a/environments/magento2-mutagen.toml b/environments/magento2.mutagen.toml similarity index 100% rename from environments/magento2-mutagen.toml rename to environments/magento2.mutagen.toml diff --git a/utils/env.sh b/utils/env.sh index c04ef41c..b4a24b8d 100644 --- a/utils/env.sh +++ b/utils/env.sh @@ -28,7 +28,12 @@ function loadEnvConfig () { WARDEN_ENV_NAME="${WARDEN_ENV_NAME:-}" WARDEN_ENV_TYPE="${WARDEN_ENV_TYPE:-}" - if [[ ! -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.yml" ]]; then + 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." return 1 fi From 10b88b30849ba1d81bad29c0d80922aca6c9cd04 Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 27 Jun 2019 09:17:27 -0500 Subject: [PATCH 2/7] Fixed warden sync command to output error when any sub-command is run on an env type lacking a mutagen configuration --- commands/sync.cmd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/sync.cmd b/commands/sync.cmd index 68f4261a..8edc7eeb 100644 --- a/commands/sync.cmd +++ b/commands/sync.cmd @@ -16,13 +16,13 @@ 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 +[[ ! -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.mutagen.toml" ]] \ + && >&2 echo -e "\033[31mMutagen configuration does not exist for environment type \"${WARDEN_ENV_TYPE}\"" && exit 1 + ## 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}.mutagen.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 From 710e1cb600acfeab33396bcf5bf73cb23032fe2f Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 27 Jun 2019 09:21:13 -0500 Subject: [PATCH 3/7] Fixed incorrect file reference in sync start command --- commands/sync.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/sync.cmd b/commands/sync.cmd index 8edc7eeb..96e064c3 100644 --- a/commands/sync.cmd +++ b/commands/sync.cmd @@ -30,7 +30,7 @@ case "${WARDEN_PARAMS[0]}" in 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" From 74b56612abac49401b75e919367a3b1e7fe1ac0a Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 27 Jun 2019 09:28:42 -0500 Subject: [PATCH 4/7] Removed delegated annotations from linux-gnu specific config --- environments/magento2.linux-gnu.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/environments/magento2.linux-gnu.yml b/environments/magento2.linux-gnu.yml index 29e3f495..bf6f259b 100644 --- a/environments/magento2.linux-gnu.yml +++ b/environments/magento2.linux-gnu.yml @@ -2,14 +2,14 @@ version: "3.5" services: nginx: volumes: - - .${WARDEN_WEB_ROOT:-}/:/var/www/html:delegated + - .${WARDEN_WEB_ROOT:-}/:/var/www/html php-fpm: volumes: - - ~/.composer:/home/www-data/.composer:delegated - - .${WARDEN_WEB_ROOT:-}/:/var/www/html:delegated + - ~/.composer:/home/www-data/.composer + - .${WARDEN_WEB_ROOT:-}/:/var/www/html php-debug: volumes: - - ~/.composer:/home/www-data/.composer:delegated - - .${WARDEN_WEB_ROOT:-}/:/var/www/html:delegated + - ~/.composer:/home/www-data/.composer + - .${WARDEN_WEB_ROOT:-}/:/var/www/html From 4702786371a41c2f0060e78aa6b8cde75456f75e Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 27 Jun 2019 09:33:22 -0500 Subject: [PATCH 5/7] Fixed a few error messages so they won't change shell text color permanently when they output --- commands/sync.cmd | 2 +- utils/env.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/sync.cmd b/commands/sync.cmd index 96e064c3..18ae7251 100644 --- a/commands/sync.cmd +++ b/commands/sync.cmd @@ -6,7 +6,7 @@ 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 diff --git a/utils/env.sh b/utils/env.sh index b4a24b8d..be9762d8 100644 --- a/utils/env.sh +++ b/utils/env.sh @@ -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 @@ -34,7 +34,7 @@ function loadEnvConfig () { fi if [[ ! -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.base.yml" ]]; then - >&2 echo -e "\033[31mInvalid environment type \"${WARDEN_ENV_TYPE}\" specified." + >&2 echo -e "\033[31mInvalid environment type \"${WARDEN_ENV_TYPE}\" specified.\033[0m" return 1 fi } From e9474e444ba2bc71af1bb5df3727546bcb69260a Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 27 Jun 2019 09:37:00 -0500 Subject: [PATCH 6/7] Added error message to sync command if attempting to use it on non-darwin host environments --- commands/sync.cmd | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/commands/sync.cmd b/commands/sync.cmd index 18ae7251..e0a5dd18 100644 --- a/commands/sync.cmd +++ b/commands/sync.cmd @@ -10,6 +10,12 @@ if (( ${#WARDEN_PARAMS[@]} == 0 )); then 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 + ## attempt to install mutagen if not already present if ! which mutagen >/dev/null; then echo -e "\033[33mMutagen could not be found; attempting install via brew.\033[0m" @@ -17,8 +23,10 @@ if ! which mutagen >/dev/null; then fi ## if no mutagen configuration file exists for the environment type, exit with error -[[ ! -f "${WARDEN_DIR}/environments/${WARDEN_ENV_TYPE}.mutagen.toml" ]] \ - && >&2 echo -e "\033[31mMutagen configuration does not exist for environment type \"${WARDEN_ENV_TYPE}\"" && exit 1 +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 From fd4782f7bfdf6deb7e2929c6a7d1f559d871deef Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 27 Jun 2019 09:41:33 -0500 Subject: [PATCH 7/7] Updated CL --- CHANGELOG.md | 8 ++++++++ commands/usage.help | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 607a5102..6824a2d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 =============== diff --git a/commands/usage.help b/commands/usage.help index efc93b32..93326356 100755 --- a/commands/usage.help +++ b/commands/usage.help @@ -11,7 +11,7 @@ WARDEN_HEADER=' WARDEN_USAGE=$(cat <