Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Drupal VM 3.1 integration. #105

Merged
merged 2 commits into from
Jun 8, 2016
Merged
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ script:
- ./blt.sh ci:build:validate:test -Dcreate_alias=false -Dbehat.run-server=true -Dbehat.launch-phantom=true
# Deploy build artifact.
- ./blt.sh deploy:artifact:build -Ddeploy.commitMsg="Automated commit by Travis CI for Build ${TRAVIS_BUILD_ID}" -Ddeploy.branch="8.x-build"
# Add Drupal VM config to repo.
- ./blt.sh vm:init
# Switch back to 'blt' directory
- cd ../blt
# Run 'blt' phpunit tests, excluding deploy-push tests.
Expand Down
3 changes: 3 additions & 0 deletions template/build/core/phing/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<!-- Contains acsf tasks. -->
<import file="${core.phing.dir}/tasks/acsf.xml"/>

<!-- Contains Drupal VM tasks. -->
<import file="${core.phing.dir}/tasks/vm.xml"/>

<target name="list" hidden="true">
<exec dir="${repo.root}" command="./blt.sh -q -l" passthru="true"/>
</target>
Expand Down
23 changes: 23 additions & 0 deletions template/build/core/phing/tasks/vm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<project name="vm" default="vm:init">

<target name="vm:init" description="Initializes Drupal VM for this project.">
<copy file="${repo.root}/scripts/drupal-vm/drupal-vm.aliases.drushrc.php" todir="${repo.root}/drush/site-aliases">
<filterchain>
<expandproperties />
</filterchain>
</copy>
<mkdir dir="${repo.root}/box" mode="755"/>
<exec dir="${repo.root}" command="composer require --dev geerlingguy/drupal-vm:~3.1" logoutput="true" checkreturn="true"/>
<copy file="${repo.root}/scripts/drupal-vm/config.yml" tofile="${repo.root}/box/config.yml">
<filterchain>
<expandproperties />
</filterchain>
</copy>
<copy file="${repo.root}/scripts/drupal-vm/Vagrantfile" todir="${repo.root}"/>
<!-- Sadly this wipes out comments in the file. -->
<exec dir="${repo.root}" command="${composer.bin}/drupal yaml:update:value ${repo.root}/project.yml drush.default_alias '${project.machine_name}.local'" logoutput="true" checkreturn="true"/>
<exec dir="${repo.root}" command="${composer.bin}/drupal yaml:update:value ${repo.root}/project.yml drush.aliases.local '${project.machine_name}.local'" logoutput="true" checkreturn="true"/>
<exec dir="${repo.root}" command="${composer.bin}/drupal yaml:update:value ${repo.root}/build/custom/phing/build.yml drush.root ''" logoutput="true" checkreturn="true"/>
</target>

</project>
72 changes: 1 addition & 71 deletions template/readme/local-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,78 +27,8 @@ If you must use Windows, we recommend that:

