How Do I Start a Drupal 8 Site Build

Submitted by allan on Thu, 01/28/2016 - 16:09

This is part of a series My First D8 Site as A Professional Drupal Developer - Questions With Answers. Be sure to check out my other questions and answers I had.

I personally spent some serious time on this one. As a Developer, I'm plagued by the fact that I want something repeatable... so scripting out a build is important to me. So what is the process I need to take in building a new site. I started with Promet's D7 Framework since it's what I knew best. You can actually get a really good first build using Drupal-VM, but the scripts I'm about to share will help you here as well (except you will need to exchange composer with drush make)

So lets install


    #!/bin/bash
    set -e
    path=$(dirname "$0")
    true=`which true`
    source $path/common.sh

    echo "Installing Drupal minimal profile."
    echo "Installing site...";
    sqlfile=$base/build/ref/$PROJECT.sql
    gzipped_sqlfile=$sqlfile.gz
    if [ -e "$gzipped_sqlfile" ]; then
      echo "...from reference database."
      $drush sql-drop -y
      zcat "$gzipped_sqlfile" | $drush sqlc
    elif [ -e "$sqlfile" ]; then
      echo "...from reference database."
      $drush sql-drop -y
      $drush sqlc < $sqlfile
    else
      echo "...from scratch, with Drupal minimal profile.";
      # Setting PHP Options so that we don't fail while sending mail if a mail system
      # doesn't exist.
      PHP_OPTIONS="-d sendmail_path=`which true`" $drush si minimal --account-name=admin --account-pass=drupaladm1n -y
      if [[ -e "$base/cnf/drupal/system.site.yml" ]]; then
        # Without this, our import would fail in update.sh. See https://github.com/drush-ops/drush/pull/1635
        site_uuid="$(grep "uuid: " "$base/cnf/drupal/system.site.yml" | sed "s/uuid: //")"
        $drush cset system.site uuid $site_uuid -y
      fi
    fi
    source $path/update.sh

Ok lets talk about this. Essentially, what I'm doing here. Importing a D8 database if I got one... or install a new site if I don't. The crucial part here though is that our base site (and everyone else's that is developing on it) needs to have the same start configuration. Features is a good solution, but you will find that importing ALL configuration on a site built from scratch (even via Features) is not feasible because of this problem. You can fix this by sharing a database or do like I do and export the initial configuration and set the site uuid for the site we are developing on. The first person to commit their code defines what this UUID is for everyone. This leads to my next question.

Read more about my quest in my first Drupal 8 site in Configuration Management... How do I use it, and what is it good for?