Zum Inhalt springen

Drupal 8 Website Developer Environments: Unterschied zwischen den Versionen

Aus Computech CMS Wiki
Frederick (Diskussion | Beiträge)
→Short version: Added that you should export Drupal configuration before importing changes so they do not overwrite them.
Frederick (Diskussion | Beiträge)
Zeile 33: Zeile 33:


=== Long version ===
=== Long version ===
First get the changes from the Git repository and branch. Checkout the branch that you want to get changes from. Then:
First  
  git pull
 
get the changes from the remote dev Git repository. On your Git Flow feature branch that you want to get changes from:
  git pull origin dev
Next import changes into the development environment with:
Next import changes into the development environment with:
   drush config-import
   drush config-import

Version vom 3. Februar 2017, 13:08 Uhr

Managing Development Environments

This section describes how to use composer, drush, git, git flow and Drupal Configuration Management to move changes between development environments.

Export main development site configuration to sync directory

The location of site configuration sync directory should be configured in the settings.php file or settings.local.php. Many are using ../config/sync. This is outside the webroot for security reasons. The command export a Drupal 8 website configuration to the configuration sync directory:

drush config-export

or use the short command:

drush cex

To export Drupal configuration and choose changes to commit to git run:

drush cex --add

To export Drupal configuration and commit all changes to current git branch:

drush cex --commit --message="This is the commit message."

To export Drupal configuration and commit all changes to current git branch and push to remote git repository:

drush cex --push --message="This is the commit message."

Import configuration changes into your developer environment

Short version

First go to the webroot folder (or use your sites drush site alias from anywhere) and first check that you do not have any configuration changes that will be overwritten with:

drush cex

If you do have changes that should not be overwritten answer yes to have them exported. Then in the project root do:

git pull origin dev
composer install

Then in the Drupal webroot do:

drush cim
drush updatedb
drush cr

Long version

First

get the changes from the remote dev Git repository. On your Git Flow feature branch that you want to get changes from:

git pull origin dev

Next import changes into the development environment with:

 drush config-import

Or use the short form:

drush cim

If you would like to see a diff of the changes that will be applied:

drush cim --preview=diff

After importing Drupal configuration it is always good to rebuild a Drupal 8 site and clear all its caches with:

drush cache-rebuild

Or its short form:

drush cr

NOTE: If modules have been installed, updated or removed you will also need to run:

composer install

This will run all the changes in the composer.json file for the project. This will make all need changes to modules, themes and libraries. In the webroot you will also need to run the database update to make changes to the database that newer version of modules require.

drush updatedb

Git Flow Setup / Configuration

Navigate to the folder where you want the git repository. To create a new git repository run: (you can also use a current git repository, just skip this step)

git init

To configure git flow run:

git flow init

For websites I prefer to use different names then the defaults for the production releases and the next releases. Production releases are on the live branch and the next release branch is on the dev branch.

No branches exist yet. Base branches must be created now.
Branch name for production releases: [master] live
Branch name for "next release" development: [develop] dev
How to name your supporting branch prefixes?
Feature branches? [feature/] 
Bugfix branches? [bugfix/] 
Release branches? [release/] 
Hotfix branches? [hotfix/] 
Support branches? [support/] 
Version tag prefix? [] 
Hooks and filters directory? [/tmp/aaa-tmp/.git/hooks]

This Git flow configuration only needs to be done once for a developer's local git repository. The is not saved to the remote repository. To see the current Git Flow configuration:

git flow config

Add Bonobo or other remote git repository to local git folder

git remote add 

Then you can pull the remote repository if it has commits or make a commit then you can do:

git push origin <BranchName

z.B for the dev branch

git push origin dev

Set tracking information for git pull for a remote repository

To be able to do just:

git pull

instead of:

git pull origin <BranchName>

You can set the remote branch to pull from each time like this:

git branch --set-upstream-to=<RemoteRepositoryName>/<RemoteBranchName> <LocalBranchName>

z.B to set the Remote repository with the name origin for the local branch dev to the remote branch dev

git branch --set-upstream-to=origin/dev dev

How to start a new git flow branch for development work

Normal development work should be done on "feature" branches not on dev.

git flow start feature <FeatureName>

z.B. new branch for paragraphs theming

git flow start feature paragraphstheming

How to finish your git flow feature branch

When you have finished your work and want to merge your branch into the dev branch and delete your feature branch:

git flow finish <FeatureName>

Or if you are currently on the git flow feature branch you can also use the short version

git flow finish

Add custom theme from separate repository to a developer environment

In the developer environment:

cd themes/custom

Clone repository.

git clone <UrlToRepository>

z.B. MEOS Adminimal Theme

git clone http://192.168.60.12/Bonobo.Git.Server/meostheme.git

Copy Drupal 8 Website to developer environments

  • cd in to the new developer environment:
cd /var/www/meos-fh
  • Initialize the folder for git:
git init
  • Add the Git Repository as a remote called origin:
git remote add origin <repository_URL>
  • Pull the repository to the directory:
git pull
  • Check out the development branch dev:
git checkout dev
  • Fix permissions on sites/default so Drupal can write to it:
chmod -R g+w docroot/sites/default/
  • Change to sites/default directory:
cd docroot/sites/default/
  • Copy as settings.local.php from another development site:
cp  /var/www/meos/docroot/sites/default/settings.local.php ./
  • Fix permissions of settings.local.php
chmod u+w settings.local.php
  • Edit the file:
nano settings.local.php

Change database settings to the new database for the website.

  • Change back to the project folder:
cd ../../../
  • Run Composer to install dependencies:
composer install
  • Pull the database from the main development site: Where @meos.fh is the Drush site alias you want to update.(NOTE:Drush shell alias needs to be created in the aliases file in /etc/drush/ for the pull-live.db command to work.)
drush @meos.fh pull-live-db
  • Import the configuration from the config/sync directory with Drush:
drush @meos.fh cim  #(cim is short for config-import)