Lagoon
Lagoon is an open source container-based hosting platform that provides automated deployments for Drupal applications using Docker and Kubernetes.
This page is for the lead or DevOps engineer who runs a project built from Vortex on Lagoon. It explains what happens on Lagoon during a deployment, how the site detects its environment, and how to run the routine operations. For general Lagoon documentation, see the Lagoon documentation.
Lagoon pulls and builds your code itself after CI asks it to deploy; Lagoon deployment covers that part.
Integration
The following sections describe what the integration does on Lagoon.
Tasks
Vortex gives you the following tasks on Lagoon:
- Fetch a database from a Lagoon environment for local development or CI
- Trigger deployments to Lagoon environments (see Lagoon deployment)
- Run custom commands on Lagoon environments
These tasks read the project name (LAGOON_PROJECT) from your .env file
and the SSH key settings, such as VORTEX_FETCH_DB_SSH_FILE, from
.env.local.
Deployment automation
On each deployment, Vortex runs these steps on Lagoon:
- Notifies configured channels that the deployment is starting
- In production, backs up the database to
web/sites/default/files/private/pre_deployment_backups - In every other environment, fetches the database dump that provisioning imports into a new environment, or into an existing one when the database override is on
- Provisions the site: runs database updates, imports configuration,
rebuilds caches, and runs Drupal's deploy hooks (
drush deploy:hook) - Notifies configured channels about the finished deployment
In production, provisioning never sanitizes the database. With the default
database provision type, it also never overwrites the existing production
database. Step 3 isn't there when the site installs from a profile, and
projects with a migration source database fetch that database too, before
provisioning.
The post-rollout tasks in the
.lagoon.yml
configuration file run these steps. The same file runs a drush cron job
every 15 minutes in both the main and the develop environments, and
defines monitoring URLs for both. Other environments get no cron job.
Environment detection
Vortex detects Lagoon by its LAGOON_KUBERNETES variable and then
applies the settings in
web/sites/default/includes/providers/settings.lagoon.php.
That file applies the following settings:
- It maps the environment to an environment type.
- It sets
reverse_proxytoTRUEandreverse_proxy_headertoHTTP_TRUE_CLIENT_IP. - It gives each branch its own cache prefix, made of the project name and the branch.
- It trusts the hostnames of the environment's Lagoon routes, the internal
nginx-phphostname, and anyamazee.iosubdomain. - It defines the
LAGOON_VERSIONconstant as1when nothing else has.
An environment is production when Lagoon sets its LAGOON_ENVIRONMENT_TYPE
variable to production, or when its branch name equals
VORTEX_LAGOON_PRODUCTION_BRANCH exactly. VORTEX_LAGOON_PRODUCTION_BRANCH
lives in .env and is main by default. Otherwise, main, master,
release/*, and hotfix/* branches count as staging, and every other
branch as development. The production check comes first, so main counts
as staging only when it isn't the production branch. The production steps
in .lagoon.yml use the same 2 checks.
Onboarding
Lagoon onboarding is part of the project setup flow. See Set up hosting in the Installation guide and select Lagoon.
Routine operations
The following sections cover the operations you run against Lagoon environments.
Fetch database
Fetch a database dump from your Lagoon environment for local development or CI builds:
ahoy fetch-db
When the database source (VORTEX_FETCH_DB_SOURCE) is lagoon, the
installer's default for Lagoon projects, the command connects over SSH to
the VORTEX_FETCH_DB_ENVIRONMENT environment, which the installer sets to
main. Both settings live in .env. The command dumps the database there
and downloads the dump. A dump made earlier the same day is reused, and so
is an existing local dump; add --fresh to make a new one.
Run a custom task
Run an arbitrary command in a Lagoon environment through the platform-agnostic task runner, which drives the Lagoon CLI. Run it from the project root on your machine or in a CI job, wherever an SSH key that your Lagoon user accepts is available:
VORTEX_PLATFORM=lagoon \
VORTEX_TASK_CUSTOM_LAGOON_BRANCH=develop \
VORTEX_TASK_CUSTOM_LAGOON_COMMAND="drush cron" \
./vendor/bin/vortex-task custom
VORTEX_TASK_CUSTOM_LAGOON_BRANCH selects the environment and
VORTEX_TASK_CUSTOM_LAGOON_COMMAND is the command to run there. The task
reads the project name and SSH configuration from your .env and
.env.local files. Its other settings have defaults:
VORTEX_TASK_CUSTOM_LAGOON_NAME- the task name shown in Lagoon (default:Automation task)VORTEX_TASK_CUSTOM_LAGOON_PROJECT- the Lagoon project (default: the value ofLAGOON_PROJECT)VORTEX_TASK_CUSTOM_LAGOON_INSTANCE,VORTEX_TASK_CUSTOM_LAGOON_INSTANCE_GRAPHQL,VORTEX_TASK_CUSTOM_LAGOON_INSTANCE_HOSTNAME, andVORTEX_TASK_CUSTOM_LAGOON_INSTANCE_PORT- the Lagoon instance, with the same defaults as the Lagoon deploymentVORTEX_TASK_CUSTOM_LAGOON_SSH_FINGERPRINTandVORTEX_TASK_CUSTOM_LAGOON_SSH_FILE- the SSH key (default file:~/.ssh/id_rsa)VORTEX_TASK_CUSTOM_LAGOON_CLI_PATH,VORTEX_TASK_CUSTOM_LAGOON_CLI_VERSION, andVORTEX_TASK_CUSTOM_LAGOON_CLI_FORCE_INSTALL- the Lagoon CLI's install directory (default:/tmp), its version (default:v0.32.0), and a flag to reinstall it when one is already on the path
Confirm that Lagoon accepted the task. With the default name, the output
shows a Created line for the task, then ends with the finish line:
[ OK ] Created Automation task: project: your_site, branch: develop.
[ OK ] Finished Lagoon task Automation task.
These lines mean Lagoon queued the task, not that the command succeeded,
because the Lagoon CLI returns as soon as the task exists. Follow the task
and its output in the environment's tasks in the Lagoon UI. When Lagoon
rejects the request, the script stops with the Lagoon CLI's error and
prints no Created line.
The runner's other operations, copy-db, copy-files, and purge-cache,
exist only for Acquia. On Lagoon, they stop with an error that says the
operation is not supported on the "lagoon" platform.
Run Drush against remote environments
The shipped drush/sites/lagoon.site.yml file defines an alias for every
environment of the project, such as @lagoon.develop or @lagoon.pr-123.
Drush aliases shows how to
load your SSH key and run commands with them.