To use [Drupal VM](http://www.drupalvm.com/) with a Drupal project that is generated with BLT:

1. Place your downloaded copy of Drupal VM inside the generated Drupal project folder, and name the drupal-vm directory `box`.
1. Inside the new project's `build/custom/phing/build.yml` file, override the `docroot` used for Drush commands with the value:

```
drush:
root: ''
```
1. Add a drush alias to `drush/site-aliases/aliases.drushrc.php`:

```
// [vagrant_machine_name].local
$aliases['[vagrant_machine_name].local'] = array(
// /var/www/[vagrant_machine_name]/docroot
'root' => '/var/www/[vagrant_machine_name]/docroot',
// vagrant_hostname
'uri' => '[vagrant_hostname]',
// vagrant_hostname
'remote-host' => '[vagrant_hostname]',
'remote-user' => 'vagrant',
'ssh-options' => '-i ~/.vagrant.d/insecure_private_key',
);
```
1. Updating `project.yml` so that `drush.default_alias` is set to your Drupal VM alias.
1. Execute `./blt.sh vm:init` from the project root directory.
1. Follow the Quick Start Guide in [Drupal VM's README](https://github.com/geerlingguy/drupal-vm#quick-start-guide)
Copy link

Choose a reason for hiding this comment

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

2. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Technically it can always be 1 (or any number) since Markdown parses it as a typical ol item in the resulting HTML... I like numbering them in the markdown itself because I usually read Markdown in its native format... but many people like using 1 1 1 1 1 1 since it requires renumbering if you're off (well, technically you could have any number there, but I'm a little OCD, so I always renumber when editing) :D

1. Before you run `vagrant up`, make the following changes to your VM `config.yml` file:

```
# Update the hostname to the local development environment hostname.
vagrant_hostname: [project_local_domain]
vagrant_machine_name: [project_machine_name]

# Provide the path to the project root to Vagrant.
vagrant_synced_folders:
# Set the local_path for the first synced folder to `../`.
- local_path: ../
# Set the destination to the Acquia Cloud subscription machine name.
destination: /var/www/[project_machine_name]
type: nfs

# Set this to `7` for a Drupal 7 site, or `8` for a Drupal 8 site.
drupal_major_version: 8

# Set drupal_core_path to the `destination` in the synced folder
# configuration above, plus `/docroot`.
drupal_core_path: /var/www/[project_machine_name]/docroot

# Set drupal_domain to the same thing as the `vagrant_hostname` above.
drupal_domain: [project_local_domain]

# Set drupal_site_name to the project's human-readable name.
drupal_site_name: [project_human_name]

# If you build the makefile using BLT's built-in Phing task (recommended),
# set `build_makefile` to `false`.
build_makefile: false

# If you need to install the site inside the VM, set `install_site` to
# `true`. Otherwise, after you build the VM, you can import the database
# using Drush, Adminer, or any other method of connecting to the MySQL
# database.
install_site: true

# To add support for XSL, which is used for some BLT-supplied tests, add
# `php5-xsl` to `extra_packages`.
extra_packages:
- unzip
# - php5-xsl

drupal_mysql_user: drupal
drupal_mysql_password: drupal
```


There are also other changes you can make if you choose to match the Acquia Cloud server configuration more closely. See Drupal VM's example configuration changes in Drupal VM's `examples/acquia/acquia.overrides.yml` file.

Expand Down
13 changes: 13 additions & 0 deletions template/scripts/drupal-vm/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# The absolute path to the root directory of the project. Both Drupal VM and
# the config file need to be contained within this path.
ENV['DRUPALVM_PROJECT_ROOT'] = "#{__dir__}"

# The relative path from the project root to the config directory where you
# placed your config.yml file.
ENV['DRUPALVM_CONFIG_DIR'] = "box"

# The relative path from the project root to the directory where Drupal VM is located.
ENV['DRUPALVM_DIR'] = "vendor/geerlingguy/drupal-vm"

# Load the real Vagrantfile
load "#{__dir__}/#{ENV['DRUPALVM_DIR']}/Vagrantfile"
34 changes: 34 additions & 0 deletions template/scripts/drupal-vm/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Update the hostname to the local development environment hostname
vagrant_hostname: ${project.local.hostname}
vagrant_machine_name: ${project.machine_name}

# Set drupal_site_name to the project's human-readable name.
drupal_site_name: "${project.human_name}"

# Provide the path to the project root to Vagrant.
vagrant_synced_folders:
# Set the local_path for the first synced folder to `../`.
- local_path: .
# Set the destination to the Acquia Cloud subscription machine name.
destination: /var/www/${project.machine_name}
type: nfs
Copy link

Choose a reason for hiding this comment

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

Has this been tested? I believe local_path should be kept as . and destination should be /var/www/${project.machine_name}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this has been tested. I did initially attempt to keep it as . and it did not work. I'll double check the value of the destination.


build_composer_project: false
# Toggling this to `true` would invoke `composer install` with the
# projects own `composer.json` successfully.
build_composer: false
drupal_composer_path: false
drupal_composer_install_dir: "/var/www/${project.machine_name}"
drupal_core_path: "{{ drupal_composer_install_dir }}/docroot"

drupal_mysql_user: drupal
drupal_mysql_password: drupal
drupal_mysql_database: drupal

# Set this to 'false' if you don't need to install drupal (using the drupal_*
# settings below), but instead copy down a database (e.g. using drush sql-sync).
install_site: false

# Drupal VM automatically creates a drush alias file in your ~/.drush folder if
# this variable is 'true'.
configure_drush_aliases: false
13 changes: 13 additions & 0 deletions template/scripts/drupal-vm/drupal-vm.aliases.drushrc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

// [vagrant_machine_name].local
$aliases['${project.machine_name}.local'] = array(
// /var/www/[vagrant_machine_name]/docroot
'root' => '/var/www/${project.machine_name}/docroot',
// vagrant_hostname
'uri' => '${project.local.hostname}',
// vagrant_hostname
'remote-host' => '${project.local.hostname}',
'remote-user' => 'vagrant',
'ssh-options' => '-o PasswordAuthentication=no -i ' . drush_server_home() . '/.vagrant.d/insecure_private_key'
);
49 changes: 49 additions & 0 deletions tests/phpunit/DrupalVmTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Drupal;

use Symfony\Component\Yaml\Yaml;

/**
* Class DrupalVM.
*
* Verifies that Drupal VM integration works as expected.
*/
class DrupalVmTest extends \PHPUnit_Framework_TestCase {

/**
* Class constructor.
*/
public function __construct() {
$this->projectDirectory = realpath(dirname(__FILE__) . '/../../');
$this->config = Yaml::parse(file_get_contents("{$this->projectDirectory}/project.yml"));
$this->new_project_dir = dirname($this->projectDirectory) . '/' . $this->config['project']['machine_name'];
}

/**
* Tests Phing vm:init target.
*/
public function testVmInit() {
$this->assertFileExists($this->new_project_dir . '/Vagrantfile');
$this->assertFileExists($this->new_project_dir . '/box/config.yml');
$this->assertFileExists($this->new_project_dir . '/drush/site-aliases/drupal-vm.aliases.drushrc.php');

$this->assertNotContains(
'${project.machine_name}',
file_get_contents($this->new_project_dir . '/box/config.yml')
);
$this->assertNotContains(
'${project.machine_name}',
file_get_contents($this->new_project_dir . '/drush/site-aliases/drupal-vm.aliases.drushrc.php')
);
$this->assertContains(
'drush:',
file_get_contents($this->new_project_dir . '/build/custom/phing/build.yml')
);
$this->assertContains(
'root:',
file_get_contents($this->new_project_dir . '/build/custom/phing/build.yml')
);
}

}