Environment Variables

Environment variables are a powerful way to manage application runtime configurations. Containers running on Cycle can have runtime environment variables injected from a variety of sources. The platform also injects many variables about the container and the context it is running in on Cycle. Environment variables are shared amongst all instances of the container.

Restart Required

Any change to environment variables will require the container to be restarted before they become available within the container process.

User-Defined Environment Variables

Custom user-defined environment variables can be specified several different ways

Image Variables

A container image can define environment variables and their values. Image variables will ALWAYS be injected into the container. They can be overridden on the container runtime configuration, but cannot be removed.

Defining environment variables on an image looks like this:

ENV MY_NAME="John Doe"
ENV MY_DOG=Rex\ The\ Dog
ENV MY_CAT=fluffy

Environment variables can also be set in a Dockerfile without a value, to use as a placeholder when deploying on Cycle.

ENV MY_VARIABLE=

The MY_VARIABLE variable will be set on the container in Cycle as an empty string, but will be visible in interfaces such as the portal environment variable form as a reminder that the variable needs set.

Runtime Configuration Variables

Environment variables can be added to the container manually via the container runtime configuration. The variables do not have to exist on the image to be added this way.

Add runtime configuration variables

Scoped Variables

Scoped variables can be used when sharing variables between multiple different containers within an environment. Scoped variables can be injected into the container several different ways, one of which is as an environment variable.

Function Runtime Variables

Function containers can have environment variables injected dynamically on every start, so that each unique run of a function encapsulates its own environment.

Set Runtime Variables On Function Run

Platform Environment Variables

The platform injects special "Cycle specific" environment variables into every container instance. This is to provide it with information about, for example, the environment its running in, the infrastructure provider, available resources, etc.

NAMEDESCRIPTION
CYCLE_HUB_IDThe ID of the hub this container is deployed into.
CYCLE_API_TOKENA token that is used by instances to authenticate against the Internal API .
CYCLE_AUTO_STARTWill be set to yes if the platform has caused this container to restart, otherwise no.
CYCLE_FIRST_STARTWill be set to yes if this is the first time this container has been started, otherwise no.
CYCLE_CONTAINER_IDENTIFIERThe identifier used for this container.
CYCLE_CONTAINER_IDThe ID of the container.
CYCLE_COMPUTE_PROXYThe URL of the Cycle compute proxy.
CYCLE_ENVIRONMENT_IDThe ID of the environment this container is deployed in.
CYCLE_INSTANCE_IDThe ID of this instance.
CYCLE_INSTANCE_IPV6_IPThe IPv6 address of this specific instance.
CYCLE_INSTANCE_IPV6_SUBNETThe subnet of the instance itself. If there are 5 instances this will be 1-5 depending on the instance.
CYCLE_INSTANCE_IPV6_CIDRThe IPv6 address range this instance is assigned.
CYCLE_LOCATION_IDThe ID of the location of the server that this container is deployed to.
CYCLE_PROVIDER_IDENTIFIERThe identifier of the provider of the server.
CYCLE_PROVIDER_LOCATIONThe physical location of the server.
CYCLE_SERVER_IDThe ID of the server this container is deployed to.
CYCLE_DEPLOYMENT_VERSIONIf the container instance is part of a deployment, this is the version of that deployment.
CYCLE_PROVIDER_VENDORThe provider that the container instance is currently running on.
CYCLE_CPU_PERIODA value in microseconds. 100,000 is equal to 100 milliseconds or 100% of a period.
CYCLE_CPU_QUOTAA value in microseconds. 100,000 is equal to 100 milliseconds or 100% of one core.
CYCLE_CPU_LIMITEDA value that reads yes if the container instance has limits on how much of the underlying CPU it can use or no if it is unlimited.
CYCLE_CLUSTERThe cluster this instance is deployed into.
CYCLE_ENVIRONMENT_LEGACYWill be yes if the instance is running in an environment with legacy mode enabled, otherwise no.

Order of Evaluation

When multiple environment variables of the same name are present from different sources, they're evaluated in the following order, where the last source wins.

  1. Image Variables
  2. Scoped Variables*
  3. Runtime Configuration Variables
  4. Function Runtime Variables
  5. Cycle Platform Environment Variables

Runtime vs Scoped Variables

*If a runtime configuration variable is set, but left blank, and a scoped variable of the same name is set, the scoped variable's value will be applied.

Environment Metadata File

In addition to the environment variables provided by the platform, Cycle also injects a JSON file into the container that contains information about the environment the container instance is running in. The file is mounted at:

/var/run/cycle/metadata/environment.json

This file is available at runtime, and may be useful for writing specialized scripts executed as an ENTRYPOINT into the container.

Example

{
	"id": "65b93b8dee5a5e8d87b2bd13",
	"deployments": {
		"tags": {
			"current": "v2.0.2",
			"demo": "v2.0.0",
			"live": "v8.9.10",
			"test": "v8.9.10"
		}
	},
	"private_network": {
		"vxlan_tag": 361,
		"subnet": "d600",
		"ipv6": {
			"ip": "fd00::d600:0:0:0",
			"cidr": "fd00::d600:0:0:0/80"
		},
		"legacy": null
	},
	"services": {
		"discovery": {
			"enable": true,
			"container_id": "65b93b8df9aadae178915a2e",
			"high_availability": false,
			"auto_update": false,
			"config": null
		},
		"vpn": {
			"enable": true,
			"container_id": "65b93b8df9aadae178915a32",
			"high_availability": false,
			"auto_update": false,
			"config": null
		},
		"loadbalancer": {
			"enable": true,
			"container_id": "65b93b8df9aadae178915a37",
			"high_availability": false,
			"auto_update": true,
			"config": null
		},
		"scheduler": {
			"enable": true,
			"container_id": "65b93b8df9aadae178915a39",
			"high_availability": false,
			"auto_update": false,
			"config": null
		}
	}
}