Automate Drupal 8 Deployment Process


Pre condition: you already have all these setup locally or some where in your server to run these. or you can see some example to setup composer, jenkins on your server.

Drupal 8 Deployment can be setup by using following setup:

  • Git: for versioning your code and YAML for configuration files of your settings
    1. confidure your configuration directory by add this line to settings.php

      ['sync'] = __DIR__ . '../config/sync';   
    2. Add them out of root directory.
    3. now when your export or import configurations this will go in this directory.
    4. Add this directory to your git as well. 

      git add config/sync
    5. You can manage your configuration for different stages plus you can also ignor some configurations to import and export by using config_split and config_ignore modules.
  • Drush: to run import or export configuration for deployment. Additionally clear cache or update database. 
    1. There could be different ways to do it.
    2. You can add file in your repository and can run on other stages. 
    3. You can add to jenking shell directely.
    4. This deplooyment script will include some drush commands

                   drush cache:rebuild or drush cr

                   drush updatedb -y

                   drush config:import -y or drush cim -y

                   drush cr 

                  Additionally, you should know about drush config:export -y or drush cex -y .
                 This will be needed whenever you locally make some changes in you site and want to deploy exactly same.

  • Composer: all your site dependencies can be managed like modules, libraries, core or even getting newer version.
    1. you can do alot of alternatives with composer, start with drupal using composer, or just add core, contribe modules themes libraries using composer. e.g,…
    2. than you can add new modules/themes/libraries later stage of project using composer

      composer require drupal/<modulename>
    3. Composer will automatically update your composer.json, adding the module to all the other requirements in the list.
    4. You can also see changes in composer.lock file regarding new module.
    5. These changes will be install during deployment process with composer install
    6. With composer update can update your current drupal core and module version to latest but always carefully apply it. 
    7. You can also update to new drupal module version alone as well

      composer require “drupal/<modulename>:<version>. or
      composer update drupal/modulename --with-dependencies
  • Jenkins: you can setup jobs that can  automate the process.
    1. Main thing is here to connect to your git and  branch to deployment.
    2. run the file as we build earlier or directly run the drush commands in Execute shell. plus also add

      composer install…