In this session, we will look at configuration management, what it is, how it was done in Drupal 7 and how it is now done in Drupal 8.
(French) For those wondering where the accent comes from...
Pixel Onion is an Singapore based digital agency. We help medium and large organisations with digital strategy, user-centric design and web platform development. We try to empower our clients and make their life as easy as possible.
I would like to have a feel of the people attenting this session, can you raise your hand if:
DrupalCamp Cebu 2017
Thibaud (Tibo) Guilpain
In this session, we will look at configuration management, what it is, how it was done in Drupal 7 and how it is now done in Drupal 8.
(French) For those wondering where the accent comes from...
Pixel Onion is an Singapore based digital agency. We help medium and large organisations with digital strategy, user-centric design and web platform development. We try to empower our clients and make their life as easy as possible.
I would like to have a feel of the people attenting this session, can you raise your hand if:
"a systems engineering process for establishing and maintaining consistency of a product's performance, functional, and physical attributes with its requirements, design, and operational information throughout its life."
Thanks wiki, but hum what does that mean for us?
What is a website?
What is a website?
What is a website?
What is a website?
Ok, so ?
Configuration and content are in the database.
Config and content in the db you said?
Yes, and extracting the configuration from it is not easy. single dev could work on his own and deliver the website to the client, but as soon as it is in production and you need to make changes or updates, you would be stuck. You cannot put the client's website on maintenance, work on your update, and push the new database with the changes into production and then reope the website.
Configuration and content are in the database.
Could we separate the tables in the database and just export the relevant configuration ones?
No, not easily.
Config and content in the db you said?
Yes, and extracting the configuration from it is not easy. single dev could work on his own and deliver the website to the client, but as soon as it is in production and you need to make changes or updates, you would be stuck. You cannot put the client's website on maintenance, work on your update, and push the new database with the changes into production and then reope the website.
All in custom modules' code:
Yes I had some hard core colleagues that really didn't like using contrib modules unless they did exactly what they wanted and nothing more.
It is really good to understant how everything works, but really hard to get there. Also requires a lot of knowledge and most of the time reverse engineering.
Can be used to export most of the configuration and has integration with most other modules.
-> Self disciplne is required
Or it can become a real mess. No real standard here though, each developer has his/her own way of sorting it all out.
Features master: allows you to export active modules, themes and permissions into a special master feature.
Devinci: Allows your code to be context aware and switch between environments and automatically change some configuration in the process.
Still quite complex
Lots of experience needed to use all these tools efficiently
Still quite complex
Lots of experience needed to use all these tools efficiently
Always a pain point in Drupal development
Since configuration management was so complicated in D7, and not part of the core, the community felt it needed an overall for Drupal 8, so here comes the CMI.
Basic principles:
Since configuration management was so complicated in D7, and not part of the core, the community felt it needed an overall for Drupal 8, so here comes the CMI.
Basic principles:
Since configuration management was so complicated in D7, and not part of the core, the community felt it needed an overall for Drupal 8, so here comes the CMI.
Basic principles:
Since configuration management was so complicated in D7, and not part of the core, the community felt it needed an overall for Drupal 8, so here comes the CMI.
Basic principles:
Since configuration management was so complicated in D7, and not part of the core, the community felt it needed an overall for Drupal 8, so here comes the CMI.
Basic principles:
Since configuration management was so complicated in D7, and not part of the core, the community felt it needed an overall for Drupal 8, so here comes the CMI.
Basic principles:
Since configuration management was so complicated in D7, and not part of the core, the community felt it needed an overall for Drupal 8, so here comes the CMI.
Think display of content
Basic principles:
Since configuration management was so complicated in D7, and not part of the core, the community felt it needed an overall for Drupal 8, so here comes the CMI.
Think display of content
Think configuration forms
Basic principles:
Basic principles:
Basic principles:
Basic principles:
Basic principles:
drush config-export drush config-import
Interactions between both set of configuration:
Interactions between both set of configuration:
Export:
Very simple and straightforward logic
Interactions between both set of configuration:
Export:
Import:
Very simple and straightforward logic
Needed for conf delete.
TODO :CHECK drush cim --partial !!!!!!!!!!!!!!!!!
Both are copies of each other, like a production and a devlopment environment.
Both are copies of each other, like a production and a devlopment environment.
Export the active configuration to the YAML files
Add the files to Git and push to code repository.
Both are copies of each other, like a production and a devlopment environment.
Export the active configuration to the YAML files
Add the files to Git and push to code repository.
Pull the files into destination environment
Both are copies of each other, like a production and a devlopment environment.
Export the active configuration to the YAML files
Add the files to Git and push to code repository.
Pull the files into destination environment
Import the YAML files as the active configuration.
Both are copies of each other, like a production and a devlopment environment.
Warning: database has to be the same
Workflow to follow for a safe process:
Workflow to follow for a safe process:
Or you would have nothing to export...
Workflow to follow for a safe process:
Or you would have nothing to export...
Export your configuration into files so that they can be merged with your colleagues' work.
Workflow to follow for a safe process:
Or you would have nothing to export...
Export your configuration into files so that they can be merged with your colleagues' work.
to have a safe haven to go back to. So these first three steps are to prepare you for the actual merging of your work with your teammates'
Workflow to follow for a safe process:
Or you would have nothing to export...
Export your configuration into files so that they can be merged with your colleagues' work.
to have a safe haven to go back to. So these first three steps are to prepare you for the actual merging of your work with your teammates'
Merge and solve eventual merge conflicts. Be careful of git here, as if your colleague deleted a config file and you needed it for something new you added, you might not notice. Example: your colleagues deletes a field. it deletes the basic conf of the field and the field instance, since only 1 content type was using it. At the same time, you added that field to another content type. So the associated conf is just a new file for the field's instance. So you merge, it deletes the field default config but keep your field instance file. -> the conf is broken. Best if you see it now, but other wise detected by one of the next steps.
Workflow to follow for a safe process:
Or you would have nothing to export...
Export your configuration into files so that they can be merged with your colleagues' work.
to have a safe haven to go back to. So these first three steps are to prepare you for the actual merging of your work with your teammates'
Merge and solve eventual merge conflicts. Be careful of git here, as if your colleague deleted a config file and you needed it for something new you added, you might not notice. Example: your colleagues deletes a field. it deletes the basic conf of the field and the field instance, since only 1 content type was using it. At the same time, you added that field to another content type. So the associated conf is just a new file for the field's instance. So you merge, it deletes the field default config but keep your field instance file. -> the conf is broken. Best if you see it now, but other wise detected by one of the next steps.
Make sure your modules and all dependencies are up to date.
Workflow to follow for a safe process:
Or you would have nothing to export...
Export your configuration into files so that they can be merged with your colleagues' work.
to have a safe haven to go back to. So these first three steps are to prepare you for the actual merging of your work with your teammates'
Merge and solve eventual merge conflicts. Be careful of git here, as if your colleague deleted a config file and you needed it for something new you added, you might not notice. Example: your colleagues deletes a field. it deletes the basic conf of the field and the field instance, since only 1 content type was using it. At the same time, you added that field to another content type. So the associated conf is just a new file for the field's instance. So you merge, it deletes the field default config but keep your field instance file. -> the conf is broken. Best if you see it now, but other wise detected by one of the next steps.
Make sure your modules and all dependencies are up to date.
Update the db to take your teammate's hook update and module updates into account
Workflow to follow for a safe process:
Or you would have nothing to export...
Export your configuration into files so that they can be merged with your colleagues' work.
to have a safe haven to go back to. So these first three steps are to prepare you for the actual merging of your work with your teammates'
Merge and solve eventual merge conflicts. Be careful of git here, as if your colleague deleted a config file and you needed it for something new you added, you might not notice. Example: your colleagues deletes a field. it deletes the basic conf of the field and the field instance, since only 1 content type was using it. At the same time, you added that field to another content type. So the associated conf is just a new file for the field's instance. So you merge, it deletes the field default config but keep your field instance file. -> the conf is broken. Best if you see it now, but other wise detected by one of the next steps.
Make sure your modules and all dependencies are up to date.
Update the db to take your teammate's hook update and module updates into account
Reimport the config, to make sure it is not broken. D8 will tell you if the config is broken. Will alos tell you if a file is missing as per my example.
Workflow to follow for a safe process:
Or you would have nothing to export...
Export your configuration into files so that they can be merged with your colleagues' work.
to have a safe haven to go back to. So these first three steps are to prepare you for the actual merging of your work with your teammates'
Merge and solve eventual merge conflicts. Be careful of git here, as if your colleague deleted a config file and you needed it for something new you added, you might not notice. Example: your colleagues deletes a field. it deletes the basic conf of the field and the field instance, since only 1 content type was using it. At the same time, you added that field to another content type. So the associated conf is just a new file for the field's instance. So you merge, it deletes the field default config but keep your field instance file. -> the conf is broken. Best if you see it now, but other wise detected by one of the next steps.
Make sure your modules and all dependencies are up to date.
Update the db to take your teammate's hook update and module updates into account
Reimport the config, to make sure it is not broken. D8 will tell you if the config is broken. Will alos tell you if a file is missing as per my example.
Test it all, see if all works as expected (automated tests would be a great help here....)
Workflow to follow for a safe process:
Or you would have nothing to export...
Export your configuration into files so that they can be merged with your colleagues' work.
to have a safe haven to go back to. So these first three steps are to prepare you for the actual merging of your work with your teammates'
Merge and solve eventual merge conflicts. Be careful of git here, as if your colleague deleted a config file and you needed it for something new you added, you might not notice. Example: your colleagues deletes a field. it deletes the basic conf of the field and the field instance, since only 1 content type was using it. At the same time, you added that field to another content type. So the associated conf is just a new file for the field's instance. So you merge, it deletes the field default config but keep your field instance file. -> the conf is broken. Best if you see it now, but other wise detected by one of the next steps.
Make sure your modules and all dependencies are up to date.
Update the db to take your teammate's hook update and module updates into account
Reimport the config, to make sure it is not broken. D8 will tell you if the config is broken. Will alos tell you if a file is missing as per my example.
Test it all, see if all works as expected (automated tests would be a great help here....)
Now you are finally good to push your code to the repo.
If you fail to follow the previous steps and:
If you fail to follow the previous steps and:
you just overrode your work with your colleagues' after all
If you fail to follow the previous steps and:
you just overrode your work with your colleagues' after all
If you fail to follow the previous steps and:
you just overrode your work with your colleagues' after all
If you fail to follow the previous steps and:
you just overrode your work with your colleagues' after all
If you fail to follow the previous steps and:
you just overrode your work with your colleagues' after all
If you fail to follow the previous steps and:
you just overrode your work with your colleagues' after all
Use case: change existing configuration values in different environments $conf in Drupal 7 becomes $config in Drupal 8.
Use case: change existing configuration values in different environments $conf in Drupal 7 becomes $config in Drupal 8.
// Get system site maintenance message text. This value may be overriden by// default from global $config (as well as translations, see below).$message = \Drupal::config('system.maintenance')->get('message');
Use case: change existing configuration values in different environments $conf in Drupal 7 becomes $config in Drupal 8.
// Get system site maintenance message text. This value may be overriden by// default from global $config (as well as translations, see below).$message = \Drupal::config('system.maintenance')->get('message');
To override the value in settings.php, use:
$config['system.maintenance']['message'] = 'Sorry, our site is down now.';
When using $config override outside of settings.php, use a preceding global $config; Note that values overridden via $config within settings.php will not be viewable from the Drupal administration interface
CMI has a built in check that makes sure the uuid of the site is the same, if it is not, won't let you
Sharing configuration with another site (instead of another environment)
Having different configuration per environment: devel ?
CMI has a built in check that makes sure the uuid of the site is the same, if it is not, won't let you
What if I want to have devel only on my dev env? What if I need some dev environment permissions or views? Cannot solve this with what I just showed you.
config_readonly
This module is to prevent users from altering the configuration at all. No edit permitted.
config_readonly
This module is to prevent users from altering the configuration at all. No edit permitted.
To enable readonly mode, enable this module and add this to your settings.php:
$settings['config_readonly'] = TRUE;
or
if (isset($_ENV['AH_SITE_ENVIRONMENT']) && $_ENV['AH_SITE_ENVIRONMENT'] === 'prod') { $settings['config_readonly'] = TRUE;}
To allow all changes via the command line and enable readonly mode for the UI only:
if (PHP_SAPI !== 'cli') { $settings['config_readonly'] = TRUE; } You could similarly toggle read-only mode based on the presence or absence of a file on the webserver (e.g. in a location outside the docroot).
if (!file_exists('/home/myuser/disable-readonly.txt')) { $settings['config_readonly'] = TRUE; }
config_split
config_split
Define sets of configuration that will get exported to separate directories when exporting, and get merged together when importing. It is possible to define in settings.php which of these sets should be active and considered for the export and import.
Works based on config_filter
So, config filter adds a filter in CMI just before the files are written.
Then can put plugins there. Basically hooks that are run on import/export Such as config split...
config_split
Defines black list:
and grey list:
Blacklist:
Greylist:
For example, if you want to override site performance settings in your local split in order to disable css / js aggregation, the greylist would be a good option. This would allow you to store your performance settings for dev / test / prod in the default directory, while also storing an altered version for local development in your local split. You can also achieve this using the blacklist, but you would need to store a copy of the performance settings in each split. If performance settings are the same for dev / test / prod and only vary for the local split, this is duplicative
config_split
When to use it?
-> When you need to define configuration for different environments
config_split
When to use it?
-> When you need to define configuration for different environments
How?
-> Define configuration splits per environment, use environment variable to choose which split to enable on each environment.
config_installer
Installation profile taking over the the Drupal installer in order to set up the website based on exported configuration.
config_installer
Installation profile taking over the the Drupal installer in order to set up the website based on exported configuration.
-> Let's you create new environments without relying on db export.
config_installer
Example workflow:
features
Allow you to add a set of configuration to a website. But not used as a replacement of CMI.
However, it is difficult not to have it overlap with CMI. Does any of you use feature with Drupal 8?
As the module creator said, Features can now focus on doing what it was meant for. Sharing a common set of configuration to a new website so as to skip some recurring development. Photo gallery example.
I would like to have a feel of the people attenting this session, can you raise your hand if:
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |