Using site aliases with Drush 9, by converting them in Amazee.io Lagoon
One Friday afternoon I tried to run `drush sa` to see the site aliases that were available to my project before I ran a drush sql-sync to clone my database from master to my local development environment.
When I did, the output I received was "No site aliases found." which was unexpected. I tried a few things including
- restarting Pygmy (amazee.io's docker runner)
- restarting Docker
- rebuilding the docker containers for this site (using `docker-compose up -d --build` instead of `docker-compose up -d`)
- finally restarting my machine
At this point I reached out to amazee.io support on rocket chat (free open source alternative to Slack, without history disappearing) where Bastian in Switzerland asked me if I was using Drush 9 with the project. I checked composer.json which usually controls the project specific Drush version used.
Then Elliot in the USA asked me to run `LAGOON_DEBUG=yes drush -v -d sa` which I did, then pasted the output into the channel. It turns out the project was using the wrong Drush version. I also ran `which drush` to see which one it was using and it told me it was `/home/.composer/vendor/bin/drush`.
For some reason it wasn't listening to composer.json to use Drush 8:
"drush/drush": "~8.0",
Whereas `drush status` told me I was running 9.4.0
Instead of resolving this, I decided to challenge myself and jump onto the Drush 9 bandwagon.
Tyler in the USA sent me this documentation which helped me to convert the aliases for use in Drush 9 https://lagoon.readthedocs.io/en/stable/using_lagoon/drupal/drush9/
I renamed `aliases.drushrc.php` to `lagoon.aliases.drushrc.php`, then ran `drush site:alias-convert` which gave me:
[lead-2030]cli-drupal:/app$ drush site:alias-convert
Absolute path to a directory for writing new alias files [/app/drush/sites]:
>[success] Created 1 file(s) at /app/drush/sites. Usually, one commits them to /drush/sites in your Composer project.
legacy_files:
- /app/drush/lagoon.aliases.drushrc.php
converted_files:
lagoon.site.yml:
develop:
host: ssh.lagoon.amazeeio.cloud
options:
command-specific:
sql-sync:
no-ordered-dump: true
root: /app/web
user: lead-2030-develop
ssh:
options: '-o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 32222'
master:
host: ssh.lagoon.amazeeio.cloud
options:
command-specific:
sql-sync:
no-ordered-dump: true
root: /app/web
user: lead-2030-master
ssh:
options: '-o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 32222'
test:
host: ssh.lagoon.amazeeio.cloud
options:
command-specific:
sql-sync:
no-ordered-dump: true
root: /app/web
user: lead-2030-test
ssh:
options: '-o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 32222'
I then ran `drush sa --format=list` which gave me
@lagoon.develop
@lagoon.master
@lagoon.test
I now use these aliases instead of @develop & @master.
These are the drush `site:` commands available in Drush 9
site: site:set (use) Set a site alias that will persist for the current session.
site:alias (sa) Show site alias details, or a list of available site aliases.
site:alias-convert (sa-convert, sac) Convert legacy site alias files to the new yml format.
site:ssh (ssh) Connect to a Drupal site's server via SSH.
site:install (si, sin) Install Drupal along with modules/themes/configuration/profile.