Effective D8 Configuration Management

with Git and Drush

Introduction

Blanca Esthela Esqueda Gutierrez

Senior Software Engineer & Drupal Grand Master

OPIN Software

Effective D8 Configuration 

What we will discuss today...

  • Features vs Configuration
  • Configuration and Version Controller
  • Deployment Workflow
  • Configuration folder and settings.php
  • Tips and Troubleshooting
  • Configuration UI vs Terminal
  • Export configuration
  • Import configuration

 

Features vs Configuration

Configuration system (D8), stores configuration data in a consistent manner. All of your site configuration from enabled modules through fields, contact categories to views, are stored with this system.

A feature is a collection of Drupal entities which taken together satisfy a certain use-case.

Features vs Configuration

Configuration and Version Control

Advantages of having "Configuration in Code" under version control (GIT):

  • comparing configuration states
     
  • keeping a history of configuration changes
     
  • moving configuration between sites
     
  • Reverting to previous configuration states

Deployment Workflow

Local

Dev

Stage

Prod

In an ideal world, configuration updates wouldn't be done on production.

Configuration Read-only mode module helps to avoid configuration updates.

After install it only add the following line to settings.php

Deployment Workflow

$settings['config_readonly'] = TRUE;

Unless the prod site doesn't exist yet, export configuration from dev to stage only after the prod db has been copied to stage.

Remember, most of the time the stage site is the combination of the dev code and prod files and db.

Deployment Workflow

The configuration system is designed to optimize the process of moving configuration between instances of the same site, system.site configuration item UUID should be the same. It won't allow exporting the configuration from one site to another.

Configuration can still be overridden in settings.php using the $config variable.

Configuration Folder and Settings.php

Considerations:
  • $config_directories key is arbitrary, as it is the path. Import/Export Drush commands would use the key as specified.
     

  • Use the path suggested by your hosting (If Applicable).
     

  • Configuration folder outside the root folder.
     

  • Make sure that the configuration folder is added to git.

Update settings.php, define the configuration folder:

$config_directories['vcs'] = $app_root.'/../config/'.basename($site_path);

Troubleshooting: 

  • Make sure local and any other environments are using the same configuration folder.
     

  • .gitignore or git update-index --assume-unchanged could avoid the updated version of settings.php to be committed and pushed.
     

  • Be-careful of hosting database information includes, always define the configuration folder after those includes.

Configuration Folder and Settings.php

if (file_exists('/var/www/site-php')) {
  require('/var/www/site-php/[site]/[site]-settings.inc');
}

Synchronization - DB configuration and Configuration folder

Configuration UI

Import full configuration archive or single configuration item.

Configuration UI

Export full configuration archive or single configuration item.

Configuration UI

Export Configuration

It is important to first export the configuration changes and then pull changes from collaborators because the exporting action wipes the directory and re-populates it with the active configuration.

 

Since everything is in git, you can recover from such a mistake without much difficulty but why make your life complicated.

 

Import the configuration before pushing it to another repository. Broken configuration breaks the site, be a nice co-worker.
 

Sometimes at the time of writing, drush will signal a successful import but doesn't actually import it while the UI is more helpful and complains about instances not imported due to missing storage.

Export Configuration

Export Configuration

Use config-export to generate the yml files containing the configuration site.

$ drush config-export vsc

Export Configuration

Because this is a collaborative environment merging work from any other collaborators is needed. Usually a git pull would do the trick, but git is not God so resolve any merging conflicts if needed.

$ git pull

Use commit to version the changes.

$ git commit -am "New site information configuration"

After merging always run config-import.
If the import is successful then configuration changes are ready to export,   If it is not successful then fix the configuration and repeat the steps.

Also, Instead of drush config-import the UI can be use to do the import.

$ drush config-import vsc --preview=diff

Export Configuration

Export Configuration

Run updatedb. Instead of drush updatedb, update.php can be used.

$ drush updatedb

Push to Dev

$ git push

Note:   If you export,  then you import!

Export Configuration

