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 645
Issue #506: Add support for composer based site builds #694
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
copy: | ||
src: "{{ drush_makefile_path }}" | ||
dest: /tmp/drupal.make.yml | ||
when: drupal_site.stat.exists == false | ||
when: not drupal_site_exists | ||
|
||
- name: Ensure drupal_core_path directory exists. | ||
file: | ||
|
@@ -12,23 +12,23 @@ | |
recurse: yes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, what was the reason behind this being recursive? |
||
mode: 0775 | ||
become: no | ||
when: drupal_site.stat.exists == false | ||
when: not drupal_site_exists | ||
|
||
- name: Generate Drupal site with drush makefile. | ||
command: > | ||
{{ drush_path }} make -y /tmp/drupal.make.yml --no-gitinfofile | ||
chdir={{ drupal_core_path }} | ||
when: drupal_site.stat.exists == false | ||
when: not drupal_site_exists | ||
become: no | ||
|
||
- name: Check if a composer.json file is present. | ||
stat: "path={{ drupal_core_path }}/composer.json" | ||
register: drupal_core_composer_file | ||
when: drupal_site.stat.exists == false | ||
when: not drupal_site_exists | ||
|
||
- name: Run composer install if composer.json is present. | ||
command: > | ||
composer install | ||
chdir={{ drupal_core_path }} | ||
when: drupal_site.stat.exists == false and drupal_core_composer_file.stat.exists == true | ||
when: not drupal_site_exists and drupal_core_composer_file.stat.exists | ||
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 |
---|---|---|
@@ -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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is extremely helpful. Hopefully we can get more visibility/testing on this so we can improve build performance across the board. One thing I hate about the current D8 project I'm working on is how, every time I add a module to the
composer.json
and runcomposer update
, I have to wait about 5-10 minutes before I can be productive again...