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

Commit

Permalink
Merge branch 'drush-launcher'
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Jan 30, 2018
2 parents 0863eda + d579225 commit 1f4b79d
Show file tree
Hide file tree
Showing 25 changed files with 368 additions and 83 deletions.
15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ env:
# Nginx and Drush make file test - Ubuntu 16.04.
- type: nginx-drush-make
distro: ubuntu1604
local_config: tests/ubuntu-16-nginx.config.yml
local_config: tests/ubuntu-16-nginx-drush-make.config.yml
config_dir: /var/www/drupalvm/config

# TODO: See https://github.com/geerlingguy/drupal-vm/issues/1675
# PostgreSQL - Ubuntu 16.04.
- type: postgresql
distro: ubuntu1604
local_config: tests/ubuntu-16-postgresql.config.yml
config_dir: /var/www/drupalvm/config
DRUSH_BIN: "${DRUPALVM_DIR}/drupal/vendor/drush/drush/drush"
TEST_INSTALLED_EXTRAS: false
# - type: postgresql
# distro: ubuntu1604
# local_config: tests/ubuntu-16-postgresql.config.yml
# config_dir: /var/www/drupalvm/config
# DRUSH_BIN: "${DRUPALVM_DIR}/drupal/vendor/drush/drush/drush"
# TEST_INSTALLED_EXTRAS: false

before_install:
# Pull container.
Expand Down
4 changes: 2 additions & 2 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ drupalvm_cron_jobs: []
# this variable is 'true'.
configure_drush_aliases: true
drush_aliases_host_template: "templates/drupalvm.aliases.drushrc.php.j2"
drush_aliases_host_template_yml: "templates/drupalvm.aliases.yml.j2"
drush_aliases_guest_template: "templates/drupalvm-local.aliases.drushrc.php.j2"
drush_aliases_guest_template_yml: "templates/drupalvm-local.aliases.yml.j2"

# Helper variable to configure the PHP-FPM connection for each Apache
# VirtualHost in the `apache_vhosts` list.
Expand Down Expand Up @@ -234,8 +236,6 @@ extra_packages:
- sqlite

# You can configure almost anything else on the server in the rest of this file.
drush_version: "8.1.15"

extra_security_enabled: false

