Environment Variables
  • 28 Feb 2024
  • 2 Minutes to read
  • Contributors
  • Dark
    Light

Environment Variables

  • Dark
    Light

Article summary

Kapeta exposes a number of environment variables to your applications which contains
everything from your block configuration to connection details for databases etc.

Note that most of these are already handled in the Kapeta SDK so if you're using that you wont need to worry too much about the details of these.
map them to the kapeta-specific ones.

The available kapeta-specific environment variables are:

NameDescriptionExample value
KAPETA_SYSTEM_IDThe plan referencekapeta://my-org/my-plan:1.2.3
KAPETA_BLOCK_REFThe block referencekapeta://my-org/my-block:1.2.3
KAPETA_INSTANCE_IDThe instance id (UUID) of the block in the plan17c24593-d23e-4a0c-ae3f-88d918ebf3d1
KAPETA_CONSUMER_RESOURCE_<resource-name>_<port-type>Resource information for the operator resource <resource-name> for <port-type>. Will contain credentials and connection details for resourceResourceInfo (See below)
KAPETA_CONSUMER_SERVICE_<resource-name>_<port-type>Base URL for the service resource <resource-name> for <port-type>. Only meaningful for HTTP API resourceshttps://some-domain/api/
KAPETA_INSTANCE_OPERATOR_<instance-id>Instance information for the operator instance with id <instance-id>InstanceOperator (See below)
KAPETA_INSTANCE_FOR_CONSUMER_<resource-name>Block details for the block that provides the resource <resource-name>BlockInstanceDetails[] (See below)
KAPETA_INSTANCES_FOR_PROVIDER_<resource-name>Block details for the blocks that consume the resource <resource-name>BlockInstanceDetails (See below)
KAPETA_INSTANCE_CONFIGConfiguration defined for your block{"MyConfig":{"someKey":"someValue", ... }}
KAPETA_BLOCK_HOSTSHosts for all the blocks in the current plan{"some-instance-id":"localhost:40212", ... }
KAPETA_PROVIDER_HOSTHost for the this block to bind to127.0.0.1
KAPETA_PROVIDER_PORT_<port-type>Port for this block to bind to for <port-type>80
KAPETA_SYSTEM_TYPE*The environment in which the block is startedkubernetes or local
KAPETA_LOCAL_SERVER*Sets the host to bind to. Is only used locally.127.0.0.1
KAPETA_LOCAL_SERVER_PORT_<port-type>*Sets the port to bind to for <port-type>. Is only used locally.127.0.0.1
KAPETA_ENVIRONMENT_TYPE*Added as HTTP Header X-Kapeta-Environment to all requests to the local cluster. Only used locally.docker
KAPETA_ENVIRONMENT_PLATFORM*The platform that Kapeta is running on. Is only used locally.win32, darwin, linux

Note: Variables marked with "*" is intended for internal use within Kapeta only.

ResourceInfo:

interface ResourceInfo {
    host: string;
    port: string | number;
    type: string;
    protocol: string;
    options?: { [key:string]:any };
    credentials?: { [key:string]:any };
}

InstanceOperator:

interface InstanceOperator {
    hostname: string;
    ports: { 
        [portType:string]: {
            protocol: 'tcp'|'udp';
            port: number;
        } 
    };
    path?: string;
    query?: string;
    hash?: string;
    options?: { [key:string]:any };
    credentials?: { [key:string]:any };
}

BlockInstanceDetails:

interface BlockInstanceDetails {
    instanceId: string;
    block: {
        kind: string;
        metadata: {
            name:         string;
            description?: string;
            title?:       string;
            visibility?:  string;
        };
        spec: { [key:string]:any };
    };
    connections: {
        consumer: {
            blockId: string;
            resourceName: string;    
        };
        provider: {
            blockId: string;
            resourceName: string;    
        };
        port?:    {
            type: string
        };
        mapping?: { [key: string]: any };
    }[]
}

Was this article helpful?