Skip to content

Commit

Permalink
refactor(config): make module name mandatory
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Module name no longer defaults to directory name but must be explicitly
set in the module's garden.yml file. Any existing garden.yml module files
without a name key must therefore be updated to expclitily provide the
module name.
  • Loading branch information
eysi09 committed Aug 10, 2018
1 parent c3029b1 commit aa83d7f
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module:
description: Hello world npm package
type: npm-package
name: hello-npm-package
1 change: 1 addition & 0 deletions examples/hello-world/services/hello-container/garden.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module:
description: Hello world container service
type: container
name: hello-container
services:
- name: hello-container
command: [npm, start]
Expand Down
1 change: 1 addition & 0 deletions examples/multi-container/services/jworker/garden.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module:
description: worker
type: container
name: jworker
services:
- name: javaworker
dependencies:
Expand Down
1 change: 1 addition & 0 deletions examples/multi-container/services/postgres/garden.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module:
description: postgres container
type: container
name: postgres
image: postgres:9.4
services:
- name: db
Expand Down
1 change: 1 addition & 0 deletions examples/multi-container/services/redis/garden.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module:
description: redis service
type: container
name: redis
image: redis:alpine
services:
- name: redis
Expand Down
1 change: 1 addition & 0 deletions examples/multi-container/services/result/garden.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module:
description: Results presentation service
type: container
name: result
services:
- name: result
command: [nodemon, server.js]
Expand Down
1 change: 1 addition & 0 deletions examples/multi-container/services/vote/garden.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module:
description: voting service
type: container
name: vote
services:
- name: vote
command: [python, app.py]
Expand Down
17 changes: 3 additions & 14 deletions garden-cli/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { join, parse, relative, sep } from "path"
import { join, relative, basename } from "path"
import {
findByName,
getNames,
} from "../util/util"
import { baseModuleSpecSchema, ModuleConfig } from "./module"
import { joiIdentifier, validate } from "./common"
import { validate } from "./common"
import { ConfigurationError } from "../exceptions"
import * as Joi from "joi"
import * as yaml from "js-yaml"
Expand Down Expand Up @@ -82,7 +82,7 @@ export async function loadConfig(projectRoot: string, path: string): Promise<Gar

const parsed = <GardenConfig>validate(spec, configSchema, { context: relative(projectRoot, absPath) })

const dirname = parse(absPath).dir.split(sep).slice(-1)[0]
const dirname = basename(path)
const project = parsed.project
let module = parsed.module

Expand Down Expand Up @@ -122,17 +122,6 @@ export async function loadConfig(projectRoot: string, path: string): Promise<Gar
variables: module.variables,
}

if (!module.name) {
try {
module.name = validate(dirname, joiIdentifier())
} catch (_) {
throw new ConfigurationError(
`Directory name ${parsed.dirname} is not a valid module name (must be valid identifier). ` +
`Please rename the directory or specify a module name in the garden.yml file.`,
{ dirname: parsed.dirname },
)
}
}
}

return {
Expand Down
5 changes: 3 additions & 2 deletions garden-cli/src/types/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export const baseModuleSpecSchema = Joi.object()
.description("The type of this module.")
.example("container"),
name: joiIdentifier()
.default(() => null, "<name of module directory>"),
.required()
.description("The name of this module.")
.example("my-sweet-module"),
description: Joi.string(),
variables: joiVariables()
.description("Variables that this module can reference and expose as environment variables.")
Expand Down Expand Up @@ -206,7 +208,6 @@ export class Module<
async getVersion(force?: boolean) {
return this.ctx.getModuleVersion(this.name, force)
}

async getBuildPath() {
return await this.ctx.getModuleBuildPath(this.name)
}
Expand Down
1 change: 1 addition & 0 deletions garden-cli/static/local-gcf-container/garden.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module:
description: Base container for running Google Cloud Functions emulator
type: container
name: local-gcf-container
1 change: 1 addition & 0 deletions garden-cli/static/openfaas/openfaas-builder/garden.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module:
description: Base image used for building openfaas modules
name: openfaas-builder
type: generic
build:
command: [./bootstrap.sh]
Expand Down

0 comments on commit aa83d7f

Please sign in to comment.