20
Drupal 8 deployment New configuration management system by Andrew Siz

Drupal 8 deploying

Embed Size (px)

Citation preview

Page 1: Drupal 8 deploying

Drupal 8 deployment

New configuration management system

by Andrew Siz

Page 2: Drupal 8 deploying

Let’s look at three cases

1. Simple deployment from dev site to live one.

1. Deployment with usage of git.

1. Deployment with usage of git and drush commands.

Page 3: Drupal 8 deploying

1. Simple deployment from dev site

to live one.So, we have two instances of one site:

http://drupal8.loc/ - dev site

http://drupal82.loc/ - live site

Notes:

Currently in Drupal 8 all site Instances should be cloned from one installed source (sql dump, files, some settings in

settings.php should be the same on all site instances), because you won’t be able to sync all configurations. More info

- https://www.drupal.org/node/1613424

Page 4: Drupal 8 deploying

1.1 Simple Ex.: Trying to change “Default country” to “Ukraine” on dev site.

Go to the admin/config/regional/settings and change current Default country to “Ukraine”. After, click “Save configuration”

Page 5: Drupal 8 deploying

1.2 Export all configurations to config.tar.gz on dev site.

Go to the admin/config/development/configuration/full/export and click “Export” button. You will receive archive with all

configurations

Page 6: Drupal 8 deploying

1.3 Import all configurations to the live site.

Go to the admin/config/development/configuration/full/import on the live site and upload our configurations from

dev site.

Page 7: Drupal 8 deploying

1.4 Check if configurations which we want to apply are correct.

Go to the admin/config/development/configuration on live site and click button “View differences”. In popup we can see

what was changed. If this exactly what we want, we can close the popup and click “Import all”.

Page 8: Drupal 8 deploying

1.5 Check if our configurations of “default country” were deployed.

Go to the admin/config/regional/settings on the live site and see new default country. That’s all :)

Page 9: Drupal 8 deploying

2. Deployment with usage of git.In drupal 8 we have 2 states of configurations:

active - state of configuration which is currently being used.

staging - state of configuration which was changed and which is currently waiting for review.

The active configuration files can be found at sites/default/files/config_XXXX/active (where XXXX is a hash that looks

somewhat like iND62oxf-4DyUHcbCA7mhupb_KEpUaGZ6qcfTnAscNQ). BUT for performance, by default, the active

store is in a "config" table in the database (somewhat analogous to the "variables" table in D7 and below), though the

storage location is swappable.

The staging configuration files can be found by default at sites/default/files/config_XXXX/staging (where XXXX is a

hash that looks somewhat like iND62oxf-4DyUHcbCA7mhupb_KEpUaGZ6qcfTnAscNQ).

Page 10: Drupal 8 deploying

During the installation, Drupal writes the location of the (active & staging) configuration directories to the settings.php

file. For our example we will override location of staging configurations files. But this is not required and will be made

only for showing possibility. So, go to the settings.php and change default location to “staging”. After creating

“staging” folder in our site folder.

NOTE: settings.php configurations should be the same on dev and live sites.

Page 11: Drupal 8 deploying

2.1 Preparing dev and live sites

Before any changes will be made, we should go to admin/config/development/configuration/full/export on dev site and

export configurations archive. After, go to admin/config/development/configuration/full/import on dev site and import this

archive.

Now we can go to “staging” folder and see that this folder is not even empty, but has all configuration files. As you can

mention, after importing all configuration files, they upload to staging folder.

Page 12: Drupal 8 deploying

2.2 Add all site files to Git

Just go to webroot on dev site, commit all site files to git, AND commit our “staging” folder as well. After, pull all these

changes on live site. So, we should have “staging” folder with all files on dev and live site as well. (screenshot)

Page 13: Drupal 8 deploying

2.3 Again simple Ex.: Trying to change “Default country” from “Ukraine” (in our

case) to “Germany” on dev site.

Page 14: Drupal 8 deploying

2.4 Export new changes, and after, revert all changes to get rid of annoying

message

Go to the admin/config/development/configuration/full/export on dev site and export all our changes. After go to

admin/config/development/configuration on dev site, we see message “Your current configuration has changed” and we

see what exactly was changed.(screenshot) To get rid of annoying message we should revert all changes to old state by

click on “import all” button, in any case we already have our new changes in archive which we have downloaded few

seconds ago, so nothing will be lost.

Page 15: Drupal 8 deploying

2.5 Import our new changes on dev site and revert to current state

Go to the admin/config/development/configuration/full/import and upload our archive. After, go to

admin/config/development/configuration and now revert all changes to current state by clicking “Import all” button. On

clicking “Import all” drupal takes all changed configurations from staging folder and moves them to the active (as we

know, by default, active configurations are stored in a database). It means that all changes were applied.

Page 16: Drupal 8 deploying

2.6 Commit and pull all new changes.

In Command-line on dev site we can see that one configuration file was changed (in our case configuration file with

default country)(screenshot). After, commit this file and push to git repo. Go to Command-line on live site and pull all new

changes.

Page 17: Drupal 8 deploying

2.7 Check and apply configurations on live site.

Go to admin/config/development/configuration on live site and check what was changed by clicking the button “View

differences”. In our case it should be something like UA => DE . If this is exactly what we want, we can apply this by clicking

on “Import all” button.(screenshot). After that, our staging settings will be active and we can check it on

admin/config/regional/settings page. That’s all :)

Page 18: Drupal 8 deploying

3. Deployment with usage of git and

drush commandsDrush of 7 version has new commands for working with configurations in Drupal 8. More information you can find on

http://drushcommands.com/drush-7x/.

In general all steps of deployment are mostly the same as in case number 2, but, for example, on live site, after “git

pull”, you can run “drush config-import -y” and all new changes will be immediately applied on site. Pretty handy! ;)

In general that’s all ;)

Page 19: Drupal 8 deploying

FAQHow to install drush 7 for drupal 8?

- https://drupalize.me/blog/201408/upgrading-drush-work-drupal-8

Why active configurations are stored in database and how to swap it to files?

- https://www.drupal.org/node/2241059, for example, there is one module which saves active configuratins in files

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

After pulling new changes on live, I have an error “The staged configuration cannot be imported, because it originates

from a different site than this site. You can only synchronize configuration between cloned instances of this site.”

- please read notes from the slide number 3.

After running “drush config-import -y” I have some errors.

- Try to upload latest dev version of Drupal 8 and Drush 7.

Page 20: Drupal 8 deploying

Sources

https://www.drupal.org/documentation/administer/config

https://www.acquia.com/blog/ultimate-guide-drupal-8-episode-6-new-back-end-features-drupal-8

https://drupalize.me/blog/201408/upgrading-drush-work-drupal-8