Skip to content

Commit

Permalink
refactor: rename generic plugin to exec
Browse files Browse the repository at this point in the history
This naming is much more clear, since basically the plugin executes
commands in a shell, and the name `generic` doesn't give any indication
as to how it works.

BREAKING CHANGE:
Projects using the `generic` module type need to update the relevant
`garden.yml` files, to reference the `exec` module type instead.
  • Loading branch information
edvald committed Dec 17, 2018
1 parent 9f0f9d0 commit 4c85d46
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 98 deletions.
8 changes: 4 additions & 4 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ project:
## Built-in module types
### generic
### exec
```yaml

# The module specification for a generic module.
# The module specification for an exec module.
#
# Required.
module:
Expand Down Expand Up @@ -305,7 +305,7 @@ module:
#
# Optional.
tests:
# The test specification of a generic module.
# The test specification of an exec module.
#
# Optional.
- # The name of the test.
Expand Down Expand Up @@ -646,7 +646,7 @@ module:
#
# Optional.
tests:
# The test specification of a generic module.
# The test specification of an exec module.
#
# Optional.
- # The name of the test.
Expand Down
2 changes: 1 addition & 1 deletion docs/using-garden/configuration-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ modules use the same name.

A [module](../reference/glossary.md#module)'s `type` specifies what kind of module this is, which will control how the
module's code gets built, tested, deployed, etc. The module types are implemented by _providers_. The built-in module types
include `container` and `generic` (which basically provides a way to run commands locally).
include `container` and `exec` (which basically provides a way to run commands locally).

The example above is a `container` module, and the `hello-function` module is an `openfaas` module
(which is one of many ways to run functions-as-a-service on Kubernetes).
Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/docs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import {
padEnd,
} from "lodash"
import { containerModuleSpecSchema } from "../plugins/container"
import { genericModuleSpecSchema } from "../plugins/generic"
import { execModuleSpecSchema } from "../plugins/exec"
import { configSchema } from "../config/base"
import { baseModuleSpecSchema } from "../config/module"

const maxWidth = 100
const builtInModuleTypes = [
{ name: "generic", schema: genericModuleSpecSchema },
{ name: "exec", schema: execModuleSpecSchema },
{ name: "container", schema: containerModuleSpecSchema },
]

Expand Down
18 changes: 9 additions & 9 deletions garden-service/src/plugins/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ import { DEFAULT_PORT_PROTOCOL } from "../constants"
import { splitFirst } from "../util/util"
import { keyBy } from "lodash"
import {
genericTestSchema,
GenericTestSpec,
GenericTaskSpec,
genericTaskSpecSchema,
} from "./generic"
execTestSchema,
ExecTestSpec,
ExecTaskSpec,
execTaskSpecSchema,
} from "./exec"
import { ModuleSpec, ModuleConfig } from "../config/module"
import { BaseServiceSpec, ServiceConfig, baseServiceSchema } from "../config/service"

Expand Down Expand Up @@ -256,15 +256,15 @@ export const containerRegistryConfigSchema = Joi.object()

export interface ContainerService extends Service<ContainerModule> { }

export interface ContainerTestSpec extends GenericTestSpec { }
export interface ContainerTestSpec extends ExecTestSpec { }

export const containerTestSchema = genericTestSchema
export const containerTestSchema = execTestSchema

export interface ContainerTaskSpec extends GenericTaskSpec {
export interface ContainerTaskSpec extends ExecTaskSpec {
command: string[],
}

export const containerTaskSchema = genericTaskSpecSchema
export const containerTaskSchema = execTaskSpecSchema
.keys({
command: Joi.array().items(Joi.string())
.description("The command that the task should run inside the container."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,52 +38,52 @@ import { ModuleSpec, ModuleConfig } from "../config/module"
import execa = require("execa")
import { BaseTaskSpec, baseTaskSpecSchema } from "../config/task"

export const name = "generic"
export const name = "exec"

export interface GenericTestSpec extends BaseTestSpec {
export interface ExecTestSpec extends BaseTestSpec {
command: string[],
env: { [key: string]: string },
}

export const genericTestSchema = baseTestSpecSchema
export const execTestSchema = baseTestSpecSchema
.keys({
command: Joi.array().items(Joi.string())
.description("The command to run in the module build context in order to test it."),
env: joiEnvVars(),
})
.description("The test specification of a generic module.")
.description("The test specification of an exec module.")

export interface GenericTaskSpec extends BaseTaskSpec {
export interface ExecTaskSpec extends BaseTaskSpec {
command: string[],
}

export const genericTaskSpecSchema = baseTaskSpecSchema
export const execTaskSpecSchema = baseTaskSpecSchema
.keys({
command: Joi.array().items(Joi.string())
.description("The command to run in the module build context."),
})
.description("A task that can be run in this module.")

export interface GenericModuleSpec extends ModuleSpec {
export interface ExecModuleSpec extends ModuleSpec {
env: { [key: string]: string },
tests: GenericTestSpec[],
tests: ExecTestSpec[],
}

export const genericModuleSpecSchema = Joi.object()
export const execModuleSpecSchema = Joi.object()
.keys({
env: joiEnvVars(),
tests: joiArray(genericTestSchema)
tests: joiArray(execTestSchema)
.description("A list of tests to run in the module."),
})
.unknown(false)
.description("The module specification for a generic module.")
.description("The module specification for an exec module.")

export interface GenericModule extends Module<GenericModuleSpec, BaseServiceSpec, GenericTestSpec> { }
export interface ExecModule extends Module<ExecModuleSpec, BaseServiceSpec, ExecTestSpec> { }

export async function parseGenericModule(
{ moduleConfig }: ValidateModuleParams<GenericModule>,
export async function parseExecModule(
{ moduleConfig }: ValidateModuleParams<ExecModule>,
): Promise<ValidateModuleResult> {
moduleConfig.spec = validate(moduleConfig.spec, genericModuleSpecSchema, { context: `module ${moduleConfig.name}` })
moduleConfig.spec = validate(moduleConfig.spec, execModuleSpecSchema, { context: `module ${moduleConfig.name}` })

moduleConfig.testConfigs = moduleConfig.spec.tests.map(t => ({
name: t.name,
Expand All @@ -95,7 +95,7 @@ export async function parseGenericModule(
return moduleConfig
}

export async function getGenericModuleBuildStatus({ module }: GetBuildStatusParams): Promise<BuildStatus> {
export async function getExecModuleBuildStatus({ module }: GetBuildStatusParams): Promise<BuildStatus> {
const buildVersionFilePath = join(module.buildPath, GARDEN_BUILD_VERSION_FILENAME)
let builtVersion: ModuleVersion | null = null

Expand All @@ -112,7 +112,7 @@ export async function getGenericModuleBuildStatus({ module }: GetBuildStatusPara
return { ready: false }
}

export async function buildGenericModule({ module }: BuildModuleParams<GenericModule>): Promise<BuildResult> {
export async function buildExecModule({ module }: BuildModuleParams<ExecModule>): Promise<BuildResult> {
const config: ModuleConfig = module
const output: BuildResult = {}
const buildPath = module.buildPath
Expand All @@ -137,7 +137,7 @@ export async function buildGenericModule({ module }: BuildModuleParams<GenericMo
return output
}

export async function testGenericModule({ module, testConfig }: TestModuleParams<GenericModule>): Promise<TestResult> {
export async function testExecModule({ module, testConfig }: TestModuleParams<ExecModule>): Promise<TestResult> {
const startedAt = new Date()
const command = testConfig.spec.command

Expand Down Expand Up @@ -167,7 +167,7 @@ export async function testGenericModule({ module, testConfig }: TestModuleParams
}
}

export async function runGenericTask(params: RunTaskParams): Promise<RunTaskResult> {
export async function runExecTask(params: RunTaskParams): Promise<RunTaskResult> {
const { task } = params
const module = task.module
const command = task.spec.command
Expand Down Expand Up @@ -204,20 +204,20 @@ export async function runGenericTask(params: RunTaskParams): Promise<RunTaskResu
}
}

export async function getGenericTaskStatus(): Promise<TaskStatus> {
export async function getExecTaskStatus(): Promise<TaskStatus> {
return { done: false }
}

export const genericPlugin: GardenPlugin = {
export const execPlugin: GardenPlugin = {
moduleActions: {
generic: {
validate: parseGenericModule,
getBuildStatus: getGenericModuleBuildStatus,
build: buildGenericModule,
runTask: runGenericTask,
testModule: testGenericModule,
exec: {
validate: parseExecModule,
getBuildStatus: getExecModuleBuildStatus,
build: buildExecModule,
runTask: runExecTask,
testModule: testExecModule,
},
},
}

export const gardenPlugin = () => genericPlugin
export const gardenPlugin = () => execPlugin
4 changes: 2 additions & 2 deletions garden-service/src/plugins/google/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Module } from "../../types/module"
import { PrepareEnvironmentParams } from "../../types/plugin/params"
import { Service } from "../../types/service"
import { ConfigurationError } from "../../exceptions"
import { GenericTestSpec } from "../generic"
import { ExecTestSpec } from "../exec"
import { GCloud } from "./gcloud"
import { ModuleSpec } from "../../config/module"
import { BaseServiceSpec } from "../../config/service"
Expand All @@ -25,7 +25,7 @@ export interface GoogleCloudServiceSpec extends BaseServiceSpec {
export interface GoogleCloudModule<
M extends ModuleSpec = ModuleSpec,
S extends GoogleCloudServiceSpec = GoogleCloudServiceSpec,
T extends GenericTestSpec = GenericTestSpec,
T extends ExecTestSpec = ExecTestSpec,
> extends Module<M, S, T> { }

export async function getEnvironmentStatus() {
Expand Down
8 changes: 4 additions & 4 deletions garden-service/src/plugins/google/google-cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from "path"
import * as Joi from "joi"
import { GARDEN_ANNOTATION_KEYS_VERSION } from "../../constants"
import { GenericTestSpec, genericTestSchema } from "../generic"
import { ExecTestSpec, execTestSchema } from "../exec"
import {
prepareEnvironment,
gcloud,
Expand Down Expand Up @@ -64,16 +64,16 @@ export const gcfServicesSchema = joiArray(gcfServiceSchema)

export interface GcfModuleSpec extends ModuleSpec {
functions: GcfServiceSpec[],
tests: GenericTestSpec[],
tests: ExecTestSpec[],
}

const gcfModuleSpecSchema = Joi.object()
.keys({
functions: gcfServicesSchema,
tests: joiArray(genericTestSchema),
tests: joiArray(execTestSchema),
})

export interface GcfModule extends Module<GcfModuleSpec, GcfServiceSpec, GenericTestSpec> { }
export interface GcfModule extends Module<GcfModuleSpec, GcfServiceSpec, ExecTestSpec> { }

export async function parseGcfModule(
{ moduleConfig }: ValidateModuleParams<GcfModule>,
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/plugins/kubernetes/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { GARDEN_BUILD_VERSION_FILENAME } from "../../constants"
import { writeTreeVersionFile } from "../../vcs/base"
import { ServiceState } from "../../types/service"
import { compareDeployedObjects, waitForObjects, checkObjectStatus } from "./status"
import { getGenericModuleBuildStatus } from "../generic"
import { getExecModuleBuildStatus } from "../exec"
import { ServiceSpec } from "../../config/service"
import { KubeApi } from "./api"
import { BinaryCmd } from "../../util/ext-tools"
Expand Down Expand Up @@ -131,7 +131,7 @@ export const helmHandlers: Partial<ModuleAndRuntimeActions<HelmModule>> = {
return moduleConfig
},

getBuildStatus: getGenericModuleBuildStatus,
getBuildStatus: getExecModuleBuildStatus,
build,
getServiceStatus,

Expand Down Expand Up @@ -307,7 +307,7 @@ async function getServiceStatus(
{ ctx, service, module, log, buildDependencies }: GetServiceStatusParams<HelmModule>,
): Promise<ServiceStatus> {
// need to build to be able to check the status
const buildStatus = await getGenericModuleBuildStatus({ ctx, module, log, buildDependencies })
const buildStatus = await getExecModuleBuildStatus({ ctx, module, log, buildDependencies })
if (!buildStatus.ready) {
await build({ ctx, module, log, buildDependencies })
}
Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/plugins/kubernetes/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "../../config/common"
import { GardenPlugin } from "../../types/plugin/plugin"
import { Provider, providerConfigBaseSchema, ProviderConfig } from "../../config/project"
import { getGenericTaskStatus } from "../generic"
import { getExecTaskStatus } from "../exec"
import {
deleteService,
execInService,
Expand Down Expand Up @@ -173,7 +173,7 @@ export function gardenPlugin({ config }: { config: KubernetesConfig }): GardenPl
container: {
getServiceStatus: getContainerServiceStatus,
deployService: deployContainerService,
getTaskStatus: getGenericTaskStatus,
getTaskStatus: getExecTaskStatus,
deleteService,
getServiceOutputs,
execInService,
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/plugins/kubernetes/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function setSecret({ ctx, key, value }: SetSecretParams) {
"garden.io/generated": "true",
},
},
type: "generic",
type: "exec",
stringData: { value },
},
}
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/plugins/npm-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import { GardenPlugin } from "../types/plugin/plugin"
import {
genericPlugin,
} from "./generic"
execPlugin,
} from "./exec"

export const gardenPlugin = (): GardenPlugin => ({
moduleActions: {
"npm-package": genericPlugin.moduleActions!.generic,
"npm-package": execPlugin.moduleActions!.exec,
},
})
Loading

0 comments on commit 4c85d46

Please sign in to comment.