diff --git a/docs/reference/module-types/container.md b/docs/reference/module-types/container.md index fb14c78a7a..cfa7065088 100644 --- a/docs/reference/module-types/container.md +++ b/docs/reference/module-types/container.md @@ -552,6 +552,14 @@ module: - rake - 'db:migrate' ``` +### `module.tasks[].env` +[module](#module) > [tasks](#module.tasks[]) > env + +Key/value map of environment variables. Keys must be valid POSIX environment variable names (must not start with `GARDEN`) and values must be primitives. + +| Type | Required | +| ---- | -------- | +| `object` | No ## Complete YAML schema @@ -614,4 +622,5 @@ module: dependencies: [] timeout: null args: + env: {} ``` diff --git a/docs/reference/module-types/maven-container.md b/docs/reference/module-types/maven-container.md index c0ac2a345d..0a310f8e58 100644 --- a/docs/reference/module-types/maven-container.md +++ b/docs/reference/module-types/maven-container.md @@ -552,6 +552,14 @@ module: - rake - 'db:migrate' ``` +### `module.tasks[].env` +[module](#module) > [tasks](#module.tasks[]) > env + +Key/value map of environment variables. Keys must be valid POSIX environment variable names (must not start with `GARDEN`) and values must be primitives. + +| Type | Required | +| ---- | -------- | +| `object` | No ### `module.jarPath` [module](#module) > jarPath @@ -637,6 +645,7 @@ module: dependencies: [] timeout: null args: + env: {} jarPath: jdkVersion: 8 ``` diff --git a/garden-service/src/plugins/container/config.ts b/garden-service/src/plugins/container/config.ts index 2b2fc5dacb..3c5f87ed7d 100644 --- a/garden-service/src/plugins/container/config.ts +++ b/garden-service/src/plugins/container/config.ts @@ -269,7 +269,8 @@ export const containerTestSchema = baseTestSpecSchema }) export interface ContainerTaskSpec extends BaseTaskSpec { - args: string[], + args: string[] + env: PrimitiveMap } export const containerTaskSchema = baseTaskSpecSchema @@ -277,6 +278,7 @@ export const containerTaskSchema = baseTaskSpecSchema args: Joi.array().items(Joi.string()) .description("The arguments used to run the task inside the container.") .example([["rake", "db:migrate"], {}]), + env: joiEnvVars(), }) .description("A task that can be run in the container.") @@ -341,5 +343,6 @@ export const containerModuleSpecSchema = Joi.object() export interface ContainerModule< M extends ContainerModuleSpec = ContainerModuleSpec, S extends ContainerServiceSpec = ContainerServiceSpec, - T extends ContainerTestSpec = ContainerTestSpec - > extends Module { } + T extends ContainerTestSpec = ContainerTestSpec, + W extends ContainerTaskSpec = ContainerTaskSpec + > extends Module { } diff --git a/garden-service/src/plugins/kubernetes/container/run.ts b/garden-service/src/plugins/kubernetes/container/run.ts index f2966c2dc2..fa6f3c8ddb 100644 --- a/garden-service/src/plugins/kubernetes/container/run.ts +++ b/garden-service/src/plugins/kubernetes/container/run.ts @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { includes } from "lodash" +import { includes, extend } from "lodash" import { DeploymentError } from "../../../exceptions" import { RunResult } from "../../../types/plugin/outputs" import { @@ -112,6 +112,8 @@ export async function runContainerService( export async function runContainerTask( { ctx, task, interactive, runtimeContext, log }: RunTaskParams, ) { + extend(runtimeContext.envVars, task.spec.env || {}) + const result = await runContainerModule({ ctx, interactive, diff --git a/garden-service/test/src/plugins/container.ts b/garden-service/test/src/plugins/container.ts index 6bed534d1b..14fed50b3e 100644 --- a/garden-service/test/src/plugins/container.ts +++ b/garden-service/test/src/plugins/container.ts @@ -348,13 +348,18 @@ describe("plugins.container", () => { name: "task-a", args: ["echo", "OK"], dependencies: [], + env: { + TASK_ENV_VAR: "value", + }, timeout: null, }], tests: [{ name: "unit", args: ["echo", "OK"], dependencies: [], - env: {}, + env: { + TEST_ENV_VAR: "value", + }, timeout: null, }], }, @@ -404,6 +409,9 @@ describe("plugins.container", () => { name: "task-a", args: ["echo", "OK"], dependencies: [], + env: { + TASK_ENV_VAR: "value", + }, timeout: null, }], tests: @@ -411,7 +419,9 @@ describe("plugins.container", () => { name: "unit", args: ["echo", "OK"], dependencies: [], - env: {}, + env: { + TEST_ENV_VAR: "value", + }, timeout: null, }], }, @@ -452,6 +462,9 @@ describe("plugins.container", () => { "OK", ], dependencies: [], + env: { + TASK_ENV_VAR: "value", + }, name: "task-a", timeout: null, }, @@ -466,7 +479,9 @@ describe("plugins.container", () => { name: "unit", args: ["echo", "OK"], dependencies: [], - env: {}, + env: { + TEST_ENV_VAR: "value", + }, timeout: null, }, timeout: null, @@ -521,6 +536,7 @@ describe("plugins.container", () => { name: "task-a", args: ["echo"], dependencies: [], + env: {}, timeout: null, }], tests: [{ @@ -580,6 +596,7 @@ describe("plugins.container", () => { name: "task-a", args: ["echo"], dependencies: [], + env: {}, timeout: null, }], tests: [], @@ -630,6 +647,7 @@ describe("plugins.container", () => { name: "task-a", args: ["echo"], dependencies: [], + env: {}, timeout: null, }], tests: [],