Skip to content

Commit

Permalink
Merge branch 'master' into truncated-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored Nov 29, 2019
2 parents d31aa8e + 8d66f8a commit c625a9f
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 26 deletions.
1 change: 1 addition & 0 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ export class ActionRouter implements TypeGuard {
const handlerParams = {
...(await this.commonParams(handler, log)),
...params,
service,
module,
runtimeContext,
}
Expand Down
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 @@ -36,7 +36,9 @@ export async function runContainerService({
timeout,
log,
}: RunServiceParams<ContainerModule>): Promise<RunResult> {
const { command, args } = service.spec
const { command, args, env } = service.spec

runtimeContext.envVars = { ...runtimeContext.envVars, ...env }

return runContainerModule({
ctx,
Expand Down
11 changes: 6 additions & 5 deletions garden-service/src/tasks/get-service-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { Garden } from "../garden"
import { ConfigGraph } from "../config-graph"
import { TaskResults } from "../task-graph"
import { prepareRuntimeContext } from "../runtime-context"
import { GetTaskResultTask } from "./get-task-result"
import { getTaskVersion } from "./task"
import { getTaskVersion, TaskTask } from "./task"
import Bluebird from "bluebird"

export interface GetServiceStatusTaskParams {
Expand Down Expand Up @@ -55,17 +54,19 @@ export class GetServiceStatusTask extends BaseTask {
})
})

const taskResultTasks = await Bluebird.map(deps.task, async (task) => {
return new GetTaskResultTask({
const taskTasks = await Bluebird.map(deps.task, async (task) => {
return new TaskTask({
garden: this.garden,
graph: this.graph,
log: this.log,
task,
force: false,
forceBuild: false,
version: await getTaskVersion(this.garden, this.graph, task),
})
})

return [...statusTasks, ...taskResultTasks]
return [...statusTasks, ...taskTasks]
}

getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ kind: Module
name: simple
type: container
image: busybox
services:
- name: echo-service
command: [sh, -c, "echo ok"]
- name: env-service
command: [sh, -c, "echo $ENV_VAR"]
env:
ENV_VAR: foo
tasks:
- name: echo-task
command: [sh, -c, "echo ok"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { TaskTask } from "../../../../../../src/tasks/task"
import { runAndCopy } from "../../../../../../src/plugins/kubernetes/run"
import { Provider } from "../../../../../../src/config/provider"
import { containerHelpers } from "../../../../../../src/plugins/container/helpers"
import { runContainerService } from "../../../../../../src/plugins/kubernetes/container/run"
import { prepareRuntimeContext } from "../../../../../../src/runtime-context"

describe("kubernetes container module handlers", () => {
let garden: Garden
Expand Down Expand Up @@ -234,6 +236,66 @@ describe("kubernetes container module handlers", () => {
})
})

describe("runContainerService", () => {
it("should run a service", async () => {
const service = await graph.getService("echo-service")

const runtimeContext = await prepareRuntimeContext({
garden,
graph,
dependencies: {
build: [],
service: [],
task: [],
test: [],
},
module: service.module,
serviceStatuses: {},
taskResults: {},
})

const result = await runContainerService({
ctx: garden.getPluginContext(provider),
log: garden.log,
service,
module: service.module,
interactive: false,
runtimeContext,
})

expect(result.log.trim()).to.eql("ok")
})

it("should add configured env vars to the runtime context", async () => {
const service = await graph.getService("env-service")

const runtimeContext = await prepareRuntimeContext({
garden,
graph,
dependencies: {
build: [],
service: [],
task: [],
test: [],
},
module: service.module,
serviceStatuses: {},
taskResults: {},
})

const result = await runContainerService({
ctx: garden.getPluginContext(provider),
log: garden.log,
service,
module: service.module,
interactive: false,
runtimeContext,
})

expect(result.log.trim()).to.eql("foo")
})
})

describe("runContainerTask", () => {
it("should run a basic task", async () => {
const task = await graph.getTask("echo-task")
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

139 changes: 139 additions & 0 deletions garden-service/test/unit/src/tasks/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import tmp from "tmp-promise"
import execa from "execa"

import { ProjectConfig } from "../../../../src/config/project"
import { DEFAULT_API_VERSION } from "../../../../src/constants"
import { Garden } from "../../../../src/garden"
import { GardenPlugin } from "../../../../src/types/plugin/plugin"
import { joi } from "../../../../src/config/common"
import { ServiceState } from "../../../../src/types/service"
import { DeployTask } from "../../../../src/tasks/deploy"
import { DeployServiceParams } from "../../../../src/types/plugin/service/deployService"
import { RunTaskParams } from "../../../../src/types/plugin/task/runTask"
import { expect } from "chai"

describe("DeployTask", () => {
let tmpDir: tmp.DirectoryResult
let config: ProjectConfig

before(async () => {
tmpDir = await tmp.dir({ unsafeCleanup: true })

await execa("git", ["init"], { cwd: tmpDir.path })

config = {
apiVersion: DEFAULT_API_VERSION,
kind: "Project",
name: "test",
path: tmpDir.path,
defaultEnvironment: "default",
dotIgnoreFiles: [],
environments: [{ name: "default", variables: {} }],
providers: [{ name: "test" }],
variables: {},
}
})

after(async () => {
await tmpDir.cleanup()
})

describe("process", () => {
it("should correctly resolve runtime outputs from tasks", async () => {
const testPlugin: GardenPlugin = {
name: "test",
createModuleTypes: [
{
name: "test",
docs: "test",
serviceOutputsSchema: joi.object().keys({ log: joi.string() }),
handlers: {
build: async () => ({}),
getServiceStatus: async () => {
return {
state: <ServiceState>"missing",
detail: {},
outputs: {},
}
},
deployService: async ({ service }: DeployServiceParams) => {
return {
state: <ServiceState>"ready",
detail: {},
outputs: { log: service.spec.log },
}
},
runTask: async ({ task }: RunTaskParams) => {
const log = task.spec.log

return {
taskName: task.name,
moduleName: task.module.name,
success: true,
outputs: { log },
command: [],
log,
startedAt: new Date(),
completedAt: new Date(),
version: task.module.version.versionString,
}
},
},
},
],
}

const garden = await Garden.factory(tmpDir.path, { config, plugins: [testPlugin] })

garden["moduleConfigs"] = {
test: {
apiVersion: DEFAULT_API_VERSION,
name: "test",
type: "test",
allowPublish: false,
build: { dependencies: [] },
outputs: {},
path: tmpDir.path,
serviceConfigs: [
{
name: "test-service",
dependencies: ["test-task"],
hotReloadable: false,
spec: {
log: "${runtime.tasks.test-task.outputs.log}",
},
},
],
taskConfigs: [
{
name: "test-task",
dependencies: [],
spec: {
log: "test output",
},
timeout: 10,
},
],
testConfigs: [],
spec: { bla: "fla" },
},
}

const graph = await garden.getConfigGraph()
const testService = await graph.getService("test-service")

const deployTask = new DeployTask({
garden,
graph,
service: testService,
force: true,
forceBuild: false,
log: garden.log,
})

const result = await garden.processTasks([deployTask])

expect(result[deployTask.getKey()]!.output.outputs).to.eql({ log: "test output" })
})
})
})
Loading

0 comments on commit c625a9f

Please sign in to comment.