Rebuildable và reinstallable Drupal trong phần cài đặt drupal 8

Rebuildable và reinstallable Drupal trong phần cài đặt drupal 8

Wouldn't it be great if???

Configuration management is one of the most useful site development features in Drupal 8. It makes a site's configuration exportable, importable and manageable in git. Whilst building the configuration management feature, a thought that often occurred was "Wouldn't it be great if you can take an existing set of configuration and install a new site from it?".

>> Hướng dẫn cài đặt Drupal VM PHP 7.0.x (configurable) trên Windows

>> Đưa region block vào trong node templates của Drupal 8

>> Hướng dẫn thêm CSS Classes vào Blocks ở Drupal 8

Every Drupal developer has turned up to a new project and had to learn a different way to build a development site. Do you get the code from github? Download a database from production or some other special location? And is that database sanitised? I often wonder how many Drupal developers there are in the world wandering around with production databases on their laptops.

We started to explore the ability to install from configuration in https://www.drupal.org/node/1613424. Why hasn't this made it into Drupal 8 yet? It transpires that changing the installer is hard and it was not a top priority in the run up to the 8.0.0 release. To fix the feature gap, I created the contrib project Configuration Installer. This is a special installation profile that allows you to install from a configuration export.

So problem solved in contrib right? Well, no. Profiles are special weird magic modules. They can do everything a module can do and more. But things don't work the same. You can uninstall the Contact module after installing the Standard profile even though the contact module is listed as a dependency. This causes problems for the Configuration Installer because Standard's hook_install() implementation will error if Contact is not installed. The Configuration Installer can work around that with ugly code but its luck runs out if the install profile has custom or contrib modules included. In order to work, the Configuration Installer swaps the currently active profile during install so Drupal can't find modules or themes buried inside the install profile.

Your site's install profile could contain all the configuration

In an ideal world, I want to get a project's code and use the Drupal installer to select install profile for the site I'm working on and and install it. I want to make some configuration changes, export them, and commit them to git. I want to throw away that site and forget about it. I want to come back six months later and update the code, re-install a fresh site that includes any changes other developers made in the meantime, and continue to work on the site. All without having to think particularly hard. I want to use the standard Drupal tools like the installer, configuration admin UI, and Drush.

The good news is that we can have all this! This is precisely what the patch available at https://www.drupal.org/node/2788777 does. We can change the installer to read from its config/sync directory and run a configuration import instead of the regular install. It builds on the Configuration Installer project but does not require the magic of swapping around the profile, so is much more robust. The final piece of the puzzle is to change the configuration sync directory to the profile's config/sync in settings.php, and it just works. As a happy developer said trying out this for the first time:

I love this workflow :)

How to have a rebuildable and reinstallable Drupal today!

  1. Use https://github.com/drupal-composer/drupal-project to manage your codebase using composer.
  2. Use https://github.com/cweagans/composer-patches to apply the latest patch on https://www.drupal.org/node/2788777 as part of composer install.
  3. Create an install profile with a config/sync directory. The new Install Profile Generator module can do this for you with a simple Drush command.

Now I can update my install profile after making configuration changes by running drush config-export. I can share those changes by pushing the install profile. I can pull in changes from other developers by pulling and running drush config-import. I can rebuild the site from scratch by checking out the codebase and running drush site-install.

Afterthoughts

If you are thinking "Wouldn't it be nice if we could also create some content at the same time?" have a look at the Default Content project. You will need the patch from https://www.drupal.org/node/2833562.

If you are wondering whether applying a patch to core is safe - in this instance I would argue it really is. The only changes the patch makes are to the installer and makes no runtime changes.

Isn't the obfuscated config sync directory generated by core important? Well I'm not a big believer in security through obscurity. But also if you are using Apache then core checks for the presence of a .htaccess in your config sync directory that should prevent access. Other webservers should also be denying access to .yml files by default too.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
công ty Snapseed

Google đã chính thức mua lại công ty Snapseed

Theo trang tin Cnet, vào ngày hôm qua, gã khổng lồ trong lĩnh vực tìm kiếm trực tuyến Google đã chính thức mua lại công ty đứng đằng sau ứng dụng chỉnh sửa và chia sẻ hình ảnh trên iOS Snapseed - một trong những đối thủ sừng sỏ của Instagram - nhằm mục tiêu cạnh tranh trực tiếp với Facebook.

Nhà máy linh kiện MTXT Apple MacBook Trung Quốc vẫn đóng cửa

Nhà máy linh kiện MTXT Apple MacBook Trung Quốc vẫn đóng cửa

Nhà chức trách Trung Quốc tiếp tục kiểm tra nhà máy sản xuất vỏ nhôm cho MTXT MacBook của Apple sau phàn nàn của cư dân về mùi hôi phát ra từ nơi sản xuất này.

Video: Installing Drush on Mac OS X

Video cài đặt Drush trên Mac OS X

Last weekend we made a video that shows, hopefully, how easy it is to install Drush, the fabulously powerful command line tool that can drastically speed up developing, installing and maintaining Drupal sites. If you're worried about command line, don't fret. You can type, right? Then you can do command line!

Công ty diệt chuột T&C

 

Diet con trung