Skip to main content

Environments

Examples

Create Environments#

You can create a new component by using @kosko/template-environment template.

npx @kosko/template-environment --name dev

Define Environments#

The following is the folder structure of environments folder.

environmentsโ”œโ”€โ”€ devโ”‚   โ”œโ”€โ”€ index.jsโ”‚   โ””โ”€โ”€ nginx.jsโ””โ”€โ”€ prod    โ”œโ”€โ”€ index.js    โ””โ”€โ”€ nginx.js

Global Variables#

Global variables are defined in environments/<env>/index.js.

module.exports = {  imageRegistry: "gcr.io/image-dev"};

Component Variables#

Component variables are defined in environments/<env>/<component>.js.

module.exports = {  replicas: 3,  port: 8080};

Retrieve Variables#

Get Current Environment#

The env value can be a string, an array of strings or undefined.

require("@kosko/env").env === "dev";

Global Variables#

Retrieve global variables with global() function.

require("@kosko/env").global() === require("./environments/dev");

Component Variables#

Retrieve component variables with component() function. It returns a merge of global variables and variables of the specified component.

require("@kosko/env").component("nginx") ===  {    ...require("@kosko/env").global(),    ...require("./environments/dev/nginx")  };

Specify Environments#

When running kosko generate or kosko validate, use -e,--env to specify environments.

npx kosko generate -e dev

You can also set baseEnvironment as the default environment.

kosko.toml
baseEnvironment = "dev"