firewall_enabled: true
Expand Down
13 changes: 10 additions & 3 deletions docs/deployment/drush-make.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
If you want to build a Drupal site using a [Drush make file](http://www.drush.org/en/master/make/) instead of composer, set `drupal_build_composer_project: false`, `drupal_build_makefile: true` and either use the `example.drupal.make.yml` file as a base, or use your own Drush make file: just place it or symlink it into the root of the Drupal VM folder with the filename `drupal.make.yml`. You can also set a separate path to the makefile using the `drush_makefile_path` variable.
If you want to build a Drupal site using a [Drush make file](http://www.drush.org/en/master/make/) instead of Composer, you will need to do the following:

- Set `drupal_build_composer_project: false`
- Set `drupal_build_makefile: true`
- Use the `example.drupal.make.yml` file as a base (copy it to a new file named `drupal.make.yml`), or use your own Drush make file
- (You can also set a separate path to the makefile using the `drush_makefile_path` variable.)
- Set the following options to force an install an older version of Drush (Drush 9+ no longer supports Drush make files):

```yaml
drupal_build_composer_project: false
drupal_build_makefile: true
drush_launcher_install: no
drush_install_from_source: yes
drush_source_install_version: "8.1.15"
```

Have a look at the defaults in `default.config.yml` and tweak the settings as you'd like in your `config.yml`, then run `vagrant up` as in the Quick Start Guide. Within a few minutes, you should have your site running and available at the `drupal_domain` configured in `config.yml`, falling back to the default `http://drupalvm.test` set in `default.config.yml`.
Expand Down
8 changes: 5 additions & 3 deletions docs/extras/drush.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
If you have [Drush](http://www.drush.org) and Ansible installed on your host workstation, and would like to interact with a Drupal site running inside Drupal VM, there are drush aliases automatically created by Drupal VM for each of the virtual hosts you have configured.

> Note: Drush 9.0.0 and later require some architectural changes to the way Drush is installed and used both within Drupal VM and on your host computer. Please check the [Drush](https://github.com/drush-ops/drush/issues) and [Drupal VM](https://github.com/geerlingguy/drupal-vm/issues) issue queues if you encounter any strange behavior when using Drush.
With the example configuration, you can manage the example Drupal site using the Drush alias `@drupalvm.test`. For example, to check if Drush can connect to the site in Drupal VM, run:

```
Expand Down Expand Up @@ -33,9 +35,9 @@ $ drush @drupalvm.test status
Staging config path : [...]
```

Drupal VM automatically generates a drush alias file in `~/.drush/drupalvm.aliases.drushrc.php` with an alias for every site you have defined in the `apache_vhosts` variable.
Drupal VM automatically generates a drush alias file in `~/.drush/drupalvm.aliases.drushrc.php` (for Drush < 9.0.0) and `~/.drush/sites/drupalvm.site.yml` (for Drupal 9.0.0+) with an alias for every site you have defined in the `apache_vhosts` or `nginx_vhosts` variable.

If you want to customize the generated alias file you can override the `drush_aliases_host_template` and `drush_aliases_guest_template` variables in your `config.yml`.
If you want to customize the generated alias file you can override the `drush_aliases_host_template` and `drush_aliases_guest_template` variables (or `_yml` variables for Drush 9.0.0+) in your `config.yml`.

```yaml
drush_aliases_host_template: "{{ config_dir }}/templates/drupalvm.aliases.drushrc.php.j2"
Expand All @@ -62,7 +64,7 @@ If you're locked to an older version of Drush, it is likely that Drush will try
If you're still having issues, you can avoid `sql-sync` entirely and pipe the mysqldump output yourself with:

```
drush @remote sql-dump | drush @drupalvm.drupalvm.test sql-cli
drush @remote sql-dump | drush @drupalvm.drupalvm sql-cli
```

## Running `drush core-cron` as a cron job.
Expand Down
2 changes: 1 addition & 1 deletion docs/extras/xdebug.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ php_xdebug_idekey: netbeans-xdebug
As long as `xdebug` is listed in `installed_extras` Drupal VM is configured to accept the `PHP_IDE_CONFIG`, `XDEBUG_CONFIG` and `PHP_OPTIONS` environment variables over SSH and this can be used to set up some IDE's as well as enable XDebug on a per request basis:

```
PHP_OPTIONS="-d xdebug.default_enable=1" drush @drupalvm.drupalvm.test migrate-import
PHP_OPTIONS="-d xdebug.default_enable=1" drush @drupalvm.drupalvm migrate-import
```

To send the environment variables when using `vagrant ssh`, [create a `Vagrantfile.local`](../extending/vagrantfile.md) with:
Expand Down
1 change: 1 addition & 0 deletions provisioning/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
tags: ['database']

- include: tasks/drush-aliases.yml
when: configure_drush_aliases

- include: tasks/cron.yml
tags: ['cron']
Expand Down
2 changes: 1 addition & 1 deletion provisioning/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- src: geerlingguy.drupal-console
version: 1.1.0
- src: geerlingguy.drush
version: 2.0.2
version: 3.0.0
- src: geerlingguy.elasticsearch
version: 2.1.3
- src: geerlingguy.firewall
Expand Down
5 changes: 4 additions & 1 deletion provisioning/roles/geerlingguy.drush/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
services: docker

env:
# Normal installation.
# Default installation.
- distro: centos7
playbook: test.yml
- distro: ubuntu1604
Expand All @@ -11,6 +11,9 @@ env:
playbook: test.yml
- distro: debian9
playbook: test.yml
# Install from composer.
- distro: centos7
playbook: test-composer-install.yml
# Install from source.
- distro: centos7
playbook: test-source-install.yml
Expand Down
59 changes: 46 additions & 13 deletions provisioning/roles/geerlingguy.drush/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,80 @@

[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-drush.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-drush)

Installs [Drush](http://www.drush.org/en/master/), a command line shell and scripting interface for Drupal, on any Linux or UNIX system.
Installs [Drush](http://www.drush.org), a command line shell and scripting interface for Drupal, on any Linux or UNIX system.

## Requirements

PHP must be installed on the system prior to running this role (suggested role: `geerlingguy.php`).

Global composer installation requires Composer to also be installed on the system (suggested role: `geerlingguy.composer`).

Source installation additionally requires Git and Composer to also be installed on the system (suggested roles: `geerlingguy.git` and `geerlingguy.composer`).

## Role Variables

Available variables are listed below, along with default values (see `defaults/main.yml`):

drush_phar_url: https://github.com/drush-ops/drush/releases/download/8.1.10/drush.phar
### Drush Launcher

[Drush Launcher](https://github.com/drush-ops/drush-launcher) is a small wrapper around Drush for your global `$PATH`.

It is the recommended way to use `drush`, but there are some situations where you might wish to install and run Drush globally without using Drush Launcher. The following variables control Drush Launcher's installation:

drush_launcher_install: yes

Set to `no` if you don't want the launcher installed.

The URL from which the Drush phar file will be downloaded.
drush_launcher_version: "0.5.1"

drush_path: /usr/local/bin/drush
The version of the Drush Launcher to install. This should exactly match an available [Drush Launcher release](https://github.com/drush-ops/drush-launcher/releases).

drush_launcher_phar_url: https://github.com/drush-ops/drush-launcher/releases/download/{{ drush_launcher_version }}/drush.phar

The URL from which the Drush Launcher phar file will be downloaded.

drush_launcher_path: /usr/local/bin/drush

The path where drush will be installed and available to your system. Should be in your user's `$PATH` so you can run commands simply with `drush` instead of the full path.

drush_config: ~/.drush
### Drush global install via Composer

Path to the directory where Drush will store its generated config.
Some people need to have the full power of `drush` available globally, and this role allows the global install of Drush via Composer. If using this option, make sure you have Composer installed!

drush_install_from_source: no
drush_composer_global_install: no

Whether to use Git and Composer to install Drush from source.
Set to `yes` (and set `drush_launcher_install` to `no`) if you want to install `drush` globally using Composer.

drush_version: 8.1.10
drush_composer_version: "~9.0"

The version of Drush to download (examples: `8.1.10`, `8.1.9`). This should exactly match an available [Drush release](https://github.com/drush-ops/drush/releases). Note that setting `drush_install_from_source` to `yes` changes the possible values for `drush_version`--see below for more information.
The version constraint for the global Drush installation.

drush_composer_update: no

Whether to run `composer update drush/drush` to ensure the version of Drush installed globally is the latest version.

drush_composer_path: /usr/local/bin/drush

The path in which a symlink to the Drush binary installed via Composer should be placed.

> NOTE: Composer 'global' installation is global _to the user under which Drush is installed_—e.g. if you install globally using the root user, `drush` will only work properly as `root` or when using `sudo`.
### Variables used for source install (Git).

drush_install_path: /usr/local/share/drush
You can also install Drush from source if you need a bleeding-edge release, or if you need a specific version which can't be installed via Composer.

drush_install_from_source: no

Set to `yes` (and set `drush_launcher_install` to `no`) if you want to install `drush` globally using the Drush source code.

drush_source_install_bin_path: /usr/local/bin/drush
drush_source_install_path: /usr/local/share/drush

The location of the entire drush installation (includes all the supporting files, as well as the `drush` executable file.

drush_version: "master"
drush_source_install_version: "8.x"

The version of Drush to install (examples: `"master"` for the bleeding edge, `"7.x"`, `"6.x"`, `"6.2.0"`). This should be a string as it refers to a git branch, tag, or commit hash.
The version of Drush to install (examples: `"master"` for the bleeding edge, `"8.x"`, `"7.x"`, `"6.2.0"`). This should be a string as it refers to a git branch, tag, or commit hash.

drush_keep_updated: no
drush_force_update: no
Expand Down
21 changes: 14 additions & 7 deletions provisioning/roles/geerlingguy.drush/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
---
# Install from phar (faster, but less flexible).
drush_version: "8.1.15"
drush_phar_url: https://github.com/drush-ops/drush/releases/download/{{ drush_version }}/drush.phar
drush_path: /usr/local/bin/drush
# Install Drush Launcher.
drush_launcher_install: yes
drush_launcher_version: "0.5.1"
drush_launcher_phar_url: https://github.com/drush-ops/drush-launcher/releases/download/{{ drush_launcher_version }}/drush.phar
drush_launcher_path: /usr/local/bin/drush

# Install Drush via Composer globally.
drush_composer_global_install: no
drush_composer_version: "~9.0"
drush_composer_update: no
drush_composer_path: /usr/local/bin/drush

# Install from source (git clone + composer-based install).
drush_install_from_source: no
drush_install_path: /usr/local/share/drush
# drush_version: "master"
drush_source_install_bin_path: /usr/local/bin/drush
drush_source_install_path: /usr/local/share/drush
drush_source_install_version: "8.x"
drush_keep_updated: no
drush_force_update: no
drush_force_composer_install: no

drush_composer_cli_options: "--prefer-dist --no-interaction"
drush_clone_depth: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Ensure Drush is installed globally via Composer.
composer:
command: require
global_command: yes
arguments: "drush/drush:{{ drush_composer_version }}"
register: drush_composer_require

- name: Update global Drush install if configured.
composer:
command: update
global_command: yes
arguments: "drush/drush --with-dependencies"
when:
- drush_composer_update
- not drush_composer_require.changed

- name: Ensure globally-installed Drush is symlinked into bin dir.
file:
src: "~/.composer/vendor/bin/drush"
dest: "{{ drush_composer_path }}"
state: link
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
- name: Check current state.
stat:
path: "{{ drush_path }}"
path: "{{ drush_launcher_path }}"
register: drush_path_state

- name: Perform cleanup of old symlink.
file:
path: "{{ drush_path }}"
path: "{{ drush_launcher_path }}"
state: absent
when: drush_path_state.stat.islnk is defined and drush_path_state.stat.islnk

- name: Ensure Drush path directory exists.
file:
path: "{{ drush_path | dirname }}"
path: "{{ drush_launcher_path | dirname }}"
state: directory
mode: 0755

- name: Install Drush.
get_url:
url: "{{ drush_phar_url }}"
dest: "{{ drush_path }}"
url: "{{ drush_launcher_phar_url }}"
dest: "{{ drush_launcher_path }}"

- name: Ensure Drush is executable.
file:
path: "{{ drush_path }}"
path: "{{ drush_launcher_path }}"
mode: 0755
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
- name: Clone Drush from GitHub.
git:
repo: https://github.com/drush-ops/drush.git
dest: "{{ drush_install_path }}"
version: "{{ drush_version }}"
dest: "{{ drush_source_install_path }}"
version: "{{ drush_source_install_version }}"
update: "{{ drush_keep_updated }}"
force: "{{ drush_force_update }}"
depth: "{{ drush_clone_depth }}"
register: drush_clone

- name: Check for composer.json
stat: path={{ drush_install_path }}/composer.json
stat: path={{ drush_source_install_path }}/composer.json
register: drush_composer

# See: https://github.com/geerlingguy/ansible-role-drush/issues/6
- name: Ensure Drush can be installed on Debian Wheezy.
shell: >
{{ composer_path }} update {{ drush_composer_cli_options }}
chdir={{ drush_install_path }}
chdir={{ drush_source_install_path }}
when: drush_clone.changed and ansible_distribution == "Debian" and ansible_distribution_release == "wheezy" and drush_composer.stat.exists

- name: Install Drush dependencies with Composer.
shell: >
{{ composer_path }} install {{ drush_composer_cli_options }}
chdir={{ drush_install_path }}
chdir={{ drush_source_install_path }}
when: (drush_clone.changed and drush_composer.stat.exists) or drush_force_composer_install

- name: Create drush symlink.
file:
src: "{{ drush_install_path }}/drush"
dest: "{{ drush_path }}"
src: "{{ drush_source_install_path }}/drush"
dest: "{{ drush_source_install_bin_path }}"
state: link
force: yes

- name: Run drush to finish setting it up.
command: "{{ drush_path }}"
command: "{{ drush_source_install_bin_path }}"
register: drush_result
changed_when: "'Execute a drush command' not in drush_result.stdout"
become: no
9 changes: 6 additions & 3 deletions provisioning/roles/geerlingguy.drush/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
- include: install.yml
when: not drush_install_from_source
- include: install-drush-launcher.yml
when: drush_launcher_install

- include: source-install.yml
- include: install-drush-composer.yml
when: drush_composer_global_install

- include: install-source.yml
when: drush_install_from_source

0 comments on commit 1f4b79d

Please sign in to comment.