This repository has been archived by the owner on Feb 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #694 from oxyc/drupal-project
Issue #506: Add support for composer based site builds
- Loading branch information
Showing
11 changed files
with
199 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
Drupal VM is configured to use [Drush make](drush-make.md) by default but supports building Drupal from a custom composer.json or creating a project from a composer package (`composer create-project`). | ||
|
||
## Using composer.json | ||
|
||
1. Copy `example.drupal.composer.json` to `drupal.composer.json` and modify it to your liking. | ||
2. Switch the build system by setting `build_makefile: false` and `build_composer: true` in your `config.yml`. | ||
3. Configure `drupal_core_path` to point to the webroot directory: `drupal_core_path: {{ drupal_composer_install_dir }}/docroot` | ||
|
||
```yaml | ||
build_makefile: false | ||
build_composer: true | ||
drupal_core_path: "{{ drupal_composer_install_dir }}/docroot" | ||
``` | ||
_The file set in `drupal_composer_path` (which defaults to `drupal.composer.json`) will be copied from your host computer into the VM's `drupal_composer_install_dir` and renamed `composer.json`. If you already have a composer.json within that directory, you can set `drupal_composer_path: false`._ | ||
|
||
## Using Composer when [Drupal VM is a composer dependency itself](../other/drupalvm-composer-dependency.md) | ||
|
||
In the scenario where you already have an existing `composer.json` in the root of your project, follow the usual steps for installing with a composer.json but instead of creating a `drupal.composer.json` file, disable the transfering of the file by setting `drupal_composer_path` to `false`, and change `drupal_composer_install_dir` to point to the the directory where it will be located. If `drupal_composer_path` is not truthy, Drupal VM assumes it already exists. | ||
|
||
```yaml | ||
build_makefile: false | ||
build_composer: true | ||
drupal_composer_path: false | ||
drupal_composer_install_dir: "/var/www/drupalvm" | ||
drupal_core_path: "{{ drupal_composer_install_dir }}/docroot" | ||
``` | ||
|
||
## Creating a project from a composer package: `composer create-project` | ||
|
||
There's a couple of things you need to configure in your `config.yml`: | ||
|
||
- Switch the build system by setting `build_makefile: false`, `build_composer: false` and `build_composer_project: true`. | ||
- Configure the composer package in `drupal_composer_project_package`. | ||
- Additionally you can adjust the create-project CLI options in `drupal_composer_project_options` as well as add additional dependencies in `drupal_composer_dependencies`. | ||
- Ensure that the webroot configured in the composer package matches the one set in `drupal_core_path`. | ||
|
||
With [drupal-composer/drupal-project](https://github.com/drupal-composer/drupal-project) as an example your `config.yml` overrides would be: | ||
|
||
```yaml | ||
build_makefile: false | ||
build_composer: false | ||
build_composer_project: true | ||
drupal_composer_project_package: "drupal-composer/drupal-project:8.x-dev" | ||
# Added `--no-dev` to avoid installing development dependencies. | ||
drupal_composer_project_options: "--prefer-dist --stability dev --no-interaction --no-dev" | ||
drupal_composer_dependencies: | ||
- "drupal/devel:8.*" | ||
|
||
drupal_core_path: "{{ drupal_composer_install_dir }}/web" | ||
``` | ||
## Improving composer build performance | ||
Opting for composer based installs will most likely increase your VM's time to provision considerably. | ||
If you manage multiple VM's own your computer, you can use the [`vagrant-cachier` plugin](http://fgrehm.viewdocs.io/vagrant-cachier/) to share Composer's package cache across all VM's. The first build will be as slow as before but subsequent builds with the same `vagrant_box` (eg `geerlingguy/ubuntu1604`) will be much faster. | ||
|
||
1. Install the plugin on your host computer: `vagrant plugin install vagrant-cachier` | ||
2. Create a `Vagrantfile.local` next to your `config.yml` with the following: | ||
|
||
```rb | ||
config.cache.scope = :box | ||
config.cache.auto_detect = false | ||
config.cache.enable :generic, { :cache_dir => "/home/vagrant/.composer/cache" } | ||
``` | ||
|
||
_Note: Out of the box, sharing the Composer cache is not supported as the plugin requires PHP to be installed when the VM first boots up. This is why the generic cache bucket is used instead._ | ||
|
||
_You can also use this plugin to share other package manager caches. For more information read the [documentation](http://fgrehm.viewdocs.io/vagrant-cachier/usage/)._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "custom-project/drupal-vm", | ||
"description": "", | ||
"type": "project", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "", | ||
"role": "" | ||
} | ||
], | ||
"repositories": [ | ||
{ | ||
"type": "composer", | ||
"url": "https://packagist.drupal-composer.org" | ||
} | ||
], | ||
"require": { | ||
"composer/installers": "^1.0.20", | ||
"drupal-composer/drupal-scaffold": "^2.0.1", | ||
"drupal/core": "~8.0", | ||
"drupal/devel": "8.*" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"extra": { | ||
"installer-paths": { | ||
"docroot/core": ["type:drupal-core"], | ||
"docroot/modules/contrib/{$name}": ["type:drupal-module"], | ||
"docroot/profiles/contrib/{$name}": ["type:drupal-profile"], | ||
"docroot/themes/contrib/{$name}": ["type:drupal-theme"], | ||
"drush/contrib/{$name}": ["type:drupal-drush"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
- name: Generate Drupal project with composer package. | ||
command: > | ||
{{ composer_path }} create-project | ||
{{ drupal_composer_project_package }} {{ drupal_composer_install_dir }} | ||
{{ drupal_composer_project_options|default('--prefer-dist --no-interaction') }} | ||
when: not drupal_site_exists | ||
become: no | ||
|
||
- name: Install dependencies with composer require. | ||
command: > | ||
{{ composer_path }} require {{ item }} | ||
chdir={{ drupal_composer_install_dir }} | ||
with_items: "{{ drupal_composer_dependencies|default([]) }}" | ||
become: no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
- name: Ensure drupal_composer_install_dir directory exists. | ||
file: | ||
path: "{{ drupal_composer_install_dir }}" | ||
state: directory | ||
mode: 0775 | ||
become: no | ||
when: drupal_composer_path and not drupal_site_exists | ||
|
||
- name: Copy composer.json into place. | ||
copy: | ||
src: "{{ drupal_composer_path }}" | ||
dest: "{{ drupal_composer_install_dir }}/composer.json" | ||
when: drupal_composer_path and not drupal_site_exists | ||
become: no | ||
|
||
- name: Run composer install. | ||
command: > | ||
composer install | ||
chdir={{ drupal_composer_install_dir }} | ||
when: not drupal_site_exists | ||
become: no | ||
|
||
- name: Install dependencies with composer require. | ||
command: > | ||
{{ composer_path }} require {{ item }} | ||
chdir={{ drupal_composer_install_dir }} | ||
with_items: "{{ drupal_composer_dependencies|default([]) }}" | ||
become: no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
--- | ||
drupalvm_webserver: nginx | ||
|
||
# Test composer based installation. | ||
build_makefile: false | ||
build_composer: true | ||
drupal_core_path: "{{ drupal_composer_install_dir }}/docroot" |