Skip to content

Commit

Permalink
Adding tugboat support.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Jun 1, 2016
1 parent e9e05e3 commit 681f0e5
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 36 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Drupal editor configuration normalization
# @see http://editorconfig.org/

# This is the top-most .editorconfig file; do not search in parent directories.
root = true

# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# Tab indentation (no size specified)
[Makefile]
indent_style = tab
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Follow the instructions in [INSTALL.md](INSTALL.md) to generate a new project us

"How do I pull down upstream changes from BLT to my BLT-generated project?"

This is a popular question, and it's difficult to answer.
This is a popular question, and it's difficult to answer.

BLT is designed as a "starter kit" rather than a "distribution". It intentionally began with a "fork it and forget it" approach to updates. This is largely due to the fact that BLT generated files are templates that are meant to be customized, and pulling in upstream updates would wipe out those customizations.

Expand All @@ -74,7 +74,7 @@ The ideal approach would be to split each of these into a separate, versioned pr

As a stopgap, you can run the following command to pull in upstream updates to specific files and directories in your BLT generated project:

`./blt.sh setup:blt:update`
`./blt.sh blt:update`

After running, you can review changes via `git diff` and decide what should be committed.

Expand All @@ -83,15 +83,15 @@ After running, you can review changes via `git diff` and decide what should be c
BLT is provided as an open source tool in the hope that it will enabled developers to easily generate new Drupal projects that conform to Acquia Professional Services' best practices.

Please feel free to contribute to the project or file issues via the GitHub issue queue. When doing so, please keep the following points in mind:

* BLT is distributed under the GPLv2 license; WITHOUT ANY WARRANTY.
* The project maintainers make no commitment to respond to support requests,
* The project maintainers make no commitment to respond to support requests,
feature requests, or pull requests.
* All contributions to BLT will be reviewed for compliance with Drupal Coding
Standards and best practices as defined by the project maintainer.
* Feature that are part of the [Road Map](https://github.com/acquia/blt/wiki/Road-Map)
will be prioritized for inclusion.

BLT work is currently being tracked in the [BLT GitHub issue queue]
(https://github.com/acquia/blt/issues) and organized via a
(https://github.com/acquia/blt/issues) and organized via a
[Waffle.io Kanban Board](https://waffle.io/acquia/blt).
6 changes: 5 additions & 1 deletion template/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
insert_final_newline = true

# Tab indentation (no size specified)
[Makefile]
indent_style = tab
2 changes: 1 addition & 1 deletion template/build/core/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
This directory contains the core tasks that ship with BLT. No files in this
directory should be customized. You may pull in upstream changes with:

./blt.sh setup:blt:update
./blt.sh blt:update

Please note that pulling in upstream changes in this way may break your project.
In some cases, you will need to change aspects of your project configuration or
Expand Down
3 changes: 3 additions & 0 deletions template/build/core/phing/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<!-- Defines a list of default properties, available to all targets. -->
<import file="${core.phing.dir}/tasks/properties.xml"/>

<!-- Contains BLT tasks. -->
<import file="${core.phing.dir}/tasks/blt.xml"/>

<!-- Contains Continuous Integration tasks. -->
<import file="${core.phing.dir}/tasks/ci.xml"/>

Expand Down
23 changes: 23 additions & 0 deletions template/build/core/phing/tasks/blt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<project name="blt" default="blt:update">
<target name="blt:update" description="Pulls in upstream changes to project template from BLT repository.">
<echo>You may be prompted to trust GitHub's SSL certification and to enter your GitHub password.</echo>
<echo>If you have two factor authentication enabled for GitHub, you must use an access token in lieu of a password.</echo>
<echo>GitHub access tokens can be generated here: https://github.com/settings/tokens</echo>

<input message="Press any key to continue" propertyName="continue" />

<exec dir="${repo.root}" command="./scripts/blt/update-scaffold" logoutput="true" passthru="true"/>
</target>

<target name="blt:alias" description="Installs the BLT alias for command line usage.">
<echo>BLT can automatically create a Bash alias to make it easier to run BLT tasks.</echo>
<echo>This alias may be created in .bash_profile or .bashrc depending on your system architecture.</echo>
<propertyprompt propertyName="create_alias" defaultValue="y" useExistingValue="true" promptText="Create a bash alias now? (y/n)" />
<if>
<equals arg1="${create_alias}" arg2="y"/>
<then>
<exec dir="${repo.root}/scripts/blt" command="./install-alias.sh" passthru="true" checkreturn="true"/>
</then>
</if>
</target>
</project>
15 changes: 15 additions & 0 deletions template/build/core/phing/tasks/ci.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@
<property name="create_alias" value="n"/>
</phingcall>
</target>

<target name="ci:tugboat:init" description="Initializes default tugboat configuration for this project.">
<copy file="${repo.root}/scripts/tugboat/Makefile" tofile="${repo.root}/Makefile"/>
<copy file="${repo.root}/scripts/tugboat/tugboat.drushrc.aliases.php" todir="${repo.root}/drush/site-aliases">
<filterchain>
<expandproperties />
</filterchain>
</copy>
</target>

<target name="ci:update" description="Update current database to reflect the state of the Drupal file system; uses ci drush alias.">
<phingcall target="setup:update">
<property name="drush.alias" value="${drush.aliases.ci}"/>
</phingcall>
</target>
</project>
10 changes: 4 additions & 6 deletions template/build/core/phing/tasks/local-sync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
<exec dir="${docroot}" command="${drush.cmd} cr" logoutput="true" checkreturn="true"/>
</target>

<target name="local:update" description="Update current database to reflect the state of the Drupal file system.">
<exec dir="${docroot}" command="${drush.cmd} updb -y --entity-updates" logoutput="true" checkreturn="true"/>
<exec dir="${docroot}" command="${drush.cmd} config-import -y --partial" logoutput="true" checkreturn="true"/>
<exec dir="${docroot}" command="${drush.cmd} cc drush" logoutput="true" checkreturn="true"/>
<exec dir="${docroot}" command="${drush.cmd} fra -y" logoutput="true" checkreturn="true"/>
<exec dir="${docroot}" command="../hooks/dev/post-db-copy/dev-mode.sh" logoutput="true"/>
<target name="local:update" description="Update current database to reflect the state of the Drupal file system; uses local drush alias.">
<phingcall target="setup:update">
<property name="drush.alias" value="${drush.aliases.local}"/>
</phingcall>
</target>

</project>
54 changes: 31 additions & 23 deletions template/build/core/phing/tasks/setup.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project name="setup" default="setup">

<target name="setup" description="Install dependencies, builds docroot, installs Drupal."
depends="setup:build:all, setup:drupal:install, setup:blt:alias">
depends="setup:build:all, setup:drupal:install, blt:alias">
<echo>For a full list of available Phing targets, run:</echo>
<echo>./blt.sh -l</echo>
<echo></echo>
Expand Down Expand Up @@ -77,10 +77,17 @@
<param>"install_configure_form.update_status_module='array(FALSE,FALSE)'"</param>
</drush>

<drush command="config-import" assume="yes" alias="${drush.aliases.local}">
<param>--partial</param>
<drush command="config-import" assume="yes" alias="${drush.alias}">
<option name="partial"></option>
</drush>

<!-- Grant execution permissions. -->
<chmod mode="0755">

This comment has been minimized.

Copy link
@danepowell

danepowell Jun 8, 2016

Contributor

This is going to cause problems if there are any files in sites/default/files that have previously been created by the web server. They'll be owned by www-data, so we can't chmod them and Phing will crash.

Maybe you could argue that on a fresh install there shouldn't be any existing files, although you'd obviously want to check for that first. Or just exclude the files directory from this command.

This comment has been minimized.

Copy link
@danepowell

danepowell Jun 8, 2016

Contributor

Created #128 to fix this.

<fileset dir="${docroot}/sites/default">
<include name="**" />
</fileset>
</chmod>

</target>

<target name="setup:git-hooks" description="Installs git hooks to local .git/hooks directory from version controlled scripts/git-hooks directory.">
Expand All @@ -97,26 +104,27 @@
</chmod>
</target>

<target name="setup:blt:update" description="Pulls in upstream changes to project template from BLT repository.">
<echo>You may be prompted to trust GitHub's SSL certification and to enter your GitHub password.</echo>
<echo>If you have two factor authentication enabled for GitHub, you must use an access token in lieu of a password.</echo>
<echo>GitHub access tokens can be generated here: https://github.com/settings/tokens</echo>

<input message="Press any key to continue" propertyName="continue" />

<exec dir="${repo.root}" command="./scripts/blt/update-scaffold" logoutput="true" passthru="true"/>
</target>

<target name="setup:blt:alias" description="Installs the BLT alias for command line usage.">
<echo>BLT can automatically create a Bash alias to make it easier to run BLT tasks.</echo>
<echo>This alias may be created in .bash_profile or .bashrc depending on your system architecture.</echo>
<propertyprompt propertyName="create_alias" defaultValue="y" useExistingValue="true" promptText="Create a bash alias now? (y/n)" />
<if>
<equals arg1="${create_alias}" arg2="y"/>
<then>
<exec dir="${repo.root}/scripts/blt" command="./install-alias.sh" passthru="true" checkreturn="true"/>
</then>
</if>
<target name="setup:update" description="Update current database to reflect the state of the Drupal file system.">
<!-- Execute db updates. -->
<drush command="updb" assume="yes" alias="${drush.alias}">
<option name="entity-updates"></option>
</drush>
<!-- Import configuration. -->
<drush command="config-import" assume="yes" alias="${drush.alias}">
<option name="partial"></option>
</drush>
<!-- Enable features module. -->
<drush command="en" assume="yes" alias="${drush.alias}">
<param>features</param>
</drush>
<!-- Clear drush caches to register features drush commands. -->
<drush command="cc" assume="yes" alias="${drush.alias}">
<param>drush</param>
</drush>
<!-- Revert all features. -->
<drush command="fra" assume="yes" alias="${drush.alias}"/>
<!-- Rebuild caches. -->
<drush command="cr" alias="${drush.alias}"/>
</target>

</project>
4 changes: 4 additions & 0 deletions template/drush/drushrc.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
require __DIR__ . '/../docroot/sites/default/local.drushrc.php';
}

if (getenv('TUGBOAT_URL')) {
$options['uri'] = $_ENV['TUGBOAT_URL'];
}

// Specify the base_url that should be used when generating links
# $options['l'] = 'http://example.com/subdir';

Expand Down
8 changes: 8 additions & 0 deletions template/scripts/tugboat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tugboat-init:
scripts/tugboat/init.sh

tugboat-update:
scripts/tugboat/update.sh

tugboat-build:
scripts/tugboat/build.sh
48 changes: 48 additions & 0 deletions template/scripts/tugboat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Setup

To set up this project with Tugboat, run the following commands from the project root:

```
./blt.sh ci:tugboat:init
```

## Workflow

This workflow is for a brand new repository for which a base preview has never been built or committed.

### Initial Setup
1. Visit `https://dashboard.tugboat.qa/[project]/latest` to access the Base Preview.
2. Initialize the Base Preview, click Actions -> init.
3. Makefile -> tugboat-init is triggered.
4. Commit the Base Preview, click actions -> commit.

### Dev Workflow
5. Submit a Pull Request via GitHub, feature-branch-1 against master.
6. A new container with a clone of Base Preview is created for the PR.
8. Tugboat merges feature-branch-1 into master in PR Preview.
9. Makefile -> tugboat-build is triggered.
10. Merge Pull Request on GitHub.
11. Tugboat deletes the PR Preview.

### Updating Base Preview

12. Visit `https://dashboard.tugboat.qa/[project]/latest` to access the Base Preview.
13. Initialize the Base Preview, click Actions -> update.
14. Makefile -> tugboat-update is triggered.
15. Tugboat commits updated Base Preview.
16. Make manual changes to the Base Preview.
17. Realize that you made mistake.
18. Reset the Base Preview, click Actions -> reset.
19. Base preview is reverted to commit made in step 15

## Troubleshooting

* `Makefile:2: *** missing separator. Stop.`

This is caused by using spaces rather than tabs in your Makefile. If are using PHPStorm with Drupal Coding Standards configuration, you will need to overcome the automated usage of spaces by installing the [Editorconfig plugin](https://plugins.jetbrains.com/plugin/7294) and creating `.editorconfig` file with the following contents:

```
# Tab indentation (no size specified)
[Makefile]
indent_style = tab
```
6 changes: 6 additions & 0 deletions template/scripts/tugboat/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

# Update current database to reflect the state of the Drupal file system
$DIR/../../bolt.sh ci:update
14 changes: 14 additions & 0 deletions template/scripts/tugboat/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DOCROOT=/var/lib/tugboat/docroot

mysql -h mysql -u tugboat -ptugboat -e 'CREATE DATABASE drupal;'
composer selfupdate
composer install

# Install nvm and specified nodejs version.
$DIR/install-node.sh 4.4.1


$DIR/../../bolt.sh ci:setup
27 changes: 27 additions & 0 deletions template/scripts/tugboat/install-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

if [ $# -ne 1 ]; then
echo $0: usage: install-node.sh 4.4.1
exit 1
fi

if [ ! -d "$HOME/.nvm" ]; then
echo "Downloading and installing nvm"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
fi

NODE_VERSION=$1
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
if [[ $(nvm ls $NODE_VERSION | grep "N/A") ]]; then
echo "Downloading and installing node version $NODE_VERSION"
nvm download $NODE_VERSION
nvm install $NODE_VERSION
fi

# Sets version of node in .node-version so that
# it can be picked up by tools like avn.
echo $NODE_VERSION > .node-version

echo "Please run the following command":
echo "source ~/.bashrc && nvm use --delete-prefix $NODE_VERSION"
6 changes: 6 additions & 0 deletions template/scripts/tugboat/tugboat.drushrc.aliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

$aliases['${project.machine_name}.ci'] = array(
'uri' => $_ENV['TUGBOAT_URL'],
'root' => '/var/lib/tugboat/docroot',
);
8 changes: 8 additions & 0 deletions template/scripts/tugboat/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# Import config
cd /var/lib/tugboat/docroot
chown -R www-data sites/default/files

# Update current database to reflect the state of the Drupal file system
$DIR/../../bolt.sh ci:update

0 comments on commit 681f0e5

Please sign in to comment.