Chapter 7

DeployHQ Build

Using DeployHQ Build commands for compiling assets and other useful tasks

Build commands are commmands that you can define to run on our servers before starting a deployment. These commands may fetch dependencies, build assets or anything else you can think of. Any generated files will be uploaded with your deployment.

In order to be able to take advantage of Build Commands in DeployHQ, you'll need to have the addon enabled on your account.

Configuring a build command

To create a new build command, click the Build Commands link on the left hand side of the page, then the New Build Command button on the right hand side:

Build commands

Add a description for your build command, then enter any commands that you wish to run below. If you're running multiple commands, just place each command on a new line.

New command

Enable the option Stop deployment if the command failed? if you want to halt the process if an exit code other than 0 is returned, then click Create Build Command to finish.

Known Hosts

During the build process, your commands may attempt to make an SSH connection to another service such as Github, Codebase or another host. By default we allow connections to any service, however you may manually define hostnames and public keys here to restrict what servers can be connected to with SSH during your build.

Known Hosts

To define a known host, select Known Hosts on the left hand side of the page in your propject, then click the New Known Host button at the top:

New host

Add a description for your host firstly, the public host key below, then click Create Known Host to finish.

Retrieving the host key

When adding a new known host, if you don't know the hostkey, you can obtain it with the command ssh-keyscan -t rsa example.com | cut -d ' ' -f 2-3. The example below shows the command to retrieve the host key for Codebase:

$ ssh-keyscan -t rsa codebasehq.com 2>/dev/null | cut -d ' ' -f 2-3

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqafgFtYVquYfReJa3MGIyGz0RZoc1kfnXHFDjprY4Uy0lwia+35rRa9Aycrf4eySa55JXsg7rOosqpNOi2hSFWHQ/FfKzMH077Vu1X6d5gNBzxR3aJq/zaAJSiRbrUM20NgEHzBiT8x+32zM71E4qjKnGG8AdEqV9AmROXHWddLSs3e5Tsr2+Dkc/lu+Ko4eVjFjW3ZUgTRE3VTd+PDSRGOfmimgBpcuhkBbEyK4+dq7NJKxLbUl9zC7jKPddkWpbonR9CYWj+c8R8MimKLhhSilNRUKuQBNYydol3eX8VNi+PTzAYtB/w8/jl3+BWzj6xAyfMRdeJDyhhTYX+/s+w==

Build Caching

Your build commands contain steps such as fetching dependencies with npm or bundler which may take some time to complete. Caching these files will mean they may not have to be downloaded every time. Within Cached Build Files, you can add an entry for each set of files that you'd like to be cached.

Cached files

Click New Cached File to add an entry, using the same syntax as Excluded Files if you want to cache files matching specific patterns, or entire directories.

Cached file rule

Clean Build

If you want to run a clean build, for example if you want to update some dependancies, just disable the Use build cache? option under your advanced settings when running a deployment, then a brand new set of dependancies will be fetched.

Use build cache

Running a build command

By default, the build command will run during all deployments for your project, but if you wish to override this for a specific deployment, click the Show Advanced Options button below the selected revisions on the deployment page, then enable or disable the Run build commands? option as appropriate.

Run build commands

Fetching remote dependencies

Some builds may require you to fetch dependencies from an authenticated endpoint, in particular a remote repository. If you need to do so, you'll be able to add your DeployHQ project's public key to the authorized_keys file on the repository server, or the deployment/access keys list for the repository if it's hosted with one of the major hosting providers such as Codebase or Github.

For further information about adding the key to a repository hosted with one of the main providers, please take a look at this guide on our manual.

Further information

Out of the box, DeployHQ build runs on Ubuntu 16.04 servers and supports the following languages and tools:

  • PHP 7 and Composer
  • NodeJS (version 8.9.4) with npm, Yarn (1.3.2) and gulp
  • ASP.NET Code 2.0 CLI
  • Ruby & Bundler

When running a build, a new, sandboxed container will be spawned in our build servers. You won't have root access, but you can run anything you like that's available from one of the supported tools.

If there is anything missing that you'd like us to add, please get in touch.