# Use config-export to generate the yml files containing the configuration site.
$ drush config-export vsc

# Use commit to versioning the changes.
$ git commit -am "New site information configuration"

# Merging work from any other collaborators and resolve any merging conflicts.
$ git pull

# After merging always run config-import - Also the UI can be used to import.
$ drush config-import vsc --preview=diff

# Run updatedb - Instead of drush updatedb, update.php can be used.
$ drush updatedb

# Push to Dev
$ git push
  1. First Export and then Pull
     
  2. Import before Push
     
  3. If you export, you have to import

Things to remember:

Export Configuration

Import Configuration


# Use config-export to generate the yml files containing the configuration site.
$ drush config-export vsc

# Use commit to versioning the changes.
$ git commit -am "New site information configuration"

# Merge work from and resolve any merging conflicts if needed.
$ git pull

# After merging always run config-import. Also the UI can be used to import.
$ drush config-import vsc --preview=diff

# Run updatedb, Instead of drush updatedb, update.php can be used.
$ drush updatedb

Skip the first two commands if you want to clone the latest committed configuration, use them only if you want to merge the configuration.

Free Drupal 8 Training

OPIN Software is offering free Drupal 8 training sessions to the attendees of DrupalCamp Ottawa.  Sessions will include:

 

•Drupal 8 Fundamentals

•Drupal 8 Module Development

•Drupal 8 Theming

 

If you are interested, please visit the OPIN booth.

Content Synchronization

We’ve always had a challenge synchronizing content across Drupal environments.

We’ve seen significant progress in the management of system configuration; however, we lack an effective way to deploy content in a similar fashion.

As a result, we’ve spent a lot of time synchronizing content either through migration scripting, import and export files, or “good old fashion” copy and paste.

The content synchronization module provides a mechanism to export single content items, or all content items, from an environment, and move them to another, effortlessly.

Text

Text

Thank You!

Questions?

Blanca Esqueda

Senior Software Engineer

& Drupal Grand Master

blanca.esqueda@opin.ca

https://www.linkedin.com/in/blancaesqueda/

References

  • https://docs.acquia.com/cloud/manage/code/config-d8
  • https://dev.acquia.com/blog/drupal-8-configuration-workflows-using-git
  • http://nuvole.org/blog/2014/aug/20/git-workflow-managing-drupal-8-configuration
  • http://drushcommands.com/drush-8x/config
  • https://www.drupal.org/project/config_readonly
  • https://www.ibm.com/developerworks/community/blogs/robshea/entry/
    deploying_code_configuration_and_content_with_drupal?lang=en
  • https://www.lullabot.com/articles/configuration-management-in-drupal-8-the-key-concepts
  • http://nuvole.org/blog/2014/jun/06/configuration-management-drupal-7-drupal-8

 

https://slides.com/besqueda/d8-configuration-workflow​

DrupalYOW

•Monthly meetup

•First Wednesday of every month

•From 6pm to 8pm

•New and exciting topics

•Expert speakers and presenters from the community

•Meet new people passionate about Drupal

•Get support from the local community FREE pop, beer & pizza

The Open Mic Podcast

OPIN Software is the company behind The Open Mic Podcast, which is released bi-weekly and discusses anything & everything Drupal!

 

We will be hosting a live podcast today at 4pm, in the business track room, and welcome everyone to attend and contribute by discussing what you learned today and what you are hoping for from the community in the future.

To listen to The Open Mic Podcast, please visit:

http://theopenmic.libsyn.com/

Seymour Sponsors

Thank you for your continued support

PACIFIC NORTHWEST DRUPAL SUMMIT 2017

Grouse Sponsors

Thank you for your continued support

PACIFIC NORTHWEST DRUPAL SUMMIT 2017

Cypress Sponsors

Thank you for your continued support

PACIFIC NORTHWEST DRUPAL SUMMIT 2017

D8 Configuration Workflow

By besqueda

D8 Configuration Workflow

Effective D8 Configuration Management Workflow with Git and Drush

  • 3,002