Skip to content

Commit

Permalink
fix(core): error when services had runtime dependencies on task outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and 10ko committed Nov 29, 2019
1 parent 7f74a46 commit d26595f
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 25 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
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

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" })
})
})
})
132 changes: 132 additions & 0 deletions garden-service/test/unit/src/tasks/get-service-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
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 { DeployServiceParams } from "../../../../src/types/plugin/service/deployService"
import { RunTaskParams } from "../../../../src/types/plugin/task/runTask"
import { expect } from "chai"
import { GetServiceStatusTask } from "../../../../src/tasks/get-service-status"
import { GetServiceStatusParams } from "../../../../src/types/plugin/service/getServiceStatus"

describe("GetServiceStatusTask", () => {
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 ({ service }: GetServiceStatusParams) => {
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 statusTask = new GetServiceStatusTask({
garden,
graph,
service: testService,
force: true,
log: garden.log,
})

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

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

0 comments on commit d26595f

Please sign in to comment.