From 5f656ac2c3ac1956143eab4adfb8390413b8acf2 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Sat, 22 Jun 2019 18:45:35 +0200 Subject: [PATCH] improvement(plugins): define schemas for module outputs and add docs Closes #670 --- docs/reference/module-types/container.md | 30 +++++++++++++++++-- docs/reference/module-types/exec.md | 5 ++-- docs/reference/module-types/helm.md | 22 ++++++++++++-- docs/reference/module-types/kubernetes.md | 5 ++-- .../reference/module-types/maven-container.md | 30 +++++++++++++++++-- docs/reference/module-types/openfaas.md | 5 ++-- docs/reference/template-strings.md | 4 +++ garden-service/src/actions.ts | 1 + garden-service/src/config/config-context.ts | 5 +++- garden-service/src/docs/config.ts | 29 +++++++++++------- .../src/docs/templates/module-type.hbs | 18 +++++++++-- .../src/docs/templates/template-strings.hbs | 4 +++ .../src/plugins/container/container.ts | 15 ++++++++++ .../src/plugins/container/helpers.ts | 25 ++++++++++------ garden-service/src/plugins/exec.ts | 1 + .../src/plugins/kubernetes/helm/handlers.ts | 9 ++++++ .../kubernetes/kubernetes-module/config.ts | 1 + .../maven-container/maven-container.ts | 7 ++++- .../src/plugins/openfaas/openfaas.ts | 9 ++++++ .../src/types/plugin/module/describeType.ts | 10 ++++++- garden-service/test/unit/src/actions.ts | 1 + .../test/unit/src/plugins/container.ts | 18 +++++++++++ 22 files changed, 211 insertions(+), 43 deletions(-) diff --git a/docs/reference/module-types/container.md b/docs/reference/module-types/container.md index e44d5bbbb2..7f40e3454e 100644 --- a/docs/reference/module-types/container.md +++ b/docs/reference/module-types/container.md @@ -10,11 +10,13 @@ other module types like [helm](https://docs.garden.io/reference/module-types/hel Below is the schema reference. For an introduction to configuring Garden modules, please look at our [Configuration guide](../../using-garden/configuration-files.md). -The reference is divided into two sections. The [first section](#configuration-keys) lists and describes the available +The [first section](#configuration-keys) lists and describes the available schema keys. The [second section](#complete-yaml-schema) contains the complete YAML schema. -## Configuration keys +`container` modules also export values that are available via the `${modules..outputs}`. See the +[Outputs](#outputs) section below for details. +## Configuration keys ### `apiVersion` @@ -946,4 +948,26 @@ tasks: command: args: env: {} -``` \ No newline at end of file +``` + +## Outputs + +The following keys are available via the `${modules..outputs}` template string key for `container` +modules. + +### `modules..outputs.local-image-name` + +The name of the image (without tag/version) that the module uses for local builds and deployments. + +| Type | Required | +| ---- | -------- | +| `string` | Yes + +### `modules..outputs.deployment-image-name` + +The name of the image (without tag/version) that the module will use during deployment. + +| Type | Required | +| ---- | -------- | +| `string` | Yes + diff --git a/docs/reference/module-types/exec.md b/docs/reference/module-types/exec.md index 4c0a823d3c..0f5f08bcf3 100644 --- a/docs/reference/module-types/exec.md +++ b/docs/reference/module-types/exec.md @@ -5,12 +5,11 @@ type fits your needs, and you just need to execute something (as opposed to depl Below is the schema reference. For an introduction to configuring Garden modules, please look at our [Configuration guide](../../using-garden/configuration-files.md). -The reference is divided into two sections. The [first section](#configuration-keys) lists and describes the available +The [first section](#configuration-keys) lists and describes the available schema keys. The [second section](#complete-yaml-schema) contains the complete YAML schema. ## Configuration keys - ### `apiVersion` The schema version of this module's config (currently not used). @@ -351,4 +350,4 @@ tests: timeout: null command: env: {} -``` \ No newline at end of file +``` diff --git a/docs/reference/module-types/helm.md b/docs/reference/module-types/helm.md index da4c29e0f8..6ceea9f3c8 100644 --- a/docs/reference/module-types/helm.md +++ b/docs/reference/module-types/helm.md @@ -5,11 +5,13 @@ Refer to the [Helm guide](https://docs.garden.io/using-garden/using-helm-charts) Below is the schema reference. For an introduction to configuring Garden modules, please look at our [Configuration guide](../../using-garden/configuration-files.md). -The reference is divided into two sections. The [first section](#configuration-keys) lists and describes the available +The [first section](#configuration-keys) lists and describes the available schema keys. The [second section](#complete-yaml-schema) contains the complete YAML schema. -## Configuration keys +`helm` modules also export values that are available via the `${modules..outputs}`. See the +[Outputs](#outputs) section below for details. +## Configuration keys ### `apiVersion` @@ -678,4 +680,18 @@ tests: env: {} version: values: {} -``` \ No newline at end of file +``` + +## Outputs + +The following keys are available via the `${modules..outputs}` template string key for `helm` +modules. + +### `modules..outputs.release-name` + +The Helm release name of the service. + +| Type | Required | +| ---- | -------- | +| `string` | Yes + diff --git a/docs/reference/module-types/kubernetes.md b/docs/reference/module-types/kubernetes.md index ae9c04210f..7095a949ca 100644 --- a/docs/reference/module-types/kubernetes.md +++ b/docs/reference/module-types/kubernetes.md @@ -13,12 +13,11 @@ If you need more advanced templating features you can use the Below is the schema reference. For an introduction to configuring Garden modules, please look at our [Configuration guide](../../using-garden/configuration-files.md). -The reference is divided into two sections. The [first section](#configuration-keys) lists and describes the available +The [first section](#configuration-keys) lists and describes the available schema keys. The [second section](#complete-yaml-schema) contains the complete YAML schema. ## Configuration keys - ### `apiVersion` The schema version of this module's config (currently not used). @@ -268,4 +267,4 @@ manifests: metadata: name: files: [] -``` \ No newline at end of file +``` diff --git a/docs/reference/module-types/maven-container.md b/docs/reference/module-types/maven-container.md index 4791a7fd1f..f2ded68871 100644 --- a/docs/reference/module-types/maven-container.md +++ b/docs/reference/module-types/maven-container.md @@ -15,11 +15,13 @@ The provider will automatically fetch and cache Maven and the appropriate OpenJD Below is the schema reference. For an introduction to configuring Garden modules, please look at our [Configuration guide](../../using-garden/configuration-files.md). -The reference is divided into two sections. The [first section](#configuration-keys) lists and describes the available +The [first section](#configuration-keys) lists and describes the available schema keys. The [second section](#complete-yaml-schema) contains the complete YAML schema. -## Configuration keys +`maven-container` modules also export values that are available via the `${modules..outputs}`. See the +[Outputs](#outputs) section below for details. +## Configuration keys ### `apiVersion` @@ -984,4 +986,26 @@ tasks: jarPath: jdkVersion: 8 mvnOpts: [] -``` \ No newline at end of file +``` + +## Outputs + +The following keys are available via the `${modules..outputs}` template string key for `maven-container` +modules. + +### `modules..outputs.local-image-name` + +The name of the image (without tag/version) that the module uses for local builds and deployments. + +| Type | Required | +| ---- | -------- | +| `string` | Yes + +### `modules..outputs.deployment-image-name` + +The name of the image (without tag/version) that the module will use during deployment. + +| Type | Required | +| ---- | -------- | +| `string` | Yes + diff --git a/docs/reference/module-types/openfaas.md b/docs/reference/module-types/openfaas.md index 14dea5dcba..5738e0f837 100644 --- a/docs/reference/module-types/openfaas.md +++ b/docs/reference/module-types/openfaas.md @@ -4,12 +4,11 @@ Below is the schema reference. For an introduction to configuring Garden modules, please look at our [Configuration guide](../../using-garden/configuration-files.md). -The reference is divided into two sections. The [first section](#configuration-keys) lists and describes the available +The [first section](#configuration-keys) lists and describes the available schema keys. The [second section](#complete-yaml-schema) contains the complete YAML schema. ## Configuration keys - ### `apiVersion` The schema version of this module's config (currently not used). @@ -190,4 +189,4 @@ build: copy: - source: target: '' -``` \ No newline at end of file +``` diff --git a/docs/reference/template-strings.md b/docs/reference/template-strings.md index 0dcb9ea305..0ebfb99d95 100644 --- a/docs/reference/template-strings.md +++ b/docs/reference/template-strings.md @@ -7,6 +7,10 @@ Note that there are three sections below, because Project configs and Module con them, and additional keys are available under `providers` in Project configs. Please make sure to refer to the correct section. +Modules are able to reference defined `outputs` from other modules, via the `${modules..outputs}` key. +For details on which outputs are available for a module type, please refer to the +[reference](https://docs.garden.io/reference/module-types) docs for the module type and look for the _Outputs_ section. + ## Project configuration context The following keys are available in template strings anywhere in Project `garden.yml` config files: diff --git a/garden-service/src/actions.ts b/garden-service/src/actions.ts index 7217d8a4dd..f2b0549090 100644 --- a/garden-service/src/actions.ts +++ b/garden-service/src/actions.ts @@ -261,6 +261,7 @@ export class ActionHelper implements TypeGuard { moduleType, defaultHandler: async ({ }) => ({ docs: "", + outputsSchema: Joi.object().options({ allowUnknown: true }), schema: Joi.object().options({ allowUnknown: true }), }), }) diff --git a/garden-service/src/config/config-context.ts b/garden-service/src/config/config-context.ts index 1ba09b6b85..0e90f93ab2 100644 --- a/garden-service/src/config/config-context.ts +++ b/garden-service/src/config/config-context.ts @@ -308,7 +308,10 @@ class ModuleContext extends ConfigContext { @schema( joiIdentifierMap(joiPrimitive()) - .description("The outputs defined by the module (see individual plugins for details).") + .description( + "The outputs defined by the module (see individual module type " + + "[references](https://docs.garden.io/reference/module-types) for details).", + ) .example(exampleOutputs), ) public outputs: PrimitiveMap diff --git a/garden-service/src/docs/config.ts b/garden-service/src/docs/config.ts index 3c7565acc5..3a410962d6 100644 --- a/garden-service/src/docs/config.ts +++ b/garden-service/src/docs/config.ts @@ -209,11 +209,12 @@ function getParentDescriptions( return descriptions } -function renderMarkdownTitle(description: NormalizedDescription) { +function renderMarkdownTitle(description: NormalizedDescription, prefix = "") { const parentDescriptions = getParentDescriptions(description) - return parentDescriptions.length > 0 + const title = parentDescriptions.length > 0 ? `${parentDescriptions.map(d => d.formattedName).join(".")}.${description.formattedName}` : description.name + return prefix + title } function renderMarkdownLink(description: NormalizedDescription) { @@ -221,9 +222,9 @@ function renderMarkdownLink(description: NormalizedDescription) { return `[${description.name}](#${path})` } -function makeMarkdownDescription(description: NormalizedDescription) { +function makeMarkdownDescription(description: NormalizedDescription, titlePrefix = "") { const parentDescriptions = getParentDescriptions(description) - const title = renderMarkdownTitle(description) + const title = renderMarkdownTitle(description, titlePrefix) const breadCrumbs = parentDescriptions.length > 0 ? parentDescriptions .map(renderMarkdownLink) @@ -359,12 +360,12 @@ export function renderSchemaDescriptionYaml( * The config reference contains a list of keys and their description in Markdown * and a YAML schema. */ -export function renderConfigReference(configSchema: Joi.ObjectSchema) { +export function renderConfigReference(configSchema: Joi.ObjectSchema, titlePrefix = "") { const partialTemplatePath = resolve(TEMPLATES_DIR, "config-partial.hbs") const normalizedDescriptions = normalizeDescriptions(configSchema.describe()) const yaml = renderSchemaDescriptionYaml(normalizedDescriptions, { showComment: false }) - const keys = normalizedDescriptions.map(makeMarkdownDescription) + const keys = normalizedDescriptions.map(d => makeMarkdownDescription(d, titlePrefix)) const template = handlebars.compile(readFileSync(partialTemplatePath).toString()) return { markdownReference: template({ keys }), yaml } @@ -385,11 +386,14 @@ function renderProviderReference(schema: Joi.ObjectSchema, name: string) { * Generates the module types reference from the module-type.hbs template. * The reference includes the rendered output from the config-partial.hbs template. */ -function renderModuleTypeReference(schema: Joi.ObjectSchema, name: string, docs: string) { +function renderModuleTypeReference( + schema: Joi.ObjectSchema, outputsSchema: Joi.ObjectSchema, name: string, docs: string, +) { const moduleTemplatePath = resolve(TEMPLATES_DIR, "module-type.hbs") const { markdownReference, yaml } = renderConfigReference(schema) + const outputsReference = renderConfigReference(outputsSchema, "modules..outputs.").markdownReference const template = handlebars.compile(readFileSync(moduleTemplatePath).toString()) - return template({ name, docs, markdownReference, yaml }) + return template({ name, docs, markdownReference, yaml, outputsReference }) } /** @@ -444,10 +448,15 @@ export async function writeConfigReferenceDocs(docsRoot: string) { for (const { name } of moduleTypes) { const path = resolve(moduleTypeDir, `${name}.md`) const actions = await garden.getActionHelper() - const { docs, schema, title } = await actions.describeType(name) + const { docs, outputsSchema, schema, title } = await actions.describeType(name) console.log("->", path) - writeFileSync(path, renderModuleTypeReference(populateModuleSchema(schema), name, docs)) + writeFileSync(path, renderModuleTypeReference( + populateModuleSchema(schema), + outputsSchema, + name, + docs, + )) readme.push(`* [${title || startCase(name.replace("-", " "))}](./${name}.md)`) } diff --git a/garden-service/src/docs/templates/module-type.hbs b/garden-service/src/docs/templates/module-type.hbs index fe1984b783..a427e86d5b 100644 --- a/garden-service/src/docs/templates/module-type.hbs +++ b/garden-service/src/docs/templates/module-type.hbs @@ -4,14 +4,26 @@ Below is the schema reference. For an introduction to configuring Garden modules, please look at our [Configuration guide](../../using-garden/configuration-files.md). -The reference is divided into two sections. The [first section](#configuration-keys) lists and describes the available +The [first section](#configuration-keys) lists and describes the available schema keys. The [second section](#complete-yaml-schema) contains the complete YAML schema. -## Configuration keys +{{#if outputsReference}} +`{{{name}}}` modules also export values that are available via the `${modules..outputs}`. See the +[Outputs](#outputs) section below for details. +{{/if}} +## Configuration keys {{{markdownReference}}} ## Complete YAML schema ```yaml {{{yaml}}} -``` \ No newline at end of file +``` +{{#if outputsReference}} + +## Outputs + +The following keys are available via the `${modules..outputs}` template string key for `{{{name}}}` +modules. +{{{outputsReference}}} +{{/if}} \ No newline at end of file diff --git a/garden-service/src/docs/templates/template-strings.hbs b/garden-service/src/docs/templates/template-strings.hbs index 3053fe29e1..8521e33d5a 100644 --- a/garden-service/src/docs/templates/template-strings.hbs +++ b/garden-service/src/docs/templates/template-strings.hbs @@ -7,6 +7,10 @@ Note that there are three sections below, because Project configs and Module con them, and additional keys are available under `providers` in Project configs. Please make sure to refer to the correct section. +Modules are able to reference defined `outputs` from other modules, via the `${modules..outputs}` key. +For details on which outputs are available for a module type, please refer to the +[reference](https://docs.garden.io/reference/module-types) docs for the module type and look for the _Outputs_ section. + ## Project configuration context The following keys are available in template strings anywhere in Project `garden.yml` config files: diff --git a/garden-service/src/plugins/container/container.ts b/garden-service/src/plugins/container/container.ts index f6e090dc78..233e686860 100644 --- a/garden-service/src/plugins/container/container.ts +++ b/garden-service/src/plugins/container/container.ts @@ -7,6 +7,7 @@ */ import dedent = require("dedent") +import * as Joi from "joi" import { keyBy } from "lodash" import { ConfigurationError } from "../../exceptions" @@ -19,6 +20,18 @@ import { ConfigureModuleParams } from "../../types/plugin/module/configure" import { PublishModuleParams } from "../../types/plugin/module/publishModule" import { HotReloadServiceParams } from "../../types/plugin/service/hotReloadService" +export const containerModuleOutputsSchema = Joi.object() + .keys({ + "local-image-name": Joi.string() + .required() + .description( + "The name of the image (without tag/version) that the module uses for local builds and deployments.", + ), + "deployment-image-name": Joi.string() + .required() + .description("The name of the image (without tag/version) that the module will use during deployment."), + }) + export async function configureContainerModule({ ctx, moduleConfig }: ConfigureModuleParams) { // validate hot reload configuration // TODO: validate this when validating this action's output @@ -121,6 +134,7 @@ export async function configureContainerModule({ ctx, moduleConfig }: ConfigureM ) moduleConfig.outputs = { + "local-image-name": await containerHelpers.getLocalImageName(moduleConfig), "deployment-image-name": deploymentImageName, } @@ -178,6 +192,7 @@ async function describeType() { other module types like [helm](https://docs.garden.io/reference/module-types/helm) or [kubernetes](https://github.com/garden-io/garden/blob/master/docs/reference/module-types/kubernetes.md). `, + outputsSchema: containerModuleOutputsSchema, schema: containerModuleSpecSchema, } } diff --git a/garden-service/src/plugins/container/helpers.ts b/garden-service/src/plugins/container/helpers.ts index 7d313d3b57..669496e70e 100644 --- a/garden-service/src/plugins/container/helpers.ts +++ b/garden-service/src/plugins/container/helpers.ts @@ -40,22 +40,29 @@ const helpers = { async getLocalImageId(module: ContainerModule): Promise { const hasDockerfile = await helpers.hasDockerfile(module) - if (module.spec.image && hasDockerfile) { - const { versionString } = module.version - const parsedImage = helpers.parseImageId(module.spec.image) - return helpers.unparseImageId({ ...parsedImage, tag: versionString }) - } else if (!module.spec.image && hasDockerfile) { - const { versionString } = module.version - return helpers.unparseImageId({ repository: module.name, tag: versionString }) - } else if (module.spec.image && !hasDockerfile) { + if (module.spec.image && !hasDockerfile) { return module.spec.image } else { const { versionString } = module.version - const parsedImage = helpers.parseImageId(module.name) + const name = await helpers.getLocalImageName(module) + const parsedImage = helpers.parseImageId(name) return helpers.unparseImageId({ ...parsedImage, tag: versionString }) } }, + /** + * Returns the image name used locally (without tag/version), when building and deploying to local environments + * (when we don't need to push to remote registries). + */ + async getLocalImageName(config: ContainerModuleConfig): Promise { + if (config.spec.image) { + const parsedImage = helpers.parseImageId(config.spec.image) + return helpers.unparseImageId({ ...parsedImage, tag: undefined }) + } else { + return config.name + } + }, + /** * Returns the image ID to be used for publishing to container registries * (not to be confused with the ID used when pushing to private deployment registries). diff --git a/garden-service/src/plugins/exec.ts b/garden-service/src/plugins/exec.ts index 29d21cfbf1..b5e795560a 100644 --- a/garden-service/src/plugins/exec.ts +++ b/garden-service/src/plugins/exec.ts @@ -230,6 +230,7 @@ async function describeType() { A simple module for executing commands in your shell. This can be a useful escape hatch if no other module type fits your needs, and you just need to execute something (as opposed to deploy it, track its status etc.). `, + outputsSchema: Joi.object().keys({}), schema: execModuleSpecSchema, } } diff --git a/garden-service/src/plugins/kubernetes/helm/handlers.ts b/garden-service/src/plugins/kubernetes/helm/handlers.ts index b3f24f7269..adb81fe077 100644 --- a/garden-service/src/plugins/kubernetes/helm/handlers.ts +++ b/garden-service/src/plugins/kubernetes/helm/handlers.ts @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +import * as Joi from "joi" import { ModuleAndRuntimeActions } from "../../../types/plugin/plugin" import { HelmModule, validateHelmModule as configureHelmModule, helmModuleSpecSchema } from "./config" import { buildHelmModule } from "./build" @@ -18,12 +19,20 @@ import { getServiceLogs } from "./logs" import { testHelmModule } from "./test" import { dedent } from "../../../util/string" +const helmModuleOutputsSchema = Joi.object() + .keys({ + "release-name": Joi.string() + .required() + .description("The Helm release name of the service."), + }) + async function describeType() { return { docs: dedent` Specify a Helm chart (either in your repository or remote from a registry) to deploy. Refer to the [Helm guide](https://docs.garden.io/using-garden/using-helm-charts) for usage instructions. `, + outputsSchema: helmModuleOutputsSchema, schema: helmModuleSpecSchema, } } diff --git a/garden-service/src/plugins/kubernetes/kubernetes-module/config.ts b/garden-service/src/plugins/kubernetes/kubernetes-module/config.ts index 1a247d5446..e55568e4be 100644 --- a/garden-service/src/plugins/kubernetes/kubernetes-module/config.ts +++ b/garden-service/src/plugins/kubernetes/kubernetes-module/config.ts @@ -79,6 +79,7 @@ export async function describeType() { If you need more advanced templating features you can use the [helm](https://docs.garden.io/reference/module-types/helm) module type. `, + outputsSchema: Joi.object().keys({}), schema: kubernetesModuleSpecSchema, } } diff --git a/garden-service/src/plugins/maven-container/maven-container.ts b/garden-service/src/plugins/maven-container/maven-container.ts index 3a8940656d..1b81dd4d1b 100644 --- a/garden-service/src/plugins/maven-container/maven-container.ts +++ b/garden-service/src/plugins/maven-container/maven-container.ts @@ -19,7 +19,11 @@ import { } from "../container/config" import { joiArray, joiProviderName } from "../../config/common" import { Module } from "../../types/module" -import { configureContainerModule, gardenPlugin as containerPlugin } from "../container/container" +import { + configureContainerModule, + gardenPlugin as containerPlugin, + containerModuleOutputsSchema, +} from "../container/container" import { buildContainerModule, getContainerBuildStatus } from "../container/build" import { resolve } from "path" import { RuntimeError, ConfigurationError } from "../../exceptions" @@ -109,6 +113,7 @@ async function describeType() { To use it, make sure to add the \`maven-container\` provider to your project configuration. The provider will automatically fetch and cache Maven and the appropriate OpenJDK version ahead of building. `, + outputsSchema: containerModuleOutputsSchema, schema: mavenContainerModuleSpecSchema, } } diff --git a/garden-service/src/plugins/openfaas/openfaas.ts b/garden-service/src/plugins/openfaas/openfaas.ts index deef938f62..2b31e18e0c 100644 --- a/garden-service/src/plugins/openfaas/openfaas.ts +++ b/garden-service/src/plugins/openfaas/openfaas.ts @@ -72,6 +72,14 @@ export const openfaasModuleSpecSchema = execModuleSpecSchema .unknown(false) .description("The module specification for an OpenFaaS module.") +export const openfaasModuleOutputsSchema = Joi.object() + .keys({ + endpoint: Joi.string() + .uri() + .required() + .description(`The full URL to query this service _from within_ the cluster.`), + }) + export interface OpenFaasModule extends Module { } export type OpenFaasModuleConfig = OpenFaasModule["_ConfigType"] export interface OpenFaasService extends Service { } @@ -104,6 +112,7 @@ async function describeType() { Deploy [OpenFaaS](https://www.openfaas.com/) functions using Garden. Requires either the \`kubernetes\` or \`local-kubernetes\` provider to be configured. Everything else is installed automatically. `, + outputsSchema: openfaasModuleOutputsSchema, schema: openfaasModuleSpecSchema, } } diff --git a/garden-service/src/types/plugin/module/describeType.ts b/garden-service/src/types/plugin/module/describeType.ts index 640931148c..6e1e254459 100644 --- a/garden-service/src/types/plugin/module/describeType.ts +++ b/garden-service/src/types/plugin/module/describeType.ts @@ -15,7 +15,8 @@ export const describeModuleTypeParamsSchema = Joi.object() export interface ModuleTypeDescription { docs: string - // TODO: specify the schema using primitives and not Joi objects + // TODO: specify the schemas using primitives (e.g. JSONSchema/OpenAPI) and not Joi objects + outputsSchema: Joi.ObjectSchema schema: Joi.ObjectSchema title?: string } @@ -43,6 +44,13 @@ export const describeType = { docs: Joi.string() .required() .description("Documentation for the module type, in markdown format."), + // TODO: specify the schemas using primitives and not Joi objects + outputsSchema: Joi.object() + .default(Joi.object().keys({}), "{}") + .description( + "A valid Joi schema describing the keys that each module outputs, for use in template strings " + + "(e.g. \`\${modules.my-module.outputs.some-key}\`).", + ), schema: Joi.object() .required() .description( diff --git a/garden-service/test/unit/src/actions.ts b/garden-service/test/unit/src/actions.ts index f813f699fb..d535f3b0a1 100644 --- a/garden-service/test/unit/src/actions.ts +++ b/garden-service/test/unit/src/actions.ts @@ -429,6 +429,7 @@ const testPlugin: PluginFactory = async () => ({ validate(params, moduleActionDescriptions.describeType.paramsSchema) return { docs: "bla bla bla", + outputsSchema: Joi.object(), schema: Joi.object(), title: "Bla", } diff --git a/garden-service/test/unit/src/plugins/container.ts b/garden-service/test/unit/src/plugins/container.ts index 292032bbc8..94849f329e 100644 --- a/garden-service/test/unit/src/plugins/container.ts +++ b/garden-service/test/unit/src/plugins/container.ts @@ -120,6 +120,23 @@ describe("plugins.container", () => { }) }) + describe("getLocalImageName", () => { + it("should return configured image name with no version if specified", async () => { + const config = cloneDeep(baseConfig) + config.spec.image = "some/image:1.1" + const module = await getTestModule(config) + + expect(await helpers.getLocalImageName(module)).to.equal("some/image") + }) + + it("should return module name if no image name is specified", async () => { + const config = cloneDeep(baseConfig) + const module = await getTestModule(config) + + expect(await helpers.getLocalImageName(module)).to.equal(config.name) + }) + }) + describe("getDeploymentImageId", () => { it("should return module name with module version if there is a Dockerfile and no image name set", async () => { const config = cloneDeep(baseConfig) @@ -437,6 +454,7 @@ describe("plugins.container", () => { apiVersion: "garden.io/v0", name: "module-a", outputs: { + "local-image-name": "module-a", "deployment-image-name": "module-a", }, path: modulePath,