Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Convert Drush aliases to Drush 9 syntax (fixes #326). #332

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ popd > /dev/null
# Parse project config
PROJECTCONF=$ROOT/conf/project.yml
eval $(parse_yaml $PROJECTCONF)
ALIASFILE=${project_name}.aliases.drushrc.php
ALIASTARGET=$HOME/.drush/$ALIASFILE
ALIASFILE=self.site.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alias filename should be unique across projects, otherwise only the first one will work as later projects are unable to create their alias file.

ALIASTARGET=$HOME/.drush/sites/$ALIASFILE

if [ -z "$drush_alias_path" ]; then
ALIASPATH=$ROOT/drupal/conf/$ALIASFILE
ALIASPATH=$ROOT/drupal/drush/sites/$ALIASFILE
else
ALIASPATH=$ROOT/${drush_alias_path}/$ALIASFILE
fi
Expand Down
4 changes: 1 addition & 3 deletions docs/Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ git init
## Configure Drupal build

* Edit `drupal/conf/site.yml`, remove things you don't need and add stuff you want in your project.
* Rename `drupal/drush/wundertools.aliases.drushrc.php` to `drupal/drush/[PROJECT_NAME].aliases.drushrc.php` and
configure it to fit your setup.
- this file will be automatically symlinked from `~/.drush` when running vagrant up
* Configure `drupal/drush/sites/self.site.yml` to fit your setup. This file will be automatically symlinked from `~/.drush` when running vagrant up.

## Create new drupal installation

Expand Down
7 changes: 3 additions & 4 deletions drupal/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ services:
build:
# Perform composer install.
- composer install
# Enable Drush aliases.
- chmod +x /app/scripts/drush/aliases.sh
- /app/scripts/drush/aliases.sh
# build_as_root:
# - "apt-get update -y"
# - "apt-get install python-yaml -y"
Expand Down Expand Up @@ -74,7 +77,3 @@ events:
# Clear caches after a database import
post-db-import:
- appserver: cd $LANDO_WEBROOT && drush cr -y
# Enable Drush aliases.
post-start:
- appserver: mkdir -p $LANDO_MOUNT/.drush/site-aliases
- appserver: ln -sf /app/drush/wundertools.aliases.drushrc.php $LANDO_MOUNT/.drush/site-aliases/wundertools.aliases.drushrc.php
38 changes: 38 additions & 0 deletions drupal/drush/Commands/PolicyCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Drush\Commands;

use Consolidation\AnnotatedCommand\CommandData;

/**
* Edit this file to reflect your organization's needs.
*/
class PolicyCommands extends DrushCommands {

/**
* Prevent catastrophic braino. Note that this file has to be local to the
* machine that initiates the sql:sync command.
*
* @hook validate sql:sync
*
* @throws \Exception
*/
public function sqlSyncValidate(CommandData $commandData) {
if ($commandData->input()->getArgument('target') == '@prod') {
throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__]));
}
}

/**
* Limit rsync operations to production site.
*
* @hook validate core:rsync
*
* @throws \Exception
*/
public function rsyncValidate(CommandData $commandData) {
if (preg_match("/^@prod/", $commandData->input()->getArgument('target'))) {
throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__]));
}
}
}
1 change: 1 addition & 0 deletions drupal/drush/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains commands, configuration and site aliases for Drush. See https://packagist.org/search/?type=drupal-drush for a directory of Drush commands installable via Composer.
6 changes: 6 additions & 0 deletions drupal/drush/drush.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# A Drush configuration file
#
# Docs at https://github.com/drush-ops/drush/blob/master/examples/example.drush.yml
#
# Edit or remove this file as needed.
5 changes: 0 additions & 5 deletions drupal/drush/drushrc.php

This file was deleted.

51 changes: 51 additions & 0 deletions drupal/drush/sites/self.site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Docs at https://github.com/drush-ops/drush/blob/master/examples/example.site.yml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be Lando specific environment here as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lando drush command is the correct way to run drush inside lando. There should generally be no need to run drush on the host.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also work for running drush commands on remote servers?

dev:
host: dev.wundertools.com
options:
command-specific:
sql-sync:
no-cache: true
paths:
dump-dir: /home/www-admin
root: /var/www/dev.wundertools.com/web
uri: 'https://dev.wundertools.com'
user: www-admin

local:
host: local.wundertools.com
options:
env: vagrant
parent: '@parent'
site: wundertools
paths:
files: /vagrant/drupal/files
dump-dir: /home/vagrant
root: /vagrant/drupal/web
user: vagrant
ssh:
options: '-i '

prod:
host: wundertools.com
options:
command-specific:
sql-sync:
no-cache: true
paths:
dump-dir: /home/www-admin
root: /var/www/wundertools.com/web
uri: 'https://wundertools.com'
user: www-admin

stage:
host: stage.wundertools.com
options:
command-specific:
sql-sync:
no-cache: true
paths:
dump-dir: /home/www-admin
root: /var/www/stage.wundertools.com/web
uri: 'https://stage.wundertools.com'
user: www-admin
10 changes: 10 additions & 0 deletions drupal/scripts/drush/aliases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to keep the old PATH as well or is this not important?

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:$PATH

set -ex

rm -Rf ~/.drush
mkdir -p ~/.drush/sites

ln -s /app/drush/sites/self.site.yml ~/.drush/sites/self.site.yml
drush cc drush