Pass environment-specific configuration in score-humanitec
2 minute read
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
properties:
NAME:
type: string
default: World
Resources need to map to the resource structure. To declare environment variables in a Score file, the variable name,
resources.env.NAME
must map to the structure inresource
section.
For more information, see the Resource section in the Score Specification reference.
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.