Published in


Drupal 8. Docker, composer, bootstrap, laravel-mix boilerplate. CI on GitLab

I’ve created a simple boilerplate to rapidly develop Drupal application based on the technological stack we work day-to-day. Purpose of that was to implement new programmers in Drupal 8 environment in easy way.

The whole stack contains

Installation. Step by step

Start by creating new Drupal 8 instance from composer by calling

composer create-project drupal-composer/drupal-project:8.x-dev helloworld --stability dev --no-interaction

where helloworld is name of folder where the website will be stored.

Then we would merge this with a docker environment by cloning from docker4drupal and then copy the content of the drupal_docker_server into the helloworld folder

git clone drupal_docker_server
rm -R drupal_docker_server/.git
cp -R drupal_docker_server helloworld

Lets amend the volumes sections in drupal_docker_server/docker-compose.yml into

- ./../:/var/www/html

and setup localhost by changing traefik.frontend.rule

- 'traefik.frontend.rule=Host:localhost'

Now docker is ready to by launch

cd helloworld
docker-compose up -d

Visit http://localhost:8888/ to continue installation process. For database use the following settings

DB_HOST: mariadb
DB_USER: drupal
DB_NAME: drupal
DB_DRIVER: mysql

Drupal is installed now lets continue with setting up the frontend environment.

Docker composer and drush.

To call composer just run docker-compose exec php composer … and to run drush just call docker-compose exec php drush … for instance

docker-compose exec php composer update


docker-compose exec php drush config-export

Bootstrap 4 sub-theme.

Lets install bootstrap 4 Drupal theme

docker-compose exec php composer require drupal/bootstrap_barrio

now you need to copy files from subtheme folder into new custom theme. This way you would have sub-theme that extends main theme.

cp -R web/themes/contrib/bootstrap_barrio/subtheme web/themes/custom/helloworld 

where helloworldis custom name of your theme

Rename the following files from bootstrap_barrio_subtheme to helloworld:
bootstrap_barrio_subtheme.theme to helloworld.theme to
bootstrap_barrio_subtheme.libraries.ymlto helloworld.libraries.yml
/config/install/bootstrap_barrio_subtheme.settingsto /config/install/helloworld.settings
/config/schema/bootstrap_barrio_subtheme.schemato /config/schema/helloworld.schema

Edit the file

name: YourName
type: theme
description: 'Your Description.'
version: VERSION
core: 8.x
base theme: bootstrap_barrio
- helloworld/global-styling

Delete the following:

# Information added by packaging script on 2015-11-29
# version: '8.x-4.0-beta1'
# core: '8.x'
# project: 'bootstrap_barrio'
# datestamp: 1448759945
# Information added by packaging script on 2018-04-30
# version: '8.x-4.9'
# core: '8.x'
# project: 'bootstrap_barrio'
# datestamp: 1525127885
# Information added by packaging script on 2018-05-27
version: '8.x-4.12'
core: '8.x'
project: 'bootstrap_barrio'
datestamp: 1527445384

Edit /config/schema/helloworld.schema.yml

# Schema for the configuration files of the Bootstrap Barrio Subtheme.helloworld.settings:
type: theme_settings
label: 'YourTheme settings'

Edit /color/ line 117

// Preview files.
'preview_library' => 'helloworld/color.preview',
'preview_html' => 'color/preview.html',

Edit helloworld.theme

Rename the function from:

function bootstrap_barrio_subtheme_form_system_theme_settings_alter($form, FormStateInterface $form_state)


function helloworld_form_system_theme_settings_alter($form, FormStateInterface $form_state)

visit http://localhost:8888 login into admin panel, and enable the new theme.

Laravel-mix boilerplate

Once empty bootstrap sub-theme is installed lets establish scss and es6 deployment. We’re going to use superb laravel-mix package

Laravel Mix provides a fluent API for defining Webpack build steps for your Laravel application using several common CSS and JavaScript pre-processors. Through simple method chaining, you can fluently define your asset pipeline. For example:

.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');

If you’ve ever been confused and overwhelmed about getting started with Webpack and asset compilation, you will love Laravel Mix. However, you are not required to use it while developing your application. Of course, you are free to use any asset pipeline tool you wish, or even none at all.

To init the laravel-mix create new npm package and get the dependencies by calling

npm init 
npm i laravel-mix -s

We need to establish webpack settings and deploy scripts. Lest create in main folder next to package.json new file webpack.mix.js and put there the following contents

const THEMEDIR = "./web/themes/custom/helloworld";
let mix = require('laravel-mix');
proxy: 'localhost:8888',
files: [
.sass(`${THEMEDIR}/scss/style.scss`, `${THEMEDIR}/css`)
.js(`${THEMEDIR}/js/es6/global.js`, `${THEMEDIR}/js`)
processCssUrls: false

and in package.json amend scripts section

"scripts": {
"dev": "NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"

and lets create web/themes/custom/helloworld/es6/global.js js file, which would be entry file for all out js scripts.

Once this is setup, calling scripts npm run watch launches browser sync at available port (most likely http://localhost:3000) and watches all the css and js changes. It runs browsersync so all the css changes are replaced without refreshing and all the js changes would refresh the browser. You change change browsersync settings in the webpack.mix.js file.

Script npm run prod compress css & js into production ready files.

Continuous Integration

Note that the following setup is good only for staging or test server, not for production use.

We’re going to use CI based on Gitlab. Basically after you push a code to develop branch this builds stage server by doing the following

  • pulls all the data from the git server, and merge files
  • update composer dependencies
  • clear drupal cache
  • import config from yaml files
  • deploy javascript and scss on the server by calling npm

You would need

  1. install the drupal instance on the server — this differs on each machine
  2. have composer and npm installed (or you could user composer.phar file like in example below)
  3. have access to the server by ssh key and add this key into GitLab variables. Ssh key is saved into $SSH_PRIVATE_KEY variable

First lets create deploy script This is just an example you would have to change the values on your machine.

cd /home/qunabu/webapps/helloworld
git fetch
git reset --hard HEAD
git checkout develop
git pull
php72 composer.phar update
php72 /home/qunabu/helloworld/vendor/drush/drush/drush cache-rebuild
php72 /home/qunabu/helloworld/vendor/drush/drush/drush config-import --yes
npm i
npm run dev
echo "success

Change access rights with chmod 700 and test with ./ to see if everything works fine.

Once this step is ready what is left is to have GitLab to call it each time code on develop branch is pushed. Here is and example .gitlab-ci.yaml file

image: epcallan/php7-testing-phpunit:7.1-phpunit5deploy_stage:
stage: deploy
name: stage
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- echo "Deploy to staging server"
- ssh 'exec /home/qunabu/helloworld/mbps/'
- develop

Here is example from Gitlab console of successful build.





Stories from creative software house based in Poland, with a love for all web technology

Recommended from Medium

How to: Create Task Groups Dashboard on Azure DevOps

Smile For The Camera: Snapshot Has Been Taken

Side Quest: Two Control Vectors on Single Script

Game from scratch with C++ and SFML (4)

Digital Dashboard:

A Review: Cloud Developer Nanodegree from Udacity

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mateusz Wojczal

Mateusz Wojczal

founder of Qunabu Interactive from Gdańsk, Poland. Full-stack web developer with over a dozen years of experience.

More from Medium

How to install and Secure Redis on Ubuntu 22.04

Deployment of a Dart Server on Heroku

Get Started with gRPC — CNCF Roadmap

Improve development experience with Redis