From 733e2dbc6ff888594d40ad9abc935595be270dc6 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Sat, 4 May 2019 16:08:28 -0700 Subject: [PATCH] refactor(core): fold push task into build task The push workflow doesn't really need to be separate from builds in the stack graph, since there is generally a 1:1 dependency relationship between the two, and pushing to clusters isn't needed as a discrete step. --- garden-service/src/actions.ts | 10 -- garden-service/src/commands/run/module.ts | 6 +- garden-service/src/commands/run/service.ts | 6 +- garden-service/src/commands/run/test.ts | 6 +- garden-service/src/config-graph.ts | 7 +- .../src/plugins/kubernetes/container/build.ts | 48 ++++++ .../kubernetes/container/deployment.ts | 22 +-- .../plugins/kubernetes/container/handlers.ts | 3 +- garden-service/src/tasks/base.ts | 2 +- garden-service/src/tasks/build.ts | 3 +- garden-service/src/tasks/deploy.ts | 6 +- garden-service/src/tasks/helpers.ts | 14 +- garden-service/src/tasks/push.ts | 118 ------------- garden-service/src/tasks/task.ts | 7 +- garden-service/src/tasks/test.ts | 4 +- garden-service/src/types/plugin/outputs.ts | 14 -- garden-service/src/types/plugin/params.ts | 4 - garden-service/src/types/plugin/plugin.ts | 24 +-- garden-service/test/unit/src/actions.ts | 15 -- .../test/unit/src/commands/build.ts | 3 - .../test/unit/src/commands/deploy.ts | 6 - .../test/unit/src/commands/publish.ts | 2 - garden-service/test/unit/src/config-graph.ts | 14 +- garden-service/test/unit/src/tasks/helpers.ts | 155 +++++++++--------- 24 files changed, 160 insertions(+), 339 deletions(-) create mode 100644 garden-service/src/plugins/kubernetes/container/build.ts delete mode 100644 garden-service/src/tasks/push.ts diff --git a/garden-service/src/actions.ts b/garden-service/src/actions.ts index 2dabb35096..fa68303afc 100644 --- a/garden-service/src/actions.ts +++ b/garden-service/src/actions.ts @@ -30,7 +30,6 @@ import { GetSecretResult, GetServiceLogsResult, ModuleActionOutputs, - PushResult, RunResult, ServiceActionOutputs, SetSecretResult, @@ -57,7 +56,6 @@ import { PluginActionParams, PluginActionParamsBase, PluginServiceActionParamsBase, - PushModuleParams, HotReloadServiceParams, RunModuleParams, RunServiceParams, @@ -275,10 +273,6 @@ export class ActionHelper implements TypeGuard { return this.callModuleHandler({ params, actionType: "build" }) } - async pushModule(params: ModuleActionHelperParams>): Promise { - return this.callModuleHandler({ params, actionType: "pushModule", defaultHandler: dummyPushHandler }) - } - async publishModule( params: ModuleActionHelperParams>, ): Promise { @@ -687,10 +681,6 @@ const dummyLogStreamer = async ({ service, log }: GetServiceLogsParams) => { return {} } -const dummyPushHandler = async () => { - return { pushed: false } -} - const dummyPublishHandler = async ({ module }) => { return { message: chalk.yellow(`No publish handler available for module type ${module.type}`), diff --git a/garden-service/src/commands/run/module.ts b/garden-service/src/commands/run/module.ts index 96a1c8a3db..b1b55f2b6d 100644 --- a/garden-service/src/commands/run/module.ts +++ b/garden-service/src/commands/run/module.ts @@ -19,7 +19,7 @@ import { import { printRuntimeContext, runtimeContextForServiceDeps } from "./run" import dedent = require("dedent") import { logHeader } from "../../logger/util" -import { PushTask } from "../../tasks/push" +import { BuildTask } from "../../tasks/build" const runArgs = { module: new StringParameter({ @@ -85,8 +85,8 @@ export class RunModuleCommand extends Command { await garden.actions.prepareEnvironment({ log }) - const pushTask = new PushTask({ garden, log, module, force: opts["force-build"] }) - await garden.processTasks([pushTask]) + const buildTask = new BuildTask({ garden, log, module, force: opts["force-build"] }) + await garden.processTasks([buildTask]) const command = args.command || [] diff --git a/garden-service/src/commands/run/service.ts b/garden-service/src/commands/run/service.ts index 1c44d4102f..4e7a35c58b 100644 --- a/garden-service/src/commands/run/service.ts +++ b/garden-service/src/commands/run/service.ts @@ -18,7 +18,7 @@ import { import { printRuntimeContext, runtimeContextForServiceDeps } from "./run" import dedent = require("dedent") import { logHeader } from "../../logger/util" -import { PushTask } from "../../tasks/push" +import { BuildTask } from "../../tasks/build" const runArgs = { service: new StringParameter({ @@ -66,8 +66,8 @@ export class RunServiceCommand extends Command { await garden.actions.prepareEnvironment({ log }) - const pushTask = new PushTask({ garden, log, module, force: opts["force-build"] }) - await garden.processTasks([pushTask]) + const buildTask = new BuildTask({ garden, log, module, force: opts["force-build"] }) + await garden.processTasks([buildTask]) const runtimeContext = await runtimeContextForServiceDeps(garden, graph, module) printRuntimeContext(log, runtimeContext) diff --git a/garden-service/src/commands/run/test.ts b/garden-service/src/commands/run/test.ts index 227971b561..2c9e087422 100644 --- a/garden-service/src/commands/run/test.ts +++ b/garden-service/src/commands/run/test.ts @@ -24,7 +24,7 @@ import { printRuntimeContext } from "./run" import dedent = require("dedent") import { prepareRuntimeContext } from "../../types/service" import { logHeader } from "../../logger/util" -import { PushTask } from "../../tasks/push" +import { BuildTask } from "../../tasks/build" import { getTestVersion } from "../../tasks/test" const runArgs = { @@ -92,8 +92,8 @@ export class RunTestCommand extends Command { await garden.actions.prepareEnvironment({ log }) - const pushTask = new PushTask({ garden, log, module, force: opts["force-build"] }) - await garden.processTasks([pushTask]) + const buildTask = new BuildTask({ garden, log, module, force: opts["force-build"] }) + await garden.processTasks([buildTask]) const interactive = opts.interactive const deps = await graph.getDependencies("test", testConfig.name, false) diff --git a/garden-service/src/config-graph.ts b/garden-service/src/config-graph.ts index a302878aaf..ea63c92df6 100644 --- a/garden-service/src/config-graph.ts +++ b/garden-service/src/config-graph.ts @@ -25,8 +25,7 @@ import { makeTestTaskName } from "./tasks/helpers" import { TaskType, makeBaseKey } from "./tasks/base" // Each of these types corresponds to a Task class (e.g. BuildTask, DeployTask, ...). -export type DependencyGraphNodeType = "build" | "service" | "task" | "test" - | "push" | "publish" // these two types are currently not represented in the graph +export type DependencyGraphNodeType = "build" | "service" | "task" | "test" | "publish" // The primary output type (for dependencies and dependants). export type DependencyRelations = { @@ -48,7 +47,7 @@ export type DependencyRelationFilterFn = (DependencyGraphNode) => boolean // Output types for rendering/logging export type RenderedGraph = { nodes: RenderedNode[], relationships: RenderedEdge[] } export type RenderedEdge = { dependant: RenderedNode, dependency: RenderedNode } -export type RenderedNodeType = "build" | "deploy" | "run" | "test" | "push" | "publish" +export type RenderedNodeType = "build" | "deploy" | "run" | "test" | "publish" export interface RenderedNode { type: RenderedNodeType name: string @@ -512,7 +511,6 @@ const renderedNodeTypeMap: RenderedNodeTypeMap = { service: "deploy", task: "run", test: "test", - push: "push", publish: "publish", } @@ -521,7 +519,6 @@ const depNodeTaskTypeMap: DepNodeTaskTypeMap = { service: "deploy", task: "task", test: "test", - push: "push", publish: "publish", } diff --git a/garden-service/src/plugins/kubernetes/container/build.ts b/garden-service/src/plugins/kubernetes/container/build.ts new file mode 100644 index 0000000000..b40eaaf521 --- /dev/null +++ b/garden-service/src/plugins/kubernetes/container/build.ts @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2018 Garden Technologies, Inc. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import { BuildModuleParams, GetBuildStatusParams } from "../../../types/plugin/params" +import { ContainerModule } from "../../container/config" +import { containerHelpers } from "../../container/helpers" +import { buildContainerModule, getContainerBuildStatus } from "../../container/build" + +export async function getBuildStatus(params: GetBuildStatusParams) { + const status = await getContainerBuildStatus(params) + + const { ctx } = params + + if (ctx.provider.config.deploymentRegistry) { + // TODO: Check if the image exists in the remote registry + } + + return status +} + +export async function buildModule(params: BuildModuleParams) { + const buildResult = await buildContainerModule(params) + + const { ctx, module, log } = params + + if (!ctx.provider.config.deploymentRegistry) { + return buildResult + } + + if (!(await containerHelpers.hasDockerfile(module))) { + return buildResult + } + + const localId = await containerHelpers.getLocalImageId(module) + const remoteId = await containerHelpers.getDeploymentImageId(module, ctx.provider.config.deploymentRegistry) + + log.setState({ msg: `Pushing image ${remoteId} to cluster...` }) + + await containerHelpers.dockerCli(module, ["tag", localId, remoteId]) + await containerHelpers.dockerCli(module, ["push", remoteId]) + + return buildResult +} diff --git a/garden-service/src/plugins/kubernetes/container/deployment.ts b/garden-service/src/plugins/kubernetes/container/deployment.ts index 6529d092b6..9d923af9e0 100644 --- a/garden-service/src/plugins/kubernetes/container/deployment.ts +++ b/garden-service/src/plugins/kubernetes/container/deployment.ts @@ -7,7 +7,7 @@ */ import { extend, keyBy, set, toPairs } from "lodash" -import { DeployServiceParams, PushModuleParams, DeleteServiceParams } from "../../../types/plugin/params" +import { DeployServiceParams, DeleteServiceParams } from "../../../types/plugin/params" import { RuntimeContext, Service, ServiceStatus } from "../../../types/service" import { ContainerModule, ContainerService } from "../../container/config" import { createIngressResources } from "./ingress" @@ -421,23 +421,3 @@ export async function deleteContainerDeployment( found ? log.setSuccess("Service deleted") : log.setWarn("Service not deployed") } } - -export async function pushModule({ ctx, module, log }: PushModuleParams) { - if (!ctx.provider.config.deploymentRegistry) { - return { pushed: false } - } - - if (!(await containerHelpers.hasDockerfile(module))) { - return { pushed: false } - } - - const localId = await containerHelpers.getLocalImageId(module) - const remoteId = await containerHelpers.getDeploymentImageId(module, ctx.provider.config.deploymentRegistry) - - log.setState({ msg: `Pushing image ${remoteId}...` }) - - await containerHelpers.dockerCli(module, ["tag", localId, remoteId]) - await containerHelpers.dockerCli(module, ["push", remoteId]) - - return { pushed: true, message: `Pushed ${remoteId}` } -} diff --git a/garden-service/src/plugins/kubernetes/container/handlers.ts b/garden-service/src/plugins/kubernetes/container/handlers.ts index fa5ae09a72..f6024535bd 100644 --- a/garden-service/src/plugins/kubernetes/container/handlers.ts +++ b/garden-service/src/plugins/kubernetes/container/handlers.ts @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { deployContainerService, deleteService, pushModule } from "./deployment" +import { deployContainerService, deleteService } from "./deployment" import { hotReloadContainer } from "../hot-reload" import { getServiceLogs } from "./logs" import { execInService, runContainerModule, runContainerService, runContainerTask } from "./run" @@ -44,7 +44,6 @@ export const containerHandlers = { getServiceStatus: getContainerServiceStatus, getTestResult, hotReloadService: hotReloadContainer, - pushModule, runModule: runContainerModule, runService: runContainerService, runTask: runContainerTask, diff --git a/garden-service/src/tasks/base.ts b/garden-service/src/tasks/base.ts index a4a5e5dd28..97112078cf 100644 --- a/garden-service/src/tasks/base.ts +++ b/garden-service/src/tasks/base.ts @@ -13,7 +13,7 @@ import { Garden } from "../garden" import { DependencyGraphNodeType } from "../config-graph" import { LogEntry } from "../logger/log-entry" -export type TaskType = "build" | "deploy" | "publish" | "hot-reload" | "push" | "task" | "test" +export type TaskType = "build" | "deploy" | "publish" | "hot-reload" | "task" | "test" export class TaskDefinitionError extends Error { } diff --git a/garden-service/src/tasks/build.ts b/garden-service/src/tasks/build.ts index 4da586d0d7..572a4b1bf1 100644 --- a/garden-service/src/tasks/build.ts +++ b/garden-service/src/tasks/build.ts @@ -14,7 +14,6 @@ import { BaseTask, TaskType } from "../tasks/base" import { Garden } from "../garden" import { DependencyGraphNodeType } from "../config-graph" import { LogEntry } from "../logger/log-entry" -import { PushTask } from "./push" export interface BuildTaskParams { garden: Garden @@ -45,7 +44,7 @@ export class BuildTask extends BaseTask { const deps = (await dg.getDependencies(this.depType, this.getName(), false)).build return Bluebird.map(deps, async (m: Module) => { - return new PushTask({ + return new BuildTask({ garden: this.garden, log: this.log, module: m, diff --git a/garden-service/src/tasks/deploy.ts b/garden-service/src/tasks/deploy.ts index de6d791e35..08538b8871 100644 --- a/garden-service/src/tasks/deploy.ts +++ b/garden-service/src/tasks/deploy.ts @@ -13,9 +13,9 @@ import { LogEntry } from "../logger/log-entry" import { BaseTask, TaskType } from "./base" import { Service, ServiceStatus, getServiceRuntimeContext, getIngressUrl } from "../types/service" import { Garden } from "../garden" -import { PushTask } from "./push" import { TaskTask } from "./task" import { DependencyGraphNodeType, ConfigGraph } from "../config-graph" +import { BuildTask } from "./build" export interface DeployTaskParams { garden: Garden @@ -83,7 +83,7 @@ export class DeployTask extends BaseTask { }) }) - const pushTask = new PushTask({ + const buildTask = new BuildTask({ garden: this.garden, log: this.log, module: this.service.module, @@ -92,7 +92,7 @@ export class DeployTask extends BaseTask { hotReloadServiceNames: this.hotReloadServiceNames, }) - return [...deployTasks, ...taskTasks, pushTask] + return [...deployTasks, ...taskTasks, buildTask] } } diff --git a/garden-service/src/tasks/helpers.ts b/garden-service/src/tasks/helpers.ts index ea9ac5c8f4..47792636bf 100644 --- a/garden-service/src/tasks/helpers.ts +++ b/garden-service/src/tasks/helpers.ts @@ -8,13 +8,13 @@ import { intersection, uniq } from "lodash" import { DeployTask } from "./deploy" -import { PushTask } from "./push" import { Garden } from "../garden" import { Module } from "../types/module" import { Service } from "../types/service" import { DependencyGraphNode, ConfigGraph } from "../config-graph" import { LogEntry } from "../logger/log-entry" import { BaseTask } from "./base" +import { BuildTask } from "./build" export async function getDependantTasksForModule( { garden, log, graph, module, hotReloadServiceNames, force = false, forceBuild = false, @@ -32,12 +32,12 @@ export async function getDependantTasksForModule( }, ): Promise { - let pushTasks: PushTask[] = [] + let buildTasks: BuildTask[] = [] let dependantBuildModules: Module[] = [] let services: Service[] = [] if (!includeDependants) { - pushTasks.push(new PushTask({ garden, log, module, force: forceBuild, fromWatch, hotReloadServiceNames })) + buildTasks.push(new BuildTask({ garden, log, module, force: forceBuild, fromWatch, hotReloadServiceNames })) services = await graph.getServices(module.serviceNames) } else { const hotReloadModuleNames = await getModuleNames(graph, hotReloadServiceNames) @@ -54,14 +54,14 @@ export async function getDependantTasksForModule( } else { const dependants = await graph.getDependantsForModule(module, dependantFilterFn) - pushTasks.push(new PushTask({ garden, log, module, force: true, fromWatch, hotReloadServiceNames })) + buildTasks.push(new BuildTask({ garden, log, module, force: true, fromWatch, hotReloadServiceNames })) dependantBuildModules = dependants.build services = (await graph.getServices(module.serviceNames)).concat(dependants.service) } } - pushTasks.push(...dependantBuildModules - .map(m => new PushTask({ garden, log, module: m, force: forceBuild, fromWatch, hotReloadServiceNames }))) + buildTasks.push(...dependantBuildModules + .map(m => new BuildTask({ garden, log, module: m, force: forceBuild, fromWatch, hotReloadServiceNames }))) const deployTasks = services .map(service => new DeployTask({ @@ -74,7 +74,7 @@ export async function getDependantTasksForModule( fromWatch, hotReloadServiceNames, })) - const outputTasks = [...pushTasks, ...deployTasks] + const outputTasks = [...buildTasks, ...deployTasks] log.silly(`getDependantTasksForModule called for module ${module.name}, returning the following tasks:`) log.silly(` ${outputTasks.map(t => t.getKey()).join(", ")}`) diff --git a/garden-service/src/tasks/push.ts b/garden-service/src/tasks/push.ts deleted file mode 100644 index 1aa1ad370d..0000000000 --- a/garden-service/src/tasks/push.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2018 Garden Technologies, Inc. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import * as Bluebird from "bluebird" -import chalk from "chalk" -import { BuildTask } from "./build" -import { Module } from "../types/module" -import { PushResult } from "../types/plugin/outputs" -import { BaseTask, TaskType } from "../tasks/base" -import { Garden } from "../garden" -import { DependencyGraphNodeType } from "../config-graph" -import { LogEntry } from "../logger/log-entry" - -export interface PushTaskParams { - garden: Garden - log: LogEntry - module: Module - force: boolean - fromWatch?: boolean - hotReloadServiceNames?: string[] -} - -export class PushTask extends BaseTask { - type: TaskType = "push" - depType: DependencyGraphNodeType = "push" - - force: boolean - private module: Module - private fromWatch: boolean - private hotReloadServiceNames: string[] - - constructor({ garden, log, module, force, fromWatch = false, hotReloadServiceNames = [] }: PushTaskParams) { - super({ garden, log, version: module.version }) - this.module = module - this.force = force - this.fromWatch = fromWatch - this.hotReloadServiceNames = hotReloadServiceNames - } - - async getDependencies() { - const dg = await this.garden.getConfigGraph() - const deps = (await dg.getDependencies(this.depType, this.getName(), false)).build - - const buildTask = new BuildTask({ - garden: this.garden, - log: this.log, - module: this.module, - force: this.force, - fromWatch: this.fromWatch, - hotReloadServiceNames: this.hotReloadServiceNames, - }) - - const pushTasks = await Bluebird.map(deps, async (m: Module) => { - return new PushTask({ - garden: this.garden, - log: this.log, - module: m, - force: this.force, - fromWatch: this.fromWatch, - hotReloadServiceNames: this.hotReloadServiceNames, - }) - }) - - return [buildTask, ...pushTasks] - } - - getName() { - return this.module.name - } - - getDescription() { - return `pushing module ${this.module.name}` - } - - async process(): Promise { - // avoid logging stuff if there is no push handler - const defaultHandler = async () => ({ pushed: false }) - const handler = await this.garden.actions.getModuleActionHandler({ - moduleType: this.module.type, - actionType: "pushModule", - defaultHandler, - }) - - if (handler === defaultHandler) { - this.log.verbose(`No push handler for module ${this.module.name}`) - return { pushed: false } - } - - const log = this.log.info({ - section: this.module.name, - msg: "Pushing...", - status: "active", - }) - - let result: PushResult - try { - result = await this.garden.actions.pushModule({ module: this.module, log }) - } catch (err) { - log.setError() - throw err - } - - if (result.pushed) { - log.setSuccess({ msg: chalk.green(result.message || `Done (took ${log.getDuration(1)} sec)`), append: true }) - } else if (result.message) { - log.setWarn({ msg: result.message, append: true }) - } else { - log.setSuccess({ msg: chalk.green(result.message || `Done (took ${log.getDuration(1)} sec)`), append: true }) - } - - return result - } -} diff --git a/garden-service/src/tasks/task.ts b/garden-service/src/tasks/task.ts index 6d4f6b15f8..a58144a8c6 100644 --- a/garden-service/src/tasks/task.ts +++ b/garden-service/src/tasks/task.ts @@ -11,13 +11,13 @@ import chalk from "chalk" import { BaseTask, TaskParams, TaskType } from "../tasks/base" import { Garden } from "../garden" import { Task } from "../types/task" -import { PushTask } from "./push" import { DeployTask } from "./deploy" import { LogEntry } from "../logger/log-entry" import { RunTaskResult } from "../types/plugin/outputs" import { prepareRuntimeContext } from "../types/service" import { DependencyGraphNodeType, ConfigGraph } from "../config-graph" import { ModuleVersion } from "../vcs/vcs" +import { BuildTask } from "./build" export interface TaskTaskParams { garden: Garden @@ -51,8 +51,7 @@ export class TaskTask extends BaseTask { // ... to be renamed soon. } async getDependencies(): Promise { - - const pushTask = new PushTask({ + const buildTask = new BuildTask({ garden: this.garden, log: this.log, module: this.task.module, @@ -84,7 +83,7 @@ export class TaskTask extends BaseTask { // ... to be renamed soon. }) }) - return [pushTask, ...deployTasks, ...taskTasks] + return [buildTask, ...deployTasks, ...taskTasks] } diff --git a/garden-service/src/tasks/test.ts b/garden-service/src/tasks/test.ts index 81f400b7b7..56fa5c4faa 100644 --- a/garden-service/src/tasks/test.ts +++ b/garden-service/src/tasks/test.ts @@ -11,7 +11,6 @@ import chalk from "chalk" import { Module } from "../types/module" import { TestConfig } from "../config/test" import { ModuleVersion } from "../vcs/vcs" -import { PushTask } from "./push" import { DeployTask } from "./deploy" import { TestResult } from "../types/plugin/outputs" import { BaseTask, TaskParams, TaskType } from "../tasks/base" @@ -20,6 +19,7 @@ import { Garden } from "../garden" import { LogEntry } from "../logger/log-entry" import { DependencyGraphNodeType, ConfigGraph } from "../config-graph" import { makeTestTaskName } from "./helpers" +import { BuildTask } from "./build" class TestError extends Error { toString() { @@ -71,7 +71,7 @@ export class TestTask extends BaseTask { const dg = this.graph const services = (await dg.getDependencies(this.depType, this.getName(), false)).service - const deps: BaseTask[] = [new PushTask({ + const deps: BaseTask[] = [new BuildTask({ garden: this.garden, log: this.log, module: this.module, diff --git a/garden-service/src/types/plugin/outputs.ts b/garden-service/src/types/plugin/outputs.ts index 81c7c9f14a..13a02603a2 100644 --- a/garden-service/src/types/plugin/outputs.ts +++ b/garden-service/src/types/plugin/outputs.ts @@ -190,19 +190,6 @@ export const buildModuleResultSchema = Joi.object() export interface HotReloadServiceResult { } export const hotReloadServiceResultSchema = Joi.object() -export interface PushResult { - pushed: boolean - message?: string -} -export const pushModuleResultSchema = Joi.object() - .keys({ - pushed: Joi.boolean() - .required() - .description("Set to true if the module was pushed."), - message: Joi.string() - .description("Optional result message."), - }) - export interface PublishResult { published: boolean message?: string @@ -343,7 +330,6 @@ export interface ModuleActionOutputs extends ServiceActionOutputs { configure: Promise getBuildStatus: Promise build: Promise - pushModule: Promise publishModule: Promise runModule: Promise testModule: Promise diff --git a/garden-service/src/types/plugin/params.ts b/garden-service/src/types/plugin/params.ts index ebbd305109..05de3c4abd 100644 --- a/garden-service/src/types/plugin/params.ts +++ b/garden-service/src/types/plugin/params.ts @@ -166,9 +166,6 @@ export const getBuildStatusParamsSchema = moduleActionParamsSchema export interface BuildModuleParams extends PluginModuleActionParamsBase { } export const buildModuleParamsSchema = moduleActionParamsSchema -export interface PushModuleParams extends PluginModuleActionParamsBase { } -export const pushModuleParamsSchema = moduleActionParamsSchema - export interface PublishModuleParams extends PluginModuleActionParamsBase { } export const publishModuleParamsSchema = moduleActionParamsSchema @@ -366,7 +363,6 @@ export interface ModuleActionParams { configure: ConfigureModuleParams getBuildStatus: GetBuildStatusParams build: BuildModuleParams - pushModule: PushModuleParams publishModule: PublishModuleParams runModule: RunModuleParams testModule: TestModuleParams diff --git a/garden-service/src/types/plugin/plugin.ts b/garden-service/src/types/plugin/plugin.ts index eee5e34706..c25783a35a 100644 --- a/garden-service/src/types/plugin/plugin.ts +++ b/garden-service/src/types/plugin/plugin.ts @@ -38,7 +38,6 @@ import { configureModuleParamsSchema, getBuildStatusParamsSchema, buildModuleParamsSchema, - pushModuleParamsSchema, hotReloadServiceParamsSchema, runModuleParamsSchema, testModuleParamsSchema, @@ -62,7 +61,6 @@ import { ModuleActionOutputs, moduleTypeDescriptionSchema, PluginActionOutputs, - pushModuleResultSchema, hotReloadServiceResultSchema, runResultSchema, ServiceActionOutputs, @@ -338,36 +336,16 @@ export const moduleActionDescriptions: description: dedent` Build the current version of a module. This must wait until the build is complete before returning. - Called ahead of a number of actions, including \`deployService\`, \`pushModule\` and \`publishModule\`. + Called ahead of a number of actions, including \`deployService\` and \`publishModule\`. `, paramsSchema: buildModuleParamsSchema, resultSchema: buildModuleResultSchema, }, - pushModule: { - description: dedent` - Push the build for current version of a module to the deployment environment, making it accessible - to the development environment. An example being a container registry or artifact registry that's - available to the deployment environment when deploying. - - Note the distinction to \`publishModule\` which may, depending on the module type, work similarly but - is only called when explicitly calling the \`garden publish\`. - - This is usually not necessary for plugins that run locally. - - Called before the \`deployService\` action. - `, - paramsSchema: pushModuleParamsSchema, - resultSchema: pushModuleResultSchema, - }, - publishModule: { description: dedent` Publish a built module to a remote registry. - Note the distinction to \`pushModule\` which may, depending on the module type, work similarly but - is automatically called ahead of \`deployService\`. - Called by the \`garden publish\` command. `, paramsSchema: publishModuleParamsSchema, diff --git a/garden-service/test/unit/src/actions.ts b/garden-service/test/unit/src/actions.ts index ded7f7a630..0e0bb81832 100644 --- a/garden-service/test/unit/src/actions.ts +++ b/garden-service/test/unit/src/actions.ts @@ -17,7 +17,6 @@ import { configureModuleParamsSchema, getBuildStatusParamsSchema, buildModuleParamsSchema, - pushModuleParamsSchema, runModuleParamsSchema, testModuleParamsSchema, getTestResultParamsSchema, @@ -154,15 +153,6 @@ describe("ActionHelper", () => { }) }) - describe("pushModule", () => { - it("should correctly call the corresponding plugin handler", async () => { - const result = await actions.pushModule({ log, module }) - expect(result).to.eql({ - pushed: true, - }) - }) - }) - describe("hotReloadService", () => { it("should correctly call the corresponding plugin handler", async () => { const result = await actions.hotReloadService({ @@ -494,11 +484,6 @@ const testPlugin: PluginFactory = async () => ({ return { published: true } }, - pushModule: async (params) => { - validate(params, pushModuleParamsSchema) - return { pushed: true } - }, - hotReloadService: async (params) => { validate(params, hotReloadServiceParamsSchema) return {} diff --git a/garden-service/test/unit/src/commands/build.ts b/garden-service/test/unit/src/commands/build.ts index ea7d74112b..03eadce9d1 100644 --- a/garden-service/test/unit/src/commands/build.ts +++ b/garden-service/test/unit/src/commands/build.ts @@ -22,8 +22,6 @@ describe("commands.build", () => { "build.module-a": { fresh: true, buildLog: "A" }, "build.module-b": { fresh: true, buildLog: "B" }, "build.module-c": {}, - "push.module-a": { pushed: false }, - "push.module-b": { pushed: false }, }) }) @@ -44,7 +42,6 @@ describe("commands.build", () => { expect(taskResultOutputs(result!)).to.eql({ "build.module-a": { fresh: true, buildLog: "A" }, "build.module-b": { fresh: true, buildLog: "B" }, - "push.module-a": { pushed: false }, }) }) }) diff --git a/garden-service/test/unit/src/commands/deploy.ts b/garden-service/test/unit/src/commands/deploy.ts index 49c16af72a..b12f64f2e6 100644 --- a/garden-service/test/unit/src/commands/deploy.ts +++ b/garden-service/test/unit/src/commands/deploy.ts @@ -122,9 +122,6 @@ describe("DeployCommand", () => { "deploy.service-b": { version: "1", state: "ready" }, "deploy.service-c": { version: "1", state: "ready" }, "deploy.service-d": { version: "1", state: "ready" }, - "push.module-a": { pushed: false }, - "push.module-b": { pushed: false }, - "push.module-c": { pushed: false }, }) }) @@ -160,9 +157,6 @@ describe("DeployCommand", () => { "task.task-c": taskResultC, "deploy.service-a": { version: "1", state: "ready" }, "deploy.service-b": { version: "1", state: "ready" }, - "push.module-a": { pushed: false }, - "push.module-b": { pushed: false }, - "push.module-c": { pushed: false }, }) }) }) diff --git a/garden-service/test/unit/src/commands/publish.ts b/garden-service/test/unit/src/commands/publish.ts index 544e592fba..4a04fe13cc 100644 --- a/garden-service/test/unit/src/commands/publish.ts +++ b/garden-service/test/unit/src/commands/publish.ts @@ -66,7 +66,6 @@ describe("PublishCommand", () => { expect(taskResultOutputs(result!)).to.eql({ "build.module-a": { fresh: false }, "build.module-b": { fresh: false }, - "push.module-a": { pushed: false }, "publish.module-a": { published: true }, "publish.module-b": { published: true }, "publish.module-c": { published: false }, @@ -94,7 +93,6 @@ describe("PublishCommand", () => { expect(taskResultOutputs(result!)).to.eql({ "build.module-a": { fresh: true }, "build.module-b": { fresh: true }, - "push.module-a": { pushed: false }, "publish.module-a": { published: true }, "publish.module-b": { published: true }, "publish.module-c": { published: false }, diff --git a/garden-service/test/unit/src/config-graph.ts b/garden-service/test/unit/src/config-graph.ts index 935a635e80..9f3f45134d 100644 --- a/garden-service/test/unit/src/config-graph.ts +++ b/garden-service/test/unit/src/config-graph.ts @@ -276,6 +276,7 @@ describe("DependencyGraphNode", () => { key: "build.module-a", }) }) + it("should render a deploy node", () => { const node = new DependencyGraphNode("service", "service-a", "module-a") const res = node.render() @@ -286,6 +287,7 @@ describe("DependencyGraphNode", () => { key: "deploy.service-a", }) }) + it("should render a run node", () => { const node = new DependencyGraphNode("task", "task-a", "module-a") const res = node.render() @@ -296,6 +298,7 @@ describe("DependencyGraphNode", () => { key: "task.task-a", }) }) + it("should render a test node", () => { const node = new DependencyGraphNode("test", "module-a.test-a", "module-a") const res = node.render() @@ -306,16 +309,7 @@ describe("DependencyGraphNode", () => { key: "test.module-a.test-a", }) }) - it("should render a push node", () => { - const node = new DependencyGraphNode("push", "module-a", "module-a") - const res = node.render() - expect(res).to.eql({ - type: "push", - name: "module-a", - moduleName: "module-a", - key: "push.module-a", - }) - }) + it("should render a publish node", () => { const node = new DependencyGraphNode("publish", "module-a", "module-a") const res = node.render() diff --git a/garden-service/test/unit/src/tasks/helpers.ts b/garden-service/test/unit/src/tasks/helpers.ts index 9f97904a55..c0129eab2d 100644 --- a/garden-service/test/unit/src/tasks/helpers.ts +++ b/garden-service/test/unit/src/tasks/helpers.ts @@ -9,9 +9,9 @@ import { BaseTask } from "../../../../src/tasks/base" import { LogEntry } from "../../../../src/logger/log-entry" import { ConfigGraph } from "../../../../src/config-graph" -async function sortedBaseKeysdependencyTasks(tasks: BaseTask[]): Promise { +async function dependencyBaseKeys(tasks: BaseTask[]): Promise { const dependencies = await Bluebird.map(tasks, async (t) => t.getDependencies(), { concurrency: 1 }) - const tasksdependencyTasks = flatten([tasks].concat(dependencies)) + const tasksdependencyTasks = flatten(dependencies) return sortedBaseKeys(tasksdependencyTasks) } @@ -46,14 +46,13 @@ describe("TaskHelpers", () => { }) expect(sortedBaseKeys(tasks)).to.eql([ + "build.good-morning", "deploy.good-morning", - "push.good-morning", ]) - expect(await sortedBaseKeysdependencyTasks(tasks)).to.eql([ + expect(await dependencyBaseKeys(tasks)).to.eql([ + "build.build-dependency", "build.good-morning", - "deploy.good-morning", - "push.good-morning", "task.good-morning-task", ].sort()) }) @@ -62,170 +61,170 @@ describe("TaskHelpers", () => { const expectedBaseKeysByChangedModule = [ { moduleName: "build-dependency", - expected: [ - "push.build-dependency", + taskKeys: [ + "build.build-dependency", "deploy.build-dependency", - - "push.good-morning", - "deploy.good-morning", - - "push.build-dependant", - "deploy.build-dependant", - - "deploy.service-dependant", - "deploy.service-dependant2", ], - dependencyTasks: [ + withDependants: [ "build.build-dependant", "build.build-dependency", "build.good-morning", - - "push.service-dependant", - "push.service-dependant2", - - "task.good-morning-task", + "deploy.build-dependant", + "deploy.build-dependency", + "deploy.good-morning", + "deploy.service-dependant", + "deploy.service-dependant2", ], }, { moduleName: "good-morning", - expected: [ - "push.good-morning", + taskKeys: [ + "build.good-morning", "deploy.good-morning", - - "push.build-dependant", - "deploy.build-dependant", - - "deploy.service-dependant", - "deploy.service-dependant2", ], - dependencyTasks: [ + withDependants: [ "build.build-dependant", "build.good-morning", - - "push.service-dependant", - "push.service-dependant2", - - "task.good-morning-task", + "deploy.build-dependant", + "deploy.good-morning", + "deploy.service-dependant", + "deploy.service-dependant2", ], }, { moduleName: "good-evening", - expected: [ + taskKeys: [ + "build.good-evening", "deploy.good-evening", - "push.good-evening", ], - dependencyTasks: [ + withDependants: [ "build.good-evening", + "deploy.good-evening", ], }, { moduleName: "build-dependant", - expected: [ + taskKeys: [ + "build.build-dependant", "deploy.build-dependant", - "push.build-dependant", ], - dependencyTasks: [ + withDependants: [ "build.build-dependant", + "deploy.build-dependant", ], }, { moduleName: "service-dependant", - expected: [ + taskKeys: [ + "build.service-dependant", "deploy.service-dependant", - "push.service-dependant", ], - dependencyTasks: [ + withDependants: [ "build.service-dependant", - "deploy.good-morning", + "deploy.service-dependant", ], }, ] - for (const { moduleName, expected, dependencyTasks } of expectedBaseKeysByChangedModule) { - it(`returns the correct set of tasks for ${moduleName} and its dependants`, async () => { + for (const { moduleName, taskKeys, withDependants } of expectedBaseKeysByChangedModule) { + it(`returns the correct set of tasks for ${moduleName}`, async () => { const module = await graph.getModule(moduleName) const tasks = await getDependantTasksForModule({ garden, graph, log, module, hotReloadServiceNames: [], force: true, forceBuild: true, - fromWatch: true, includeDependants: true, + fromWatch: true, includeDependants: false, }) - expect(sortedBaseKeys(tasks)).to.eql(expected.sort()) - expect(await sortedBaseKeysdependencyTasks(tasks)).to.eql(expected.concat(dependencyTasks).sort()) + expect(sortedBaseKeys(tasks)).to.eql(taskKeys.sort()) }) + it(`returns the correct set of tasks for ${moduleName} with dependants`, async () => { + const module = await graph.getModule(moduleName) + const tasks = await getDependantTasksForModule({ + garden, graph, log, module, hotReloadServiceNames: [], force: true, forceBuild: true, + fromWatch: true, includeDependants: true, + }) + expect(sortedBaseKeys(tasks)).to.eql(withDependants.sort()) + }) } - }) context("with hot reloading enabled", () => { const expectedBaseKeysByChangedModule = [ { moduleName: "build-dependency", - expected: [ - "push.build-dependency", + taskKeys: [ + "build.build-dependency", "deploy.build-dependency", ], - dependencyTasks: [ + withDependants: [ "build.build-dependency", + "deploy.build-dependency", ], }, { moduleName: "good-morning", - expected: [ + taskKeys: [ + "build.good-morning", + "deploy.good-morning", + ], + withDependants: [ "deploy.service-dependant", "deploy.service-dependant2", ], - dependencyTasks: [ - "push.service-dependant", - "push.service-dependant2", - ], }, { moduleName: "good-evening", - expected: [ + taskKeys: [ + "build.good-evening", "deploy.good-evening", - "push.good-evening", ], - dependencyTasks: [ + withDependants: [ "build.good-evening", + "deploy.good-evening", ], }, { moduleName: "build-dependant", - expected: [ + taskKeys: [ + "build.build-dependant", "deploy.build-dependant", - "push.build-dependant", ], - dependencyTasks: [ + withDependants: [ "build.build-dependant", + "deploy.build-dependant", ], }, { moduleName: "service-dependant", - expected: [ + taskKeys: [ + "build.service-dependant", "deploy.service-dependant", - "push.service-dependant", ], - dependencyTasks: [ + withDependants: [ "build.service-dependant", + "deploy.service-dependant", ], }, ] - for (const { moduleName, expected, dependencyTasks } of expectedBaseKeysByChangedModule) { - it(`returns the correct set of tasks for ${moduleName} and its dependants`, async () => { + for (const { moduleName, taskKeys, withDependants } of expectedBaseKeysByChangedModule) { + it(`returns the correct set of tasks for ${moduleName}`, async () => { const module = await graph.getModule(moduleName) const tasks = await getDependantTasksForModule({ garden, graph, log, module, hotReloadServiceNames: ["good-morning"], force: true, forceBuild: true, - fromWatch: true, includeDependants: true, + fromWatch: true, includeDependants: false, }) - expect(sortedBaseKeys(tasks)).to.eql(expected.sort()) - expect(await sortedBaseKeysdependencyTasks(tasks)).to.eql(expected.concat(dependencyTasks).sort()) + expect(sortedBaseKeys(tasks)).to.eql(taskKeys.sort()) }) + it(`returns the correct set of tasks for ${moduleName} with dependants`, async () => { + const module = await graph.getModule(moduleName) + const tasks = await getDependantTasksForModule({ + garden, graph, log, module, hotReloadServiceNames: ["good-morning"], force: true, forceBuild: true, + fromWatch: true, includeDependants: true, + }) + expect(sortedBaseKeys(tasks)).to.eql(withDependants.sort()) + }) } - }) - }) - })