From c6ef71c2f73dd45ebcbb7aa2eb5daf81d173480b Mon Sep 17 00:00:00 2001 From: Leandro Augusto Date: Thu, 18 Feb 2021 13:17:24 -0300 Subject: [PATCH] Initial commit --- .env | 36 ++++ .gitignore | 28 +++ .vscode/launch.json | 14 ++ .warden/commands/bootstrap.cmd | 321 +++++++++++++++++++++++++++++++ .warden/commands/bootstrap.help | 30 +++ README.md | 67 +++++++ backfill/.gitkeep | 0 webroot/app/etc/env.php.init.php | 124 ++++++++++++ 8 files changed, 620 insertions(+) create mode 100644 .env create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .warden/commands/bootstrap.cmd create mode 100644 .warden/commands/bootstrap.help create mode 100644 README.md create mode 100644 backfill/.gitkeep create mode 100644 webroot/app/etc/env.php.init.php diff --git a/.env b/.env new file mode 100644 index 0000000..8e020d5 --- /dev/null +++ b/.env @@ -0,0 +1,36 @@ +WARDEN_ENV_NAME=exampleproject +WARDEN_ENV_TYPE=magento2 +WARDEN_WEB_ROOT=/webroot + +TRAEFIK_DOMAIN=exampleproject.test +TRAEFIK_SUBDOMAIN=app + +WARDEN_DB=1 +WARDEN_ELASTICSEARCH=1 +WARDEN_VARNISH=1 +WARDEN_RABBITMQ=1 +WARDEN_REDIS=1 + +ELASTICSEARCH_VERSION=7.6 +MARIADB_VERSION=10.3 +NODE_VERSION=10 +PHP_VERSION=7.4 +RABBITMQ_VERSION=3.8 +REDIS_VERSION=5.0 +VARNISH_VERSION=6.0 + +WARDEN_SYNC_IGNORE= + +WARDEN_ALLURE=0 +WARDEN_SELENIUM=0 +WARDEN_SELENIUM_DEBUG=0 +WARDEN_BLACKFIRE=0 +WARDEN_SPLIT_SALES=0 +WARDEN_SPLIT_CHECKOUT=0 +WARDEN_TEST_DB=0 +WARDEN_MAGEPACK=0 + +BLACKFIRE_CLIENT_ID= +BLACKFIRE_CLIENT_TOKEN= +BLACKFIRE_SERVER_ID= +BLACKFIRE_SERVER_TOKEN= diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c1fb6b --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +.buildpath +.cache +.DS_Store +.idea +.metadata +.project +.settings +*.log +*.sql.gz +*.tar.gz +node_modules + +/webroot/* +!/webroot/app +/webroot/app/* +!/webroot/app/etc +/webroot/app/etc/* +!/webroot/app/etc/config.php +!/webroot/app/etc/env.php.warden.php +!/webroot/app/etc/env.php.init.php + +!/webroot/patches +!/webroot/modules +!/webroot/composer.json +!/webroot/composer.lock +!/webroot/robots.txt +!/webroot/Gruntfile.js +!/webroot/package.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3cc84f6 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for XDebug", + "type": "php", + "request": "launch", + "port": 9000, + "pathMappings": { + "/var/www/html": "${workspaceRoot}/webroot" + } + } + ] +} \ No newline at end of file diff --git a/.warden/commands/bootstrap.cmd b/.warden/commands/bootstrap.cmd new file mode 100644 index 0000000..f118689 --- /dev/null +++ b/.warden/commands/bootstrap.cmd @@ -0,0 +1,321 @@ +#!/usr/bin/env bash +[[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1 +set -euo pipefail + +function :: { + echo + echo "==> [$(date +%H:%M:%S)] $@" +} + +## load configuration needed for setup +WARDEN_ENV_PATH="$(locateEnvPath)" || exit $? +loadEnvConfig "${WARDEN_ENV_PATH}" || exit $? + +assertDockerRunning + +## change into the project directory +cd "${WARDEN_ENV_PATH}" + +## configure command defaults +WARDEN_WEB_ROOT="$(echo "${WARDEN_WEB_ROOT:-/}" | sed 's#^/#./#')" +REQUIRED_FILES=("${WARDEN_WEB_ROOT}/auth.json") +DB_DUMP="${DB_DUMP:-./backfill/magento-db.sql.gz}" +DB_IMPORT=1 +CLEAN_INSTALL= +AUTO_PULL=1 +META_PACKAGE="magento/project-community-edition" +META_VERSION="" +URL_FRONT="https://${TRAEFIK_SUBDOMAIN}.${TRAEFIK_DOMAIN}/" +URL_ADMIN="https://${TRAEFIK_SUBDOMAIN}.${TRAEFIK_DOMAIN}/backend/" + +## argument parsing +## parse arguments +while (( "$#" )); do + case "$1" in + --clean-install) + REQUIRED_FILES+=("${WARDEN_WEB_ROOT}/app/etc/env.php.init.php") + CLEAN_INSTALL=1 + DB_IMPORT= + shift + ;; + --meta-package) + shift + META_PACKAGE="$1" + shift + ;; + --meta-version) + shift + META_VERSION="$1" + if + ! test $(version "${META_VERSION}") -ge "$(version 2.3.4)" \ + && [[ ! "${META_VERSION}" =~ ^2\.[3-9]\.x$ ]] + then + fatal "Invalid --meta-version=${META_VERSION} specified (valid values are 2.3.4 or later and 2.[3-9].x)" + fi + shift + ;; + --skip-db-import) + DB_IMPORT= + shift + ;; + --db-dump) + shift + DB_DUMP="$1" + shift + ;; + --no-pull) + AUTO_PULL= + shift + ;; + *) + error "Unrecognized argument '$1'" + exit -1 + ;; + esac +done + +## if no composer.json is present in web root imply --clean-install flag when not specified explicitly +if [[ ! ${CLEAN_INSTALL} ]] && [[ ! -f "${WARDEN_WEB_ROOT}/composer.json" ]]; then + warning "Implying --clean-install since file ${WARDEN_WEB_ROOT}/composer.json not present" + REQUIRED_FILES+=("${WARDEN_WEB_ROOT}/app/etc/env.php.init.php") + CLEAN_INSTALL=1 + DB_IMPORT= +fi + +## include check for DB_DUMP file only when database import is expected +[[ ${DB_IMPORT} ]] && REQUIRED_FILES+=("${DB_DUMP}" "${WARDEN_WEB_ROOT}/app/etc/env.php.warden.php") + +:: Verifying configuration +INIT_ERROR= + +## attempt to install mutagen if not already present +if [[ $OSTYPE =~ ^darwin ]] && ! which mutagen 2>/dev/null >/dev/null && which brew 2>/dev/null >/dev/null; then + warning "Mutagen could not be found; attempting install via brew." + brew install havoc-io/mutagen/mutagen +fi + +## check for presence of host machine dependencies +for DEP_NAME in warden mutagen docker-compose pv; do + if [[ "${DEP_NAME}" = "mutagen" ]] && [[ ! $OSTYPE =~ ^darwin ]]; then + continue + fi + + if ! which "${DEP_NAME}" 2>/dev/null >/dev/null; then + error "Command '${DEP_NAME}' not found. Please install." + INIT_ERROR=1 + fi +done + +## verify warden version constraint +WARDEN_VERSION=$(warden version 2>/dev/null) || true +WARDEN_REQUIRE=0.6.0 +if ! test $(version ${WARDEN_VERSION}) -ge $(version ${WARDEN_REQUIRE}); then + error "Warden ${WARDEN_REQUIRE} or greater is required (version ${WARDEN_VERSION} is installed)" + INIT_ERROR=1 +fi + +## copy global Marketplace credentials into webroot to satisfy REQUIRED_FILES list; in ideal +## configuration the per-project auth.json will already exist with project specific keys +if [[ ! -f "${WARDEN_WEB_ROOT}/auth.json" ]] && [[ -f ~/.composer/auth.json ]]; then + if docker run --rm -v ~/.composer/auth.json:/tmp/auth.json \ + composer config -g http-basic.repo.magento.com >/dev/null 2>&1 + then + warning "Configuring ${WARDEN_WEB_ROOT}/auth.json with global credentials for repo.magento.com" + echo "{\"http-basic\":{\"repo.magento.com\":$( + docker run --rm -v ~/.composer/auth.json:/tmp/auth.json composer config -g http-basic.repo.magento.com + )}}" > ${WARDEN_WEB_ROOT}/auth.json + fi +fi + +## verify mutagen version constraint +MUTAGEN_VERSION=$(mutagen version 2>/dev/null) || true +MUTAGEN_REQUIRE=0.11.4 +if [[ $OSTYPE =~ ^darwin ]] && ! test $(version ${MUTAGEN_VERSION}) -ge $(version ${MUTAGEN_REQUIRE}); then + error "Mutagen ${MUTAGEN_REQUIRE} or greater is required (version ${MUTAGEN_VERSION} is installed)" + INIT_ERROR=1 +fi + +## check for presence of local configuration files to ensure they exist +for REQUIRED_FILE in ${REQUIRED_FILES[@]}; do + if [[ ! -f "${REQUIRED_FILE}" ]]; then + error "Missing local file: ${REQUIRED_FILE}" + INIT_ERROR=1 + fi +done + +## exit script if there are any missing dependencies or configuration files +[[ ${INIT_ERROR} ]] && exit 1 + +:: Starting Warden +warden svc up +if [[ ! -f ~/.warden/ssl/certs/${TRAEFIK_DOMAIN}.crt.pem ]]; then + warden sign-certificate ${TRAEFIK_DOMAIN} +fi + +:: Initializing environment +if [[ $AUTO_PULL ]]; then + warden env pull --ignore-pull-failures || true + warden env build --pull +else + warden env build +fi +warden env up -d + +## wait for mariadb to start listening for connections +warden shell -c "while ! nc -z db 3306 ${#ADMIN_PASS}?${#URL_ADMIN}:${#ADMIN_PASS}" + let "C2_LEN=${C2_LEN}>${#OTPAUTH_QRI}?${C2_LEN}:${#OTPAUTH_QRI}" + + # note: in CentOS bash .* isn't supported (is on Darwin), but *.* is more cross-platform + printf "+ %*.*s + %*.*s + \n" 0 $C1_LEN $FILL 0 $C2_LEN $FILL + printf "+ %-*s + %-*s + \n" $C1_LEN FrontURL $C2_LEN "$URL_FRONT" + printf "+ %*.*s + %*.*s + \n" 0 $C1_LEN $FILL 0 $C2_LEN $FILL + printf "+ %-*s + %-*s + \n" $C1_LEN AdminURL $C2_LEN "$URL_ADMIN" + printf "+ %*.*s + %*.*s + \n" 0 $C1_LEN $FILL 0 $C2_LEN $FILL + if [[ ${OTPAUTH_QRI} ]]; then + printf "+ %-*s + %-*s + \n" $C1_LEN AdminOTP $C2_LEN "$OTPAUTH_QRI" + printf "+ %*.*s + %*.*s + \n" 0 $C1_LEN $FILL 0 $C2_LEN $FILL + fi + printf "+ %-*s + %-*s + \n" $C1_LEN Username $C2_LEN "$ADMIN_USER" + printf "+ %*.*s + %*.*s + \n" 0 $C1_LEN $FILL 0 $C2_LEN $FILL + printf "+ %-*s + %-*s + \n" $C1_LEN Password $C2_LEN "$ADMIN_PASS" + printf "+ %*.*s + %*.*s + \n" 0 $C1_LEN $FILL 0 $C2_LEN $FILL +} +print_install_info diff --git a/.warden/commands/bootstrap.help b/.warden/commands/bootstrap.help new file mode 100644 index 0000000..208003b --- /dev/null +++ b/.warden/commands/bootstrap.help @@ -0,0 +1,30 @@ +#!/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=$(cat <.sql.gz] + +\033[33mOptions:\033[0m + -h, --help Display this help menu + + --clean-install install from scratch rather than use existing database dump; + implied when no composer.json file is present in web root + + --meta-package passed to 'composer create-project' when --clean-install is + specified and defaults to 'magento/project-community-edition' + + --meta-version specify alternate version to install; defaults to latest; may + be (for example) specified as 2.3.x (latest minor) or 2.3.4 + + --no-pull when specified latest images will not be explicitly pulled prior + to environment startup to facilitate use of locally built images + + --skip-db-import skips over db import (assume db has already been imported) + +\033[33mArguments:\033[0m + + --db-dump .sql.gz expects path to .sql.gz file for import during init + +EOF +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..95b72cd --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ + Magento 2 Application +======================================================== + +| Env | FrontURL | AdminURL | +| --- | :------- | :------- | +| DEV | https://app.exampleproject.test/ | https://app.exampleproject.test/backend/ | +| STG | https://stage.exampleproject.com/ | https://stage.exampleproject.com/backend/ | +| PRD | https://www.exampleproject.com/ | https://www.exampleproject.com/backend/ | + +Other useful URLs on DEV: + +* https://mailhog.warden.test/ +* https://rabbitmq.exampleproject.test/ +* https://elasticsearch.exampleproject.test/ + +## Developer Setup + +### Prerequisites: + +* [Warden](https://warden.dev/) 0.6.0 or later is installed. See the [Installing Warden](https://docs.warden.dev/installing.html) docs page for further info and procedures. +* `pv` is installed and available in your `$PATH` (you can install this via `brew`, `dnf`, `apt` etc) + +### Initializing Environment + +In the below examples `~/Sites/exampleproject` is used as the path. Simply replace this with whatever path you will be running this project from. It is recommended however to deploy the project locally to a case-sensitive volume. + + 1. Clone the project codebase. + + git clone -b develop git@github.com:/.git \ + ~/Sites/exampleproject + + 2. Change into the project directory. + + cd ~/Sites/exampleproject + + 3. Configure composer credentials. + + composer config -f ./webroot/composer.json http-basic.repo.magento.com + + If you don't have `composer` installed on the host machine, manually create `webroot/auth.json` using the following template: + + { + "http-basic": { + "repo.magento.com": { + "username": "", + "password": "" + } + } + } + + 4. Run the init script to bootstrap the environment, starting the containers and mutagen sync (on macOS), installing the database (or importing if `--db-dump` is specified), and creating the local admin user for accessing the Magento backend. + + warden bootstrap --clean-install + + 5. Load the site in your browser using the links and credentials taken from the init script output. + + **Note:** If you are using **Firefox** and it warns you the SSL certificate is invalid/untrusted, go to Preferences -> Privacy & Security -> View Certificates (bottom of page) -> Authorities -> Import and select `~/.warden/ssl/rootca/certs/ca.cert.pem` for import, then reload the page. + + **Note:** If you are using **Chrome** on **Linux** and it warns you the SSL certificate is invalid/untrusted, go to Chrome Settings -> Privacy And Security -> Manage Certificates (see more) -> Authorities -> Import and select `~/.warden/ssl/rootca/certs/ca.cert.pem` for import, then reload the page. + +### Additional Configuration + +Information on configuring and using tools such as Xdebug, LiveReload, MFTF, and multi-domain site setups may be found in the Warden docs page on [Configuration](https://docs.warden.dev/configuration.html). + +### Destroying Environment + +To completely destroy the local environment we just created, run `warden env down -v` to tear down the project’s Docker containers, volumes, and (where applicable) cleanup the Mutagan sync session. diff --git a/backfill/.gitkeep b/backfill/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/webroot/app/etc/env.php.init.php b/webroot/app/etc/env.php.init.php new file mode 100644 index 0000000..9d1691e --- /dev/null +++ b/webroot/app/etc/env.php.init.php @@ -0,0 +1,124 @@ + [ + 'frontend' => [ + 'default' => [ + 'frontend_options' => [ + 'write_control' => false + ] + ], + 'page_cache' => [ + 'frontend_options' => [ + 'write_control' => false + ] + ] + ] + ], + 'system' => [ + 'default' => [ + 'design' => [ + 'head' => [ + 'demonotice' => '1' + ], + 'footer' => [ + 'absolute_footer' => '' + ] + ], + 'web' => [ + 'secure' => [ + 'offloader_header' => 'X-Forwarded-Proto', + 'use_in_frontend' => '1', + 'use_in_adminhtml' => '1' + ], + 'seo' => [ + 'use_rewrites' => '1' + ], + 'url' => [ + 'use_store' => '0', + 'redirect_to_base' => '1' + ], + 'cookie' => [ + 'cookie_path' => null, + 'cookie_httponly' => '1', + 'cookie_restriction' => '0' + ], + 'session' => [ + 'use_remote_addr' => '0', + 'use_http_via' => '0', + 'use_http_x_forwarded_for' => '0', + 'use_http_user_agent' => '0', + 'use_frontend_sid' => '1' + ], + 'browser_capabilities' => [ + 'cookies' => '1', + 'javascript' => '1', + 'local_storage' => '0' + ] + ], + 'catalog' => [ + 'frontend' => [ + 'list_allow_all' => '0', + 'flat_catalog_category' => '0', + 'flat_catalog_product' => '0' + ], + 'search' => [ + 'engine' => 'elasticsearch7', + 'enable_eav_indexer' => '1', + 'elasticsearch7_server_hostname' => 'elasticsearch', + 'elasticsearch7_server_port' => '9200', + 'elasticsearch7_index_prefix' => 'magento2', + 'elasticsearch7_enable_auth' => '0', + 'elasticsearch7_server_timeout' => '15' + ] + ], + 'system' => [ + 'full_page_cache' => [ + 'caching_application' => '2', + 'ttl' => '604800' + ] + ], + 'dev' => [ + 'front_end_development_workflow' => [ + 'type' => 'server_side_compilation' + ], + 'template' => [ + 'allow_symlink' => '0', + 'minify_html' => '0' + ], + 'js' => [ + 'merge_files' => '0', + 'enable_js_bundling' => '0', + 'minify_files' => '0', + 'translate_strategy' => 'dictionary', + 'session_storage_logging' => '0', + 'session_storage_key' => 'collected_errors' + ], + 'css' => [ + 'merge_css_files' => '0', + 'minify_files' => '0' + ], + 'image' => [ + 'default_adapter' => 'GD2' + ], + 'static' => [ + 'sign' => '0' + ] + ], + 'admin' => [ + 'url' => [ + 'use_custom' => '0', + 'use_custom_path' => '0' + ], + 'security' => [ + 'use_form_key' => '1', + 'use_case_sensitive_login' => '0', + 'session_lifetime' => '7200', + 'lockout_failures' => '6', + 'lockout_threshold' => '30', + 'password_lifetime' => '90', + 'password_is_forced' => '1' + ] + ] + ] + ] +];