Oliver is giving a workshop, Automated Testing and Test Driven Development with Drupal 8, next month at DrupalCamp London.
Find out more and register on the DrupalCamp London website.
Announcing the Drupal VM Generator
Warning: This post is over a year old. I don't always update old posts with new information, so some of this information may be out of date.
For the past few weeks, I’ve been working on a personal side project based on Drupal VM. It’s called the Drupal VM Generator, and over the weekend I’ve added the final features and fixed the remaining issues, and tagged the 1.0.0 release.
What is Drupal VM?
What is different to a regular Vagrant VM is that uses a file called
config.yml to configure the machine. Settings such as
drupal_core_path are stored as YAML and passed into the
Vagrantfile and the
playbook.yml file which is used when the Ansible provisioner runs.
In addition to some essential Ansible roles for installing and configuring packages such as Git, MySQL, PHP and Drush, there are also some roles that are conditional and only installed based on the value of other settings. These include Apache, Nginx, Solr, Varnish and Drupal Console.
What does the Drupal VM Generator do?
The Drupal VM Generator is a Symfony application that allows you to quickly create configuration files that are minimal and use-case specific.
Drupal VM comes with an example.config.yml file that shows all of the default variables and their values. When I first started using it, I’d make a copy of
example.config.yml, rename it to
config.yml and edit it as needed, but a lot of the examples aren’t needed for every use case. If you’re using Nginx as your webserver, then you don’t need the Apache virtual hosts. If you are not using Solr on this project, then you don’t need the Solr variables.
For a few months, I’ve kept and used boilerplace versions of
config.yml - one for Apache and one for Nginx. These are minimal, so have most of the comments removed and only the variables that I regularly need, but these can still be quite time consuming to edit each time, and if there are additions or changes upstream, then I have two versions to maintain.
The Drupal VM Generator is a Symfony application that allows you to quickly create configuration files that are minimal and use-case specific. It uses the Console component to collect input from the user, Twig to generate the file, the Filesystem component to write it.
Based on the options passed to it and/or answers that you provide, it generates a custom, minimal
config.yml file for your project.
Here’s an example of it in action:
You can also define options when calling the command and skip any or all questions. Running the following would bypass all of the questions and create a new file with no interaction or additional steps.
Where do I get it?
The recommended method is via downloading the phar file (the same as Composer and Drupal Console). You can also clone the GitHub repository and run the command from there. I’m also wanting to upload it to Packagist so that it can be included if you manage your projects with Composer.
Please log any bugs or feature requests in the GitHub issue tracker, and I’m more than happy to receive pull requests.
If you’re interested in contributing, please feel free to fork the repository and start doing so, or contact me with any questions.
Update 17/02/16: The autoloading issue is now fixed if you require the package via Composer, and this has been tagged as the 1.0.1 release
Questions? Comments? I’m @opdavies on Twitter.
About the Author
Oliver Davies is a Full Stack Web Developer and System Administrator based in the UK. He is a Senior Software Engineer and Technical Team Lead at Inviqa and a part-time freelancer specialising in Drupal, Symfony and Laravel development and Linux systems administration.