Drupal 7
Wondering how to configure Tugboat for a typical Drupal 7 repository? Every Drupal site tends to have slightly different requirements, so you may need to do more customizing, but this should get you started.
Configure Drupal
A common practice for managing Drupal’s settings.php is to remove sensitive information, such as database credentials,
before committing it to git. Then, the sensitive information is loaded from a settings.local.php file that exists only
on the Drupal installation location.
This pattern works very well with Tugboat. It lets you keep a Tugboat-specific set of configurations in your repository where it can be copied in during the Preview build process.
Add the following to the end of settings.php:
1if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php')) {
2 include DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php';
3}Add a file to the git repository at .tugboat/settings.local.php with the following content:
1<?php
2$databases = array (
3 'default' =>
4 array (
5 'default' =>
6 array (
7 'database' => 'tugboat',
8 'username' => 'tugboat',
9 'password' => 'tugboat',
10 'host' => 'mysql',
11 'port' => '',
12 'driver' => 'mysql',
13 'prefix' => '',
14 ),
15 ),
16);Configure Tugboat
The Tugboat configuration is managed by a YAML file at
.tugboat/config.yml in the git repository. Here’s a basic Drupal 7 configuration you can use as a starting point, with
comments to explain what’s going on:
1services:
2 php:
3 # This uses PHP 8.1.x with Apache: update to match your version of PHP
4 image: tugboatqa/php:8.1-apache
5
6 # Set this as the default service. This does a few things
7 # 1. Clones the git repository into the service container
8 # 2. Exposes port 80 to the Tugboat HTTP proxy
9 # 3. Routes requests to the preview URL to this service
10 default: true
11
12 # Wait until the mysql service is done building
13 depends: mysql
14
15 # A set of commands to run while building this service
16 commands:
17 # Commands that set up the basic preview infrastructure
18 init:
19 # Install opcache and enable mod-rewrite.
20 - docker-php-ext-install opcache
21 - a2enmod headers rewrite
22
23 # Install drush 8.1.17
24 - composer --no-ansi global require drush/drush:8.1.17
25 - ln -sf ~/.composer/vendor/bin/drush /usr/local/bin/drush
26
27 # Link the document root to the expected path. This example links
28 # /docroot to the docroot
29 - ln -snf "${TUGBOAT_ROOT}/docroot" "${DOCROOT}"
30
31 # Commands that import files, databases, or other assets. When an
32 # existing preview is refreshed, the build workflow starts here,
33 # skipping the init step, because the results of that step will
34 # already be present.
35 update:
36 # Use the tugboat-specific Drupal settings
37 - cp "${TUGBOAT_ROOT}/.tugboat/settings.local.php" "${DOCROOT}/sites/default/"
38
39 # Copy the files directory from an external server. The public
40 # SSH key found in the Tugboat Repository configuration must be
41 # copied to the external server in order to use rsync over SSH.
42 - rsync -av --delete user@example.com:/path/to/files/ "${DOCROOT}/sites/default/files/"
43
44 # Alternatively, another common practice is to use the
45 # stage_file_proxy Drupal module. This module lets Drupal serve
46 # files from another publicly-accessible Drupal site instead of
47 # syncing the entire files directory into the Tugboat Preview.
48 # This results in smaller previews and reduces the build time.
49 - drush -r "${DOCROOT}" pm-download stage_file_proxy
50 - drush -r "${DOCROOT}" pm-enable --yes stage_file_proxy
51 - drush -r "${DOCROOT}" variable-set stage_file_proxy_origin "http://www.example.com"
52
53 # Set file permissions such that Drupal will not complain
54 - chgrp -R www-data "${DOCROOT}/sites/default/files"
55 - find "${DOCROOT}/sites/default/files" -type d -exec chmod 2775 {} \;
56 - find "${DOCROOT}/sites/default/files" -type f -exec chmod 0664 {} \;
57
58 # Commands that build the site. This is where you would add things
59 # like feature reverts or any other drush commands required to
60 # set up or configure the site. When a preview is built from a
61 # base preview, the build workflow starts here, skipping the init
62 # and update steps, because the results of those are inherited
63 # from the base preview.
64 build:
65 - drush -r "${DOCROOT}" cache-clear all
66 - drush -r "${DOCROOT}" updb -y
67
68 # What to call the service hosting MySQL. This name also acts as the
69 # hostname to access the service by from the php service.
70 mysql:
71 # Use the latest available 5.x version of MySQL
72 image: tugboatqa/mysql:5-debian
73
74 # A set of commands to run while building this service
75 commands:
76 # Commands that import files, databases, or other assets. When an
77 # existing preview is refreshed, the build workflow starts here,
78 # skipping the init step, because the results of that step will
79 # already be present.
80 update:
81 # Copy a database dump from an external server. The public
82 # SSH key found in the Tugboat Repository configuration must be
83 # copied to the external server in order to use scp.
84 - scp user@example.com:database.sql.gz /tmp/database.sql.gz
85 - zcat /tmp/database.sql.gz | mysql tugboat
86 - rm /tmp/database.sql.gzWant to know more about something mentioned in the comments of this config file? Check out these topics:
- Name your Service
- Specify a Service image
- Leverage Service commands
- Define a default Service
- Set the document root path
- Set up remote SSH access
- Preview build process phases (
init,update,build) - How Base Previews work
- Multisite with Tugboat
Start Building Previews!
Once the Tugboat configuration file is committed to your git repository, you can start building previews!