Environment variables in score-humanitec

This section describes how to define environment variables for score-humanitec.

Humanitec provides a dynamic application configuration mechanism through the Shared Application Values.

Overview

The Score Specification uses a special environment property type that is specified in the resources section.

apiVersion: score.sh/v1b1

metadata:
  name: hello-world

containers:
  hello:
    image: busybox
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo Hello $${FRIEND}!; sleep 5; done"]
    variables:
      FRIEND: ${resources.env.NAME}

resources:
  env:
    type: environment

Use the run command to generate a Humanitec deployment delta file from Score.

score-humanitec run -f ./score.yaml \
  --env test-env

The following is the output of the previous command.

{
  "metadata": {
    "env_id": "test-env",
    "name": "Auto-generated (SCORE)"
  },
  "modules": {
    "add": {
      "hello-world": {
        "profile": "humanitec/default-module",
        "spec": {
          "containers": {
            "hello": {
              "args": [
                "-c",
                "while true; do echo Hello $${FRIEND}!; sleep 5; done"
              ],
              "command": [
                "/bin/sh"
              ],
              "id": "hello",
              "image": "busybox",
              "variables": {
                "FRIEND": "${values.NAME}"
              }
            }
          }
        }
      }
    }
  }
}

The output JSON can be used as a payload to Create a new Delta with a Humanitec API call.

When deploying this service with Humanitec, make sure the shared application value called NAME is created and set for the target environment.