diff --git a/.gitignore b/.gitignore index f40cefe..06e0189 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ console # Local development tools. docker-compose.override.yml +.lando.local.yml # Local data directory. .data diff --git a/.lando.base.yml b/.lando.base.yml new file mode 100644 index 0000000..9462b9d --- /dev/null +++ b/.lando.base.yml @@ -0,0 +1,717 @@ +################## +## Instructions ## +################## + +# This file is designed to be used with an alternative docker-compose wrapper +# tool 'lando'. Installation instructions for the tool can be found here: +# - Mac OS - https://docs.lando.dev/install/macos.html +# - Linux OS - https://docs.lando.dev/install/linux.html +# - Windows via WSL - https://docs.lando.dev/install/linux.html#caveats +# --- (for best performance, install the full docker desktop in windows with WSL +# intergration, then the install lando in the WSL via the `caveats` way. + +# 1. After the initialising the project, (may have already been done is by +# GovCMS if '[project]/scripts/scaffold-init.sh' doesn't exist): +# Run '[project]/scripts/scaffold-existing-project-add-lando.sh'. + +# Command `./scripts/scaffold-existing-project-add-lando.sh` + +# 2. Optionally enable local overrides (e.g. change project name for multiple +# copies of the same project running at once) by duplicating +# '[project]/.lando.local.example.yml' to '[project].lando.local.yml' +# (instead of .env file): + +# Command: `cp -i ./.lando.local.example.yml ./.lando.local.yml` + +# 3. Adjust '.lando.local.yml' if required. For example, toggle DEV_MODE, +# set MARIADB_DATA_IMAGE or make the lando project name/urls unique for multiple +# instances of this same project on the same computer. + +# 4. Run the project. + +# Command: `lando start` + +####################### +## IMPORTANT - Notes ## +####################### + +# If you get a error "ERROR ==> (HTTP code 500) server error - container +# is not connected to the network lando_bridge_network" +# Then just run "lando rebuild" again. + +# If swapping image via `MARIADB_DATA_IMAGE` AFTER using the lando project, then +# the database volumes must be removed first, otherwise it will use the old +# database. So use `lando destroy` or remove the database container and volumes +# via the below commands: +# +# LANDO_APP_NAME=$(lando info 2>/dev/null | grep hostnames | grep -o -P "[^\.]*.internal('|\")" | awk -F . '{print $1}' | head -n 1) +# LANDO_APP_DB_NAME=$(printf $LANDO_APP_NAME)_mariadb_1 +# docker container rm --force $LANDO_APP_DB_NAME +# docker volume rm $(printf $LANDO_APP_NAME)_data_mariadb_blank +# docker volume rm $(printf $LANDO_APP_NAME)_data_mariadb_govcms_image +# + +################### +## Ahoy commands ## +################### + +# Out of the box, ahoy commands in lando are mapped like: +# `ahoy [command]` +# becomes +# `lando ahoy-[command]` + +# If you prefer to use ahoy directly, then first copy the content of: +# [project]/custom/ahoy.lando.yml +# to: +# [project]/custom/ahoy.yml +# +# then the commands are: +# `ahoy [command]` +# becomes +# ahoy my lando-[command] + +################ +## Misc notes ## +################ + +# The default order of .lando.yml file merge order is: +# preLandoFiles: +# - .lando.base.yml +# - .lando.dist.yml +# - .lando.upstream.yml +# landoFile: .lando.yml +# postLandoFiles: +# - .lando.local.yml + +################################# +## GovCMS Docker Configuration ## +################################# + +###################### +## !! IMPORTANT !!! ## +## To run multiple copies of the same project, the following properties must be +## unique per project: +## - lagoon-project `x-lagoon-project` +## - default-url (which affects LAGOON_ROUTE / LOCALDEV_URL) `x-default-url` +## - lando proxy urls `proxy` +###################### + +# This value intentionally matches the project name on Lagoon. +# It is used to name the CLI_IMAGE to use as a build arg locally. +x-lagoon-project: &lagoon-project {{ GOVCMS_PROJECT_NAME }} + +x-default-url: &default-url ${LOCALDEV_URL:-http://{{ GOVCMS_PROJECT_NAME }}.docker.amazee.io} + +# Lando proxy urls. +proxy: + nginx: + hostname: {{ GOVCMS_PROJECT_NAME }}-nginx.lndo.site:8080 + # solr: + # hostname: {{ GOVCMS_PROJECT_NAME }}-solr.lndo.site:8983 + +# See GOVCMS_IMAGE_VERSION in "Variables" at https://github.com/govCMS/govCMS/wiki +x-govcms-image-version: &govcms-image-version ${GOVCMS_IMAGE_VERSION:-{{ GOVCMS_VERSION }}.x-latest} + +x-volumes-lando-tooling: + volumes: + - &volume-lando-tooling ./.lando/container:/lando-govcms + +x-volumes: &default-volumes + volumes: + - ./themes:/app/web/themes/custom:${VOLUME_FLAGS:-delegated} + - ./files:/app/web/sites/default/files:delegated + - ./tests/behat/features:/app/tests/behat/features:${VOLUME_FLAGS:-delegated} + - ./tests/behat/screenshots:/app/tests/behat/screenshots:${VOLUME_FLAGS:-delegated} + - ./tests/phpunit/tests:/app/tests/phpunit/tests:${VOLUME_FLAGS:-delegated} + - ./config:/app/config + - *volume-lando-tooling + +x-volumes-paas: &paas-volumes + volumes: + - .:/app:delegated + - *volume-lando-tooling + +# Entry point process isn't PID 1 as lando entrypoint is instead, +# so force it to run. +x-extra-environment-tini: &extra-environment-tini + - TINI_SUBREAPER: true + +x-environment: &default-environment + RESTY_RESOLVER: 8.8.8.8 + STAGE_FILE_PROXY_URL: ${STAGE_FILE_PROXY_URL:-} + LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-} + LAGOON_PROJECT: *lagoon-project + LAGOON_ROUTE: *default-url + LOCALDEV_URL: *default-url + GOVCMS_IMAGE_VERSION: ${GOVCMS_IMAGE_VERSION:-{{ GOVCMS_VERSION }}.x-latest} + DEV_MODE: "${DEV_MODE:-false}" + XDEBUG_ENABLE: ${XDEBUG_ENABLE:-} + DOCKERHOST: ${DOCKERHOST:-host.docker.internal} + X_FRAME_OPTIONS: ${X_FRAME_OPTIONS:-SameOrigin} + DRUPAL_SHIELD_USER: ${DRUPAL_SHIELD_USER:-} + DRUPAL_SHIELD_PASS: ${DRUPAL_SHIELD_PASS:-} + GOVCMS_DEPLOY_WORKFLOW_CONFIG: ${GOVCMS_DEPLOY_WORKFLOW_CONFIG:-import} + GOVCMS_PREPARE_XML_SCRIPT: /app/vendor/bin/govcms-prepare-xml + HTTPAV_ENDPOINT: http://av:3993/scan + HTTPAV_RETURN_KEY: comodo + HTTP_PAYLOAD_KEY: malware + SOLR_MODULES: ${SOLR_MODULES:-extraction,langid,ltr,analysis-extras} + << : *extra-environment-tini + +######################### +## Lando configuration ## +######################### + +# Unique lando project name - uses 'lagoon-project' variable. +name: *lagoon-project + +# Note: Vars only work in the containers, not in the lando.yml files and only if +# NOT defined in the .lando.yml files, otherwise lando yml takes precedence, +# unlike docker-compose.yml. +# @see https://github.com/lando/lando/issues/1616 +#env_file: +# - .env + +# Define internal/external network 'amazeeio-network'. +compose: + - .lando/networks.external.yml + +x-lando-common-options: &lando-common-options + api: 3 + type: lando + # Do not auto mount /app folder by default. + app_mount: false + +x-lando-database-tooling-vars: &lando-database-tooling-vars + # Govcms database name for lando sql import script, instead of + # `~/.my.cnf` + MYSQL_DATABASE: drupal + LANDO_DB_EXPORT_USER: drupal + LANDO_DB_IMPORT_USER: drupal + # A default password is set, so override it, we can't force a blank password + # without creating defaults file and that defaults parameter must be first, + # but the default lando script places the extra paramters at the end, so use + # the druapl user. + LANDO_EXTRA_DB_EXPORT_ARGS: -pdrupal --single-transaction + # GovCMS SQL container doesn't allow TCP/IP connections. + LANDO_EXTRA_DB_IMPORT_ARGS: -pdrupal --socket=/run/mysqld/mysqld.sock --disable-ssl + +x-lando-tooling-mysql-cmd: &lando-mysql-cli-cmd 'mysql -udrupal -pdrupal -h 127.0.0.1 drupal' + +x-lando-tooling-ahoy-info-cmd: &lando-tooling-ahoy-info-cmd | + echo -e "\e[96m#### Project : $LAGOON_PROJECT \e[0m" + echo -e "\e[96m#### Site local URL : $LAGOON_ROUTE \e[0m" + echo -e "\e[96m#### DB port on host : [run \`docker port ${LANDO_APP_PROJECT}_mariadb_1 3306 | cut -d : -f 2\`]" + +x-lando-tooling-ahoy-govcms-deploy-cmd: &lando-tooling-ahoy-govcms-deploy-cmd | + mkdir -p /app/web/sites/default/files/private/tmp && \ + /app/vendor/bin/govcms-db-update && \ + /app/vendor/bin/govcms-config-import && \ + /app/vendor/bin/govcms-cache-rebuild && \ + /app/vendor/bin/govcms-enable_modules + +x-lando-extra-build-steps: &lando-extra-build-steps + build_as_root: + # Add pv. + - | + if apk list | grep "{pv}" > /dev/null | grep -q pv; then + # Run this if confirm returns true. + echo -e "\e[96m#### ($LANDO_SERVICE_NAME) PV is already installed. ####\e[0m"; + else + # Run this if confirm returns false. + echo -e "\e[96m#### ($LANDO_SERVICE_NAME) Installing PV. ####\e[0m" && + apk add pv && + echo -e "\e[96m#### ($LANDO_SERVICE_NAME) PV install done. ####\e[0m"; + fi + # If DB container, remove default database paramater, so we can recreate the + # database without it already existsing. + - | + CONFIG_FILE=/var/lib/mysql/.my.cnf + if test -f $CONFIG_FILE; then + echo -e "\e[96m#### ($LANDO_SERVICE_NAME) DB config file change. ####\e[0m"; + sed -i -e 's|^database=drupal$|#database=drupal|g' $CONFIG_FILE; + echo "Config file: $CONFIG_FILE changed!" + echo -e "\e[96m#### ($LANDO_SERVICE_NAME) DB config file change done. ####\e[0m"; + fi + # Download another copy of mariadb-client to avoid sandbox uncomment hack. + - | + if command -v mariadb > /dev/null; then + echo -e "\e[96m#### ($LANDO_SERVICE_NAME) Mariadb client download. ####\e[0m"; + PROGRAM=mariadb-client + # Same repo as cli image. + REPO=https://dl-cdn.alpinelinux.org/alpine/v3.23/main + apkInstalledVersion() { + apk info "$1" | head -n1 | sed "s/^$1-\(.*\) description:/\1/g" + } + apkSearchVersion() { + apk search $1 --no-cache --repository $REPO | grep "^$1-\d\+" | head -n1 | sed "s/^$1-//" + } + CURRENT_VERSION=$(apkInstalledVersion $PROGRAM) + SEARCH_VERSION=$(apkSearchVersion $PROGRAM) + echo "Version compare:" + echo "Current: $CURRENT_VERSION" + echo "Search: $SEARCH_VERSION" + if [ $(printf "${CURRENT_VERSION}\n${SEARCH_VERSION}"|sort -r|head -1) != "${CURRENT_VERSION}" ]; then + echo "Newest version of $PROGRAM required, downloading..." + mkdir "/opt/custom-${PROGRAM}" + wget -q "${REPO}/$(arch)/${PROGRAM}-${SEARCH_VERSION}.apk" -O "/opt/custom-${PROGRAM}/${PROGRAM}.apk" + tar -xzf "/opt/custom-${PROGRAM}/${PROGRAM}.apk" -C "/opt/custom-${PROGRAM}" + echo "Downloaded and extracted ${PROGRAM}@${SEARCH_VERSION} to /opt/custom-${PROGRAM}." + else + echo "Newest version of $PROGRAM is already installed." + fi + echo -e "\e[96m#### ($LANDO_SERVICE_NAME) Mariadb client download done. ####\e[0m"; + fi + # Disable SSL on mariadb client. Note that drush uses it's own mysql + # configuration instead. Also, the drush.yml extra paramater is not used on + # drush v12 for site install, so use work around of + # `composer require "drush/drush:13.6.2 as 12.5.2" -W` in cli container. + # @see https://github.com/uselagoon/lagoon-images/pull/1276 + # @see https://github.com/govCMS/scaffold/issues/133#issuecomment-4249427842 + - | + if test -d /etc/my.cnf.d; then + echo -e "\e[96m#### ($LANDO_SERVICE_NAME) Disable SSL on mariadb client. ####\e[0m"; + printf '[client]\nskip-ssl' > /etc/my.cnf.d/zz-mariadb-client.cnf + echo -e "\e[96m#### ($LANDO_SERVICE_NAME) Disable SSL on mariadb client - done. ####\e[0m"; + fi + +############## +## Services ## +############## + +services: + cli: + << : *lando-common-options + << : *lando-extra-build-steps + meUser: root + services: + user: root + build: + context: . + dockerfile: .docker/Dockerfile.cli + args: + LAGOON_SAFE_PROJECT: *lagoon-project + GOVCMS_IMAGE_VERSION: *govcms-image-version + GOVCMS_GITHUB_TOKEN: ${GOVCMS_GITHUB_TOKEN:-} + image: *lagoon-project + labels: + lagoon.type: cli-persistent + lagoon.persistent.name: nginx + lagoon.persistent: /app/web/sites/default/files/ + lagoon.base.image: govcms/govcms:${GOVCMS_IMAGE_VERSION:-{{ GOVCMS_VERSION }}.x-latest} + environment: + << : *default-environment + # Set Dockerfile entrypoint & CMD togther so lando uses it's secret sauce. + command: /sbin/tini -- /lagoon/entrypoints.sh /bin/docker-sleep + << : *default-volumes + # Mount volumes from Pygmy to inject host SSH key into container. + # https://pygmy.readthedocs.io/en/master/ssh_agent/ + volumes_from: + - container:amazeeio-ssh-agent + + test: + << : *lando-common-options + meUser: root + services: + user: root + build: + context: . + dockerfile: .docker/Dockerfile.test + args: + CLI_IMAGE: *lagoon-project + GOVCMS_IMAGE_VERSION: *govcms-image-version + SITE_AUDIT_VERSION: ${SITE_AUDIT_VERSION:-7.x-3.x} + # Can't use additional contexts, but lando rebuild pulls new images + # anyway so might not be a problem. + # @see https://github.com/lando/lagoon/pull/107 + # additional_contexts: + # cli: 'service:cli' # Ensure cli is built first + labels: + lagoon.type: none + depends_on: + - cli + environment: + << : *default-environment + # Set Dockerfile entrypoint & CMD togther so lando uses it's secret sauce. + command: /sbin/tini -- /lagoon/entrypoints.sh /bin/docker-sleep + << : *default-volumes + + nginx: + << : *lando-common-options + meUser: root + # Expose Nginx via lando proxy, note that 'ports' must also be present in + # 'services'. + moreHttpPorts: + - '8080' + # Skip Lando checking for service to be healthy, the site might not be + # installed yet and Lando DNS might not be setup either. + scanner: false + services: + user: root + build: + context: . + dockerfile: .docker/Dockerfile.nginx-drupal + args: + CLI_IMAGE: *lagoon-project + GOVCMS_IMAGE_VERSION: *govcms-image-version + # Can't use additional contexts, but lando rebuild pulls new images + # anyway so might not be a problem. + # @see https://github.com/lando/lagoon/pull/107 + # additional_contexts: + # cli: 'service:cli' # Ensure cli is built first + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/web/sites/default/files/ + depends_on: + - cli + environment: + << : *default-environment + LAGOON_LOCALDEV_URL: *default-url + networks: + - amazeeio-network + - default + # Set Dockerfile entrypoint & CMD togther so lando uses it's secret sauce. + command: /sbin/tini -- /lagoon/entrypoints.sh nginx -g 'daemon off;' + # Required for lando proxy 'moreHttpPorts'. + ports: + - '8080' + << : *default-volumes + + php: + << : *lando-common-options + meUser: root + services: + user: root + build: + context: . + dockerfile: .docker/Dockerfile.php + args: + CLI_IMAGE: *lagoon-project + GOVCMS_IMAGE_VERSION: *govcms-image-version + # Can't use additional contexts, but lando rebuild pulls new images + # anyway so might not be a problem. + # @see https://github.com/lando/lagoon/pull/107 + # additional_contexts: + # cli: 'service:cli' # Ensure cli is built first + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx + lagoon.persistent: /app/web/sites/default/files/ + depends_on: + - cli + environment: + << : *default-environment + command: /sbin/tini -- /lagoon/entrypoints.sh /usr/local/sbin/php-fpm -F -R + << : *default-volumes + + mariadb: + << : *lando-common-options + << : *lando-extra-build-steps + meUser: mysql + # Mount the app folder, for db import, db-export. + app_mount: true + services: + image: ${MARIADB_DATA_IMAGE:-govcms/mariadb-drupal:{{ GOVCMS_VERSION }}.x-latest} + platform: linux/amd64 + labels: + lagoon.type: mariadb + lagoon.image: govcms/mariadb-drupal:{{ GOVCMS_VERSION }}.x-latest + ports: + - '3306' # Find port on host with `docker port [container_name_for_mariadb] 3306` + environment: + << : *default-environment + command: /sbin/tini -- /lagoon/entrypoints.bash mysqld + # Keep index data across lando rebuilds. (1 of 2) + volumes: + # Keep database across lando rebuilds by using named volumes. (1 of 2) + - data_mariadb_blank:/var/lib/mysql + - data_mariadb_govcms_image:/var/lib/db-data + - *volume-lando-tooling + # Keep database across lando rebuilds by using named volumes. (2 of 2) + volumes: + data_mariadb_blank: + data_mariadb_govcms_image: + healthcheck: + command: mysql -uroot --silent --execute "SHOW DATABASES;" + av: + << : *lando-common-options + services: + image: govcms/av:latest + labels: + lagoon.type: none + environment: + << : *extra-environment-tini + command: /init /bin/sh -c "freshclam --checks=1 --daemon --foreground --stdout --user=clamav && rm /var/lib/clamav/freshclam.dat || rm /var/lib/clamav/mirrors.dat || true" + + # Uncomment to enable solr and `proxy` => `solr`. + # solr: + # << : *lando-common-options + # meUser: solr + # # Expose SOLR via lando proxy. + # moreHttpPorts: + # - '8983' + # # Skip Lando checking for service to be healthy, the site might not be + # # installed yet and Lando DNS might be setup either. + # scanner: false + # # Prevent 'lando ssh' failing because "cd /app" as not mounted. + # run_as_root: + # - | + # echo -e "\e[96m#### ($LANDO_SERVICE_NAME) create /app if not exist. ####\e[0m"; + # mkdir -p /app + # echo -e "\e[96m#### ($LANDO_SERVICE_NAME) create /app if not exist - done. ####\e[0m"; + # services: + # user: solr + # build: + # context: . + # dockerfile: .docker/Dockerfile.solr + # args: + # GOVCMS_IMAGE_VERSION: *govcms-image-version + # LAGOON_IMAGE_VERSION: ${LAGOON_IMAGE_VERSION:-latest} + # labels: + # lagoon.type: solr + # lagoon.base.image: govcms/solr:${GOVCMS_IMAGE_VERSION:-{{ GOVCMS_VERSION }}.x-latest} + # ports: + # - '8983' # Find port on host with `docker port [container_name_for_solr] 8983` + # depends_on: + # - cli + # environment: + # << : *default-environment + # command: /sbin/tini -- /lagoon/entrypoints.sh solr-foreground + + chrome: + << : *lando-common-options + services: + user: seluser + image: selenium/standalone-chrome:4.5.2-20221021 + platform: linux/amd64 + shm_size: '1gb' + depends_on: + - test + labels: + lagoon.type: none + environment: + LANDO_DROP_USER: seluser + command: /opt/bin/entry_point.sh + << : *default-volumes + +########################### +## Drush / ahoy commands ## +########################### + +tooling: + ###### + ## Standard Lando Drupaly commands + ###### + composer: + service: cli + cmd: 'composer --ansi' + user: root + 'db-import ': + service: ':host' + description: 'Imports a dump file into a database service' + cmd: '/lando-govcms/container-scripts/db-import-prompt.sh /helpers/sql-import.sh' + user: 'root' + env: + << : *lando-database-tooling-vars + options: + 'host': + description: 'The database service to use' + default: 'mariadb' + alias: ['h'] + 'no-wipe': + description: 'Do not destroy the existing database before an import' + boolean: true + 'db-export [file]': + service: ':host' + description: 'Exports database from a database service to a file' + cmd: '/helpers/sql-export.sh' + user: 'root' + env: + << : *lando-database-tooling-vars + options: + host: + description: 'The database service to use' + default: 'mariadb' + alias: ['h'] + stdout: + description: 'Dump database to stdout' + php: + service: 'cli' + cmd: 'php' + mysql: + service: ':host' + description: 'Drops into a MySQL shell on a database service' + cmd: *lando-mysql-cli-cmd + options: + host: + description: 'The database service to use' + default: 'mariadb' + alias: ['h'] + drush: + service: cli + description: Run drush commands + cmd: drush + ############# + ## Ahoy equivalent commands. + ############# + ## Note: these run inside the container, not on the host, so `docker`/`lando` + ## commands cannot be used. + ahoy: + service: cli + description: Shows how to run the correct lando ahoy command. + cmd: echo Command not supported, Use \`lando ahoy-[command]\` to run ahoy commands instead. + ahoy-up: + service: cli + description: Build project. (use alternative command) + cmd: echo Command not supported, the lando command to run instead is \`lando start\`. + ahoy-down: + service: cli + description: Delete project (CAUTION). (use alternative command) + cmd: echo Command not supported, the lando command to run instead is \`lando destroy\`. + ahoy-build: + service: cli + description: Build project. (use alternative command) + cmd: | + echo Command not supported, the lando commands to run instead are: + echo " - \`lando rebuild\`" + echo " - \`lando ahoy-govcms-deploy\`" + echo " - \`lando ahoy-info\`" + echo Note: this will update the containers. + ahoy-cli: + service: cli + description: Start a shell inside cli container. + cmd: bash + ahoy-run: + service: cli + description: Run command inside cli container. + cmd: /lando-govcms/container-scripts/ahoy-run.sh + ahoy-govcms-deploy: + service: cli + description: Runs deployment commands (e.g. config import, updb, cr, set up file_stage_proxy). + cmd: *lando-tooling-ahoy-govcms-deploy-cmd + ahoy-drush: + service: cli + description: Run drush commands in cli container. + cmd: drush + ahoy-logs: + service: cli + description: Show Docker logs. (use alternative command) + cmd: | + echo Command not supported, the lando command to run instead is \`lando logs\`. + echo Useful parameters: + echo " --follow" + echo " --service=[service_name, e.g. php, cli, nginx etc.]" + echo "" + echo Logs can also be viewed by running \`docker logs ${LANDO_APP_PROJECT}_[service_name]_1\` + echo Useful parameters: + echo " --follow" + echo " --tail=[number]" + echo " (shows last X number of lines)" + ahoy-ps: + service: cli + description: List running Docker containers. (use alternative command) + cmd: | + echo Command not supported, the lando command to run instead is \`lando list --app ${LANDO_APP_PROJECT} --format=table\`. + echo Useful parameters: + echo " --format=[json,table]" + ahoy-restart: + service: cli + description: Restart Docker containers. (use alternative command) + cmd: echo Command not supported, the lando command to run instead is \`lando restart\`. + ahoy-stop: + service: cli + description: Stop Docker containers. (use alternative command) + cmd: echo Command not supported, the lando command to run instead is \`lando stop\`. + ahoy-install: + service: cli + description: Install the profile. + cmd: + - | + read -r -p "Running this command will destroy your current site, are you sure? [y/N] " response; + if [ "${response}" = "y" ]; then + # Run this if confirm returns true. + drush si -y govcms + else + # Run this if confirm returns false. + echo "Cancelled."; \ + exit 1; + fi + - *lando-tooling-ahoy-govcms-deploy-cmd + ahoy-login: + service: cli + description: Login to a website. + cmd: | + drush -y cset tfa.settings reset_pass_skip_enabled true && \ + drush uinf --uid 1 --field name | xargs drush uublk && \ + drush uli + ahoy-unloop: + service: cli + description: Fix local redirect loop + cmd: | + drush ev '$u=\Drupal\user\Entity\User::load(1); $u->set("field_password_expiration", "0"); $u->save()' && \ + drush ev '$u=\Drupal\user\Entity\User::load(1); $u->set("field_last_password_reset", date("Y-m-d\TH:i:s")); $u->save()' + ahoy-mysql-import: + service: cli + description: Pipe in a sql file. `lando ahoy-mysql-import mysql-import local.sql` (use alternative command) + cmd: echo Command not supported, instead run \`lando drush sql-drop && lando drush sql-cli < local.sql\`. + ahoy-mysql-dump: + service: cli + description: Dump data out into a file. `ahoy mysql-dump local.sql` (use alternative command) + cmd: echo Command not supported, instead run \`lando drush sql-dump --ordered-dump > local.sql\`. + ahoy-lint: + service: test + description: Lint code + cmd: | + ./vendor/bin/govcms-lint web/modules/custom + ./vendor/bin/govcms-lint web/themes/custom + ahoy-test-behat: + service: test + description: Run Behat tests + cmd: ./vendor/bin/govcms-behat + ahoy-phpunit: + service: test + description: Run phpunit tests + cmd: ./vendor/bin/govcms-phpunit --testsuite govcms + ahoy-pull: + service: cli + description: Pull latest docker images. (use alternative command) + cmd: | + echo Command not supported, instead run: + echo '`docker image ls --format \"{{.Repository}}:{{.Tag}}\" | grep govcms/ | grep -v none | xargs -n1 docker pull | cat`' + echo Note that \`lando rebuild\` updates images and rebuilds the containers. + ahoy-refresh-db: + service: cli + description: Refresh the database container with latest nightly dump. (use alternative command) + cmd: | + echo Command not supported, instead run: + echo '`read -r -p "Running this command will replace your current database. Are you sure? (yes/no) [no]:" response; \ + ([ ! "${response}" = "y" ] && [ ! "${response}" = "yes" ]) \ + && echo OK, probably a wise choice... \ + || (cat .env | grep ^MARIADB_DATA_IMAGE | cut -c20- \ + '"| xargs -n1 docker pull; docker rm -f -v ${LANDO_APP_PROJECT}_mariadb_1 \ + && lando start)\`" + ahoy-ship-shape: + service: cli + description: Run site validation scripts locally + cmd: shipshape run -f /app/vendor/govcms/scaffold-tooling/shipshape.yml --exclude-db --error-code . + ahoy-debug: + service: cli + description: Enable debug configuration (use alternative command) + cmd: | + echo Command not supported, instead run: + echo '`{ lando ahoy-run "php -v|grep -q Xdebug" && echo "Debug is already enabled. \ + Use \`export XDEBUG_ENABLE="" && lando rebuild\` to disable."; } \ + || { export XDEBUG_ENABLE="true" && lando rebuild && \ + lando ahoy-run "php -v|grep -q Xdebug" && echo "Enabled debug configuration. \ + && Use \`export XDEBUG_ENABLE="" && lando rebuild\` to disable."; }`' + ahoy-info: + service: cli + description: Print information about this project. + cmd: *lando-tooling-ahoy-info-cmd + +################## +## Lando Events ## +################## +events: + post-start: + - *lando-tooling-ahoy-info-cmd diff --git a/.lando.local.example.yml b/.lando.local.example.yml new file mode 100644 index 0000000..6f6e3b7 --- /dev/null +++ b/.lando.local.example.yml @@ -0,0 +1,104 @@ +############################### +## Local override for lando ## +############################## + +###################### +## !! IMPORTANT !!! ## +## To run multiple copies of the same project, the following properties must be +## unique per project: +## - lagoon-project `x-lagoon-project` +## - default-url (which affects LAGOON_ROUTE / LOCALDEV_URL) `x-default-url` +## - lando proxy urls `proxy` +###################### + +x-lagoon-project: &lagoon-project {{ GOVCMS_PROJECT_NAME }} + +x-default-url: &default-url http://{{ GOVCMS_PROJECT_NAME }}.docker.amazee.io + +# Lando proxy urls. +proxy: + nginx: + hostname: {{ GOVCMS_PROJECT_NAME }}-nginx.lndo.site:8080 + # solr: + # hostname: {{ GOVCMS_PROJECT_NAME }}-solr.lndo.site:8983 + +# lando doesn't define .env as dockers vars @see lando/lando#1616 +x-environment: &default-environment + COMPOSE_PROJECT_NAME: *lagoon-project + DEV_MODE: true + GOVCMS_IMAGE_VERSION: &govcms-image-version {{ GOVCMS_VERSION }}.x-latest + LAGOON_ENVIRONMENT_TYPE: local + LOCALDEV_URL: *default-url + # If changing the image via `MARIADB_DATA_IMAGE` AFTER using the lando project, + # then use `lando destroy` or remove one the database volumes via terminal + # commands noted in lando base file. + MARIADB_DATA_IMAGE: &MARIADB_DATA_IMAGE govcms/mariadb-drupal:{{ GOVCMS_VERSION }}.x-latest + #MARIADB_DATA_IMAGE: &MARIADB_DATA_IMAGE gitlab-registry-production.govcms.amazee.io/org/project/mariadb-drupal-data + #STAGE_FILE_PROXY_URL: http://govcms.docker.amazee.io + X_FRAME_OPTIONS: SameOrigin + #VOLUME_FLAGS: cached + GOVCMS_DEPLOY_WORKFLOW_CONFIG: import + LAGOON_PROJECT: *lagoon-project + LAGOON_ROUTE: *default-url + # XDEBUG_ENABLE: '' + # DOCKERHOST: host.docker.internal + # DRUPAL_SHIELD_USER: '' + # DRUPAL_SHIELD_PASS: '' + +x-others: + - GOVCMS_GITHUB_TOKEN: &GOVCMS_GITHUB_TOKEN '' + +# Unique lando project name - uses 'lagoon-project' variable above in same file. +name: *lagoon-project + +############## +## Services ## +############## + +services: + cli: + services: + build: + args: + LAGOON_SAFE_PROJECT: *lagoon-project + GOVCMS_IMAGE_VERSION: *govcms-image-version + GOVCMS_GITHUB_TOKEN: *GOVCMS_GITHUB_TOKEN + image: *lagoon-project + environment: + << : *default-environment + + test: + services: + build: + args: + CLI_IMAGE: *lagoon-project + GOVCMS_IMAGE_VERSION: *govcms-image-version + nginx: + services: + build: + args: + CLI_IMAGE: *lagoon-project + GOVCMS_IMAGE_VERSION: *govcms-image-version + environment: + << : *default-environment + LAGOON_LOCALDEV_URL: *default-url + php: + services: + build: + args: + CLI_IMAGE: *lagoon-project + GOVCMS_IMAGE_VERSION: *govcms-image-version + environment: + << : *default-environment + mariadb: + services: + image: *MARIADB_DATA_IMAGE + environment: + << : *default-environment + # solr: + # services: + # build: + # args: + # GOVCMS_IMAGE_VERSION: *govcms-image-version + # environment: + # << : *default-environment diff --git a/.lando/container/container-scripts/ahoy-run.sh b/.lando/container/container-scripts/ahoy-run.sh new file mode 100755 index 0000000..483b193 --- /dev/null +++ b/.lando/container/container-scripts/ahoy-run.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# Get the lando logger +. /helpers/log.sh + +# Run the command. +bash -c "$*" diff --git a/.lando/container/container-scripts/db-import-prompt.sh b/.lando/container/container-scripts/db-import-prompt.sh new file mode 100755 index 0000000..153076f --- /dev/null +++ b/.lando/container/container-scripts/db-import-prompt.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -e + +# Get the lando logger +. /helpers/log.sh + +mysql() { + # Avoid sandbox comment due to different client versions on cli vs mariadb + # containers. + # @see https://github.com/govCMS/scaffold/issues/133 + CUSTOM_MARIADB_PROGRAM=/opt/custom-mariadb-client/usr/bin/mariadb + # Try to use our newest download version. + if test -f $CUSTOM_MARIADB_PROGRAM; then + "$CUSTOM_MARIADB_PROGRAM" "$@" + # Else use hack to remove sandbox comment. + else + # If std-input, then change it. + if ! test -t 0; then + awk 'NR == 1 && /\/\*M\!999999\\\- enable the sandbox mode \*\// {next} {print}' | command mysql "$@" + else + command mysql "$@" + fi + fi +} +# Pass to sub bash script. +export -f mysql + +echo "Do you really want to import the database file? (yes/no) [no]:" +read -r -p " > " response; +if [ ! "${response}" = "y" ] && [ ! "${response}" = "yes" ]; then + # Abort. + lando_red "Cancelled." +else + bash -c "$*" +fi diff --git a/.lando/networks.external.yml b/.lando/networks.external.yml new file mode 100644 index 0000000..9504990 --- /dev/null +++ b/.lando/networks.external.yml @@ -0,0 +1,3 @@ +networks: + amazeeio-network: + external: true diff --git a/custom/ahoy.lando.yml b/custom/ahoy.lando.yml new file mode 100644 index 0000000..36b4ecd --- /dev/null +++ b/custom/ahoy.lando.yml @@ -0,0 +1,152 @@ + # Example file to copy and paste into custom/ahoy.yml. + ##################### + ## Lando commands ### + ##################### + lando: + service: cli + cmd: echo Use \`ahoy lando-[command]\` to run specific ahoy lando commands instead. + + lando-up: + usage: Build project. [Lando] + cmd: | + lando start "$@" && + ahoy lando-info; + + lando-down: + usage: Delete project (CAUTION). [Lando] + # `lando destroy` already has a prompt. + cmd: lando destroy + + lando-build: + usage: Build project. [Lando] + cmd: | + lando rebuild "$@" + ahoy lando-govcms-deploy && ahoy lando-info; + + lando-cli: + usage: Start a shell inside cli container. [Lando] + cmd: lando ssh -s cli + + lando-run: + usage: Run command inside cli container. [Lando] + cmd: docker exec -it $(ahoy lando-app-name)_cli_1 bash -c "$*" + + lando-govcms-deploy: + usage: Runs deployment commands (e.g. config import, updb, cr, set up file_stage_proxy). [lando] + cmd: | + lando ssh -s cli -c "mkdir -p /app/web/sites/default/files/private/tmp && \ + /app/vendor/bin/govcms-db-update && \ + /app/vendor/bin/govcms-config-import && \ + /app/vendor/bin/govcms-cache-rebuild && \ + /app/vendor/bin/govcms-enable_modules" + + lando-drush: + usage: Run drush commands in cli container. [Lando] + cmd: lando drush "$@" + + lando-logs: + usage: Show Docker logs. [Lando] + cmd: lando logs "$@" + + lando-ps: + usage: List running Docker containers. [Lando] + # Find Lando app name and pass to docker docker container ls + cmd: ahoy lando-app-name | { read result; head -1; docker container ls -a | grep $result; } + + lando-restart: + usage: Restart Docker containers. [Lando] + cmd: lando restart + + lando-stop: + usage: Stop Docker containers. [Lando] + cmd: lando stop "$@" + + lando-install: + usage: Install the profile. [Lando] + cmd: | + ahoy confirm "Running this command will destroy your current site, are you sure?" && \ + (lando ssh -u 0 -s cli -c "drush si -y govcms \"$@\"" && ahoy lando-govcms-deploy) || \ + echo "Cancelled." + + lando-login: + usage: Login to a website. [Lando] + cmd: | + lando ssh -s cli -c "drush -y cset tfa.settings reset_pass_skip_enabled true" && \ + lando ssh -s cli -c "drush uinf --uid 1 --field name" | xargs -I % lando ssh -s cli -c "drush uublk %" && \ + lando ssh -s cli -c "drush uli" + + lando-unloop: + usage: Fix local redirect loop [Lando] + # Make the PHP code, escape it and run in docker not lando due to issue + # lando/lando#212 + cmd: | + DRUSH_TEMP_COMMAND=$(cat <<'END' + $u=\Drupal\user\Entity\User::load(1); $u->set("field_password_expiration", "0"); $u->save(); + $u=\Drupal\user\Entity\User::load(1); $u->set("field_last_password_reset", date("Y-m-d\TH:i:s")); $u->save(); + END + ); DRUSH_TEMP_COMMAND="$(printf "\"%q\"" $DRUSH_TEMP_COMMAND)" + docker exec -it $(ahoy lando-app-name)_cli_1 bash -c "drush ev \"$DRUSH_TEMP_COMMAND\"" + + lando-mysql-import: + usage: Pipe in a sql file. `ahoy lando-mysql-import local.sql` [Lando] + cmd: | + if [ -e "$@" ] ; then + lando ssh -s cli -c 'drush sql-drop' && + lando ssh -s cli -c 'drush sql-cli' < "$@" + else echo "Provided sql file" "$@" "does not exist" + fi + + lando-mysql-dump: + usage: Dump data out into a file. `ahoy lando-mysql-dump local.sql` [Lando] + cmd: lando ssh -s cli -c 'drush sql-dump --ordered-dump' > "$@" + + lando-lint: + usage: Lint code [Lando] + cmd: | + lando ssh -s test -c ./vendor/bin/govcms-lint web/modules/custom + lando ssh -s test -c ./vendor/bin/govcms-lint web/themes/custom + + lando-test-behat: + usage: Run Behat tests. [Lando] + cmd: lando ssh -s test -c ./vendor/bin/govcms-behat "$@" + + lando-test-phpunit: + usage: Run phpunit tests [Lando] + cmd: lando ssh -s test -c ./vendor/bin/govcms-phpunit --testsuite govcms + + lando-refresh-db: + usage: Refresh the database container with latest nightly dump. [Lando] + cmd: | + ahoy confirm "Running this command will replace your current database. Are you sure?" && + ( cat .env | grep ^MARIADB_DATA_IMAGE | cut -c20- \ + | xargs -n1 docker pull; docker rm -f -v $(ahoy lando-app-name)_mariadb_1 \ + && lando start ) || + echo OK, probably a wise choice... + + lando-ship-shape: + usage: Run site validation scripts locally [Lando] + cmd: | + docker exec -it $(ahoy lando-app-name)_cli_1 bash -c "shipshape -f /app/vendor/govcms/scaffold-tooling/shipshape.yml --exclude-db --error-code \"$@\"" + + lando-debug: + usage: Enable debug configuration. [Lando] + cmd: | + { ahoy lando-run "php -v|grep -q Xdebug" && echo "Debug is already enabled. Use \`export XDEBUG_ENABLE="" && lando rebuild\` to disable."; } \ + || { export XDEBUG_ENABLE="true" && lando rebuild && \ + ahoy lando-run "php -v|grep -q Xdebug" && echo "Enabled debug configuration. Use \`export XDEBUG_ENABLE="" && lando rebuild\` to disable." || \ + echo "Enabling debug configuration failed."; } + + lando-info: + usage: Print information about this project. [Lando] + cmd: | + echo "Project : "$(ahoy lando-run "echo \$LAGOON_PROJECT" 2>/dev/null) + echo "Site local URL : "$(ahoy lando-run "echo \$LAGOON_ROUTE" 2>/dev/null) + echo "DB port on host : "$(docker port $(ahoy lando-app-name 2>/dev/null)_mariadb_1 3306 | cut -d : -f 2) + if [ "$1" ]; then + echo "One-time login : " $(ahoy lando-login -- --no-browser) + fi + + # Helpers. + lando-app-name: + cmd: lando info 2>/dev/null | grep hostnames | grep -o -P "[^\.]*.internal('|\")" | awk -F . '{print $1}' | head -n 1 + hide: true diff --git a/scripts/scaffold-existing-project-add-lando.sh b/scripts/scaffold-existing-project-add-lando.sh new file mode 100755 index 0000000..d927c22 --- /dev/null +++ b/scripts/scaffold-existing-project-add-lando.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +# +# Modification script for the GovCMS Scaffold chnage varaibles in lando files. +# + +echo "[info] Preparing Lando GovCMS Scaffold" + +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +################## TODO "my-project" is "my" instead? +GOVCMS_NAME=$(grep -oP 'http:\/\/\K[^\n]+(?=\.docker\.amazee\.io)' docker-compose.yml | head -n 1) +GOVCMS_VERSION=$(grep -oP 'GOVCMS_IMAGE_VERSION:-\K\w+' docker-compose.yml | head -n 1) +GOVCMS_TYPE=$(grep -oP '^type:\s+\K\w+' .version.yml | head -n 1) +grep -q '^ solr:$' docker-compose.yml +HAS_SOLR=$? + +if [[ -z "$GOVCMS_NAME" ]]; then + echo "[error]: Cannot determine GovCMS project name." + exit 2 +fi + +if [[ -z "$GOVCMS_VERSION" ]]; then + echo "[error]: Cannot determine GovCMS version." + exit 2 +fi + +if [[ -z "$GOVCMS_TYPE" ]]; then + echo "[error]: Cannot determine scaffold type, must be (saas, saasplus or paas)." + exit 2 +fi + +echo "[info]: Modifying scaffold for GovCMS$GOVCMS_VERSION: $GOVCMS_NAME" + +sed -i.bak "s/{{ GOVCMS_PROJECT_NAME }}/$GOVCMS_NAME/" .lando.base.yml && rm .lando.base.yml.bak +sed -i.bak "s/{{ GOVCMS_PROJECT_NAME }}/$GOVCMS_NAME/" .lando.local.example.yml && rm .lando.local.example.yml.bak +sed -i.bak "s/{{ GOVCMS_VERSION }}/$GOVCMS_VERSION/" .lando.base.yml && rm .lando.base.yml.bak +sed -i.bak "s/{{ GOVCMS_VERSION }}/$GOVCMS_VERSION/" .lando.local.example.yml && rm .lando.local.example.yml.bak + +if [[ "$GOVCMS_TYPE" != "paas" ]]; then + : # Do nothing. +else + sed -i.bak -E 's/(\*default-volumes)([[:space:]]|$|#)/\*paas-volumes\2/' .lando.base.yml && rm .lando.base.yml.bak +fi + +if [[ "$HAS_SOLR" -eq 0 ]]; then + printf "\n${YELLOW}[!! action required !!]${NC}: SOLR has been detected,\n" + printf "please uncomment the lando SOLR proxy and service in lando.base.yml\n" + printf "and .lando.local[.example].yml files.\n\n" +fi + +printf "\n${YELLOW}[!! optional - ahoy !!]${NC}:\n" +printf "If you would like .ahoy.yml integration, see notes in .lando.base.yml.\n\n" + +rm scripts/scaffold-existing-project-add-lando.sh + +echo "[success]: Lando GovCMS scaffold changed!"