Skip to main content

Environment Variables

Catch offers a way to manage environment variables for our services. There are two methods to set environment variables:

  1. Using scp: Upload a file containing environment variables.
  2. Using yeet edit: Set them interactively via the CLI.

Using scp

We can use scp to upload a file containing environment variables. The file should be in the format of "KEY=VALUE" with one pair per line.

Take for example the following file, env.txt:

FOO=bar
BAZ=qux

We can upload this file to our service using scp. We will assume the service is named my-service.

scp env.txt my-service@catch:env

When we upload an env file, Catch will automatically restart our service with the new environment variables.

Using with Docker

When using Docker or Docker Compose, Catch will still automatically manage environment variables, however we will need to add the env_file directive to our docker-compose.yml file.

Catch creates a .env file in our service's data directory. This file is automatically managed by Catch and will properly be rolled back if the service is rolled back.

To specify the environment variables file for our service, add the following to our docker-compose.yml file:

services:
my-service:
env_file: # Add these lines
- .env

Staging environment variables

Sometimes we may want to set environment variables but not immediately apply them to our service. This is useful if we plan to make make additional changes, like running a new binary or pushing a new Docker image.

To stage environment variables, we'll use scp to upload our environment variables file to a special stage/env destination.

scp env.txt my-service@catch:stage/env

Our changes will automatically be applied the next time we deploy our service via yeet run. If we want to apply our staged changes explicitly, we can use yeet stage my-service commit.

Rolling back environment variables

Using Catch to manage our environment variables allows us to roll back to a previous state if needed. This is particularly useful if a new version of our service is not functioning as expected. The rollback process will restore both the service and the environment variables to their previous configurations.

To roll back to a previous environment variable configuration, we can use the yeet rollback command. This will restore the environment variables to their previous configuration.

yeet rollback my-service

For more information on rolling back services, see our staging and rolling back guide.