Skip to content

Commit

Permalink
feat(container): add env field to task spec
Browse files Browse the repository at this point in the history
Closes #612
  • Loading branch information
edvald committed Mar 12, 2019
1 parent 5793f0a commit 950536f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
9 changes: 9 additions & 0 deletions docs/reference/module-types/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -614,4 +622,5 @@ module:
dependencies: []
timeout: null
args:
env: {}
```
9 changes: 9 additions & 0 deletions docs/reference/module-types/maven-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -637,6 +645,7 @@ module:
dependencies: []
timeout: null
args:
env: {}
jarPath:
jdkVersion: 8
```
9 changes: 6 additions & 3 deletions garden-service/src/plugins/container/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,16 @@ export const containerTestSchema = baseTestSpecSchema
})

export interface ContainerTaskSpec extends BaseTaskSpec {
args: string[],
args: string[]
env: PrimitiveMap
}

export const containerTaskSchema = baseTaskSpecSchema
.keys({
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.")

Expand Down Expand Up @@ -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<M, S, T> { }
T extends ContainerTestSpec = ContainerTestSpec,
W extends ContainerTaskSpec = ContainerTaskSpec
> extends Module<M, S, T, W> { }
4 changes: 3 additions & 1 deletion garden-service/src/plugins/kubernetes/container/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -112,6 +112,8 @@ export async function runContainerService(
export async function runContainerTask(
{ ctx, task, interactive, runtimeContext, log }: RunTaskParams<ContainerModule>,
) {
extend(runtimeContext.envVars, task.spec.env || {})

const result = await runContainerModule({
ctx,
interactive,
Expand Down
24 changes: 21 additions & 3 deletions garden-service/test/src/plugins/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}],
},
Expand Down Expand Up @@ -404,14 +409,19 @@ 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,
}],
},
Expand Down Expand Up @@ -452,6 +462,9 @@ describe("plugins.container", () => {
"OK",
],
dependencies: [],
env: {
TASK_ENV_VAR: "value",
},
name: "task-a",
timeout: null,
},
Expand All @@ -466,7 +479,9 @@ describe("plugins.container", () => {
name: "unit",
args: ["echo", "OK"],
dependencies: [],
env: {},
env: {
TEST_ENV_VAR: "value",
},
timeout: null,
},
timeout: null,
Expand Down Expand Up @@ -521,6 +536,7 @@ describe("plugins.container", () => {
name: "task-a",
args: ["echo"],
dependencies: [],
env: {},
timeout: null,
}],
tests: [{
Expand Down Expand Up @@ -580,6 +596,7 @@ describe("plugins.container", () => {
name: "task-a",
args: ["echo"],
dependencies: [],
env: {},
timeout: null,
}],
tests: [],
Expand Down Expand Up @@ -630,6 +647,7 @@ describe("plugins.container", () => {
name: "task-a",
args: ["echo"],
dependencies: [],
env: {},
timeout: null,
}],
tests: [],
Expand Down

0 comments on commit 950536f

Please sign in to comment.