Create Custom Environment Variables

Sometimes there are “secret” values or other data that you want to be made available to a Preview, but you don’t want to commit that data to git, and for security reasons, you don’t want to host it somewhere that Tugboat can grab it. These secret values usually include things like API keys to 3rd party services, or values used to encrypt session cookies that need to be unique to Tugboat but shared between your Previews.

Tugboat provides a convenient way of injecting these values into a Preview’s services via custom environment variables. These variables can be found on the Repository Settings page.

Environment Variable Configuration

Like the other environment variables that Tugboat provides, the variables entered here are available to your Previews both while they are building as well as while they are running.

Storing Complex Data

Environment variables are good at storing simple string values. However, what if you need to store something more complex, like an encoded JSON string, or the contents of an arbitrary file? One way of accomplishing that is to base64 encode the value, and then decode the value with a configuration file command.

$ cat file | base64

Store that value into an environment variable. Then, extract it to a file you can use in your Preview with something like the following:

echo $VAR | base64 -D > /tmp/file