#DrupalCampDublin

One-click automated builds

https://luisrc7.github.io/dcdublin17/

Luis Rodriguez Castromil

Software Engineer @ Capgemini UK

Structure

Simple presentation.

Target for beginners but developers.

Minimum knowledge, I will explain tools.

You can leave now!

Tools & Commands

Don't be afraid of the "command line" "console" "terminal"

It is easy and it will save you a lot of time.

Version control

VCS, Software to organise and control code revisions.

You can save your code locally or remotely and perform easily deployments or restorations.

Keep configuration in code, it can be tested.

GIT

git clone/init

Set up a repository.

If clone, specify a remote server like GitHub or Bitbucket.

git add

Stage your local changes to be commited.

git commit

Save the staged changes into the local repository.

git push

Save your changes to a branch in a remote repository.

git pull

Get the latest version of the code branch-repository.

git hooks

Scripts you can run before or after a git action.

Useful one is pre-commit, you can define atomated tests or syntax check before commiting your code.

Drush

Drush is a command line interface for Drupal.

You can do the common drupal tasks with a command.

download/add/install/uninstall modules, clear caches, download database or files, etc.

drush dl/en/dis MODULE-NAME

Download a module, enable it or disable it.

drush dl views

drush site-install

It will install a drupal site from the drupal downloaded files.

drush site-install --db-url=mysql://DBuser:DBpass@localhost:port/DBname

You can download and install.
drush dl drupal-7.x

drush make

Build a drupal site from a predefined file, called makefile.

drush make d7example.make www

drush rsync

Import files between environments.

drush rsync @d7.dev:%files/ @d7.local:%files

You can exclude some folders with --exclude-paths.

drush sql-sync

Import a database between environments.

drush sql-dump --result-file=/tmp/prod.sql
drush sql-sync @d7.dev @d7.local

You can exclude some tables with --skip-tables-list.

drush updatedb

Run the pending database updates.

drush updatedb -y

-y in any command will reply with Yes to all.

Composer

Dependency manager for PHP applications

Drupal is a PHP application.

composer init

Creates composer.json in the path.

composer require

Add an entry to the composer.json file.

composer require drupal/admin_toolbar

composer.json file

Is the main file where you require your project dependencies.

composer install

Install the defined/required dependencies in your project.

composer.lock file

This file sets the versions for the composer.json dependencies.

If run install with a composer.lock file in your path will install all dependencies from composer.json but will get the specific versions from the composer.lock file.

You can include composer.lock in your repo.

composer update

"force" to update to the latest versions declared in composer.json and it will update your composer.lock

Of course, never update without testing it before.

Makefiles

A bunch of lines where we specify which modules, themes, folders, versions we want to install.

The very basic makefile would have just the Drupal core.


  api = 2
  core = 7.x

  projects[drupal][type] = "core"
  projects[drupal][version] = 7.56
  					

If we want to add modules, we can specify version or path.


  projects[views][version] = 3.18
  projects[views][subdir] = "contrib"
  					

There is also a way to add patches to your modules.


  projects[ctools] = 3.x
  projects[ctools][subdir] = "contrib"
  projects[ctools][patch][] = "http://drupal.org/files/issues/example-patch.patch"
  					

And different options to get your project.


  projects[mytheme][download][type] = git
  projects[mytheme][download][url] = "git://github.com/luisrc7/theme-repo.git"
  projects[mytheme][download][tag] = 7.x-1.0
  projects[mytheme][download][branch] = "feature-xxx"

  libraries[ckeditor][download][type] = get
  libraries[ckeditor][download][url] = "http://download.cksource.com/CKEditor/CKEditor/CKEditor%204.7.3/ckeditor_4.7.3_standard.zip"
  libraries[ckeditor][destination] = libraries
  					

Create Makefiles

Manually, or you can have a base installation already done and you want to export it with drush generate-makefile file.make.

Build a site from Makefile

Just run drush make file.make

Proposed workflow

1. Build the site from a makefile.

2. rsync our filesystem with drush.

3. sync the database with drush and clear sensitive data.

At this point we have our new site with the existing files and database from Production.

Extra useful steps:
(I would say mandatory)

1. Run database updates.

2. Run database or custom scripts.

3. Run our tests, like behat.

Live Demo!

Build a Drupal 7 site from updated make file.

I will leave this example to the end of the presentation if we have time.

Composer builds in Drupal 8

Still not 100% working.

Composer integration with Drupal 8 is still "under development", and there are a few ways to accomplish what we want.

In the drupal documention page you will find more information. https://www.drupal.org/docs/develop/using-composer/using-composer-with-drupal

I am going to follow the Drupal Composer method.

This tool will give us a structure and base from where we could start.

First download/create the composer.json file with this command.

composer create-project drupal-composer/drupal-project:8.x-dev www

From there we can start including our dependencies - modules, themes, etc.

composer require drupal/devel:~1.0
You can add patches with the composer-patches plugin.

  "extra": {
    "patches": {
      "drupal/devel": {
        "Patch description": "http://drupal.org/files/issues/example-patch.patch"
      }
    }
  }
  					
And we could run some commands at the end to ensure Testig, or Automatic Database updates, etc.

  "scripts": {
    "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
    "post-install-cmd": [
      "@drupal-scaffold",
    ],
    "post-update-cmd": [
      "@drupal-scaffold",
    ]
  }
  					

There is also a module to generate this composer.json from an existing site. Composer Generate.

https://www.drupal.org/project/composer_generate

Documentation

Questions?

Thanks.

https://luisrc7.github.io/dcdublin17/
Luis Rodriguez Castromil