Using Environment Variables

Using Environment Variables #

New in quantum-cli 2.3.0

Following the 12 factor principals, customers had the choice to preprocess their stack files before a deployment with custom tooling or of course to commit certain settings to the repository. The new and improved handling of environment variables in quantum-cli streamlines this process and makes deployments even easier on our platform.

Example deployment #

The following stack makes use of environment variables which quantum-cli will add to the deployment when it happens. The advantage of this method is that neither RELEASE_VERSION nor the MYSQL_PASSWORD

version: '3.7'
services:
  project:
    image: "registry.example.org/name/project:${RELEASE_VERSION}"
    environment:
      - MYSQL_PASSWORD=$MYSQL_PASSWORD
    labels:
      traefik.enable: "true"
      traefik.docker.network: "public"
      traefik.frontend.rule: "Host:app.exaple.org"
      traefik.port: "80"
    networks:
      - public

  public:
    external: true

The stack file assumes that you have build an image of your project like so:

$ docker build -t registry.example.org/name/project:1.2.3

Then to deploy/update from your own manchine:

$ export RELEASE_VERSION=1.2.3
$ export MYSQL_PASSWORD=super-secure
$ quantum-cli stacks update --create --wait --stack my-app
...

The enviroment variables will be available for review on our console when you browse your stacks and go to Editor tab. We do not alter your stack file during the deployment process.

Take it further #

The above provides a minimal example of how you can run a deployment from your own laptop with virtually no changes required to the stack’s definition. If you wanted to take this one step further, you can do the following:

  • in your CI/CD pipeline, docker build a release image based on a git ref
  • populate the MYSQL_PASSWORD from your CI/CD’s secrets store
  • use direnv to (document and) manage environment variables