Skip to content

Commit

Permalink
refactor: changed YAML spec to use lists instead of maps in most places
Browse files Browse the repository at this point in the history
See issue #94 for details and discussion
  • Loading branch information
edvald committed May 17, 2018
1 parent 5d7e064 commit f1d2548
Show file tree
Hide file tree
Showing 77 changed files with 566 additions and 484 deletions.
16 changes: 8 additions & 8 deletions examples/hello-world/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ project:
name: hello-world
global:
providers:
container: {}
npm-package: {}
- name: container
- name: npm-package
variables:
my-variable: hello-variable
environments:
local:
- name: local
providers:
local-kubernetes:
- name: local-kubernetes
context: docker-for-desktop
local-google-cloud-functions: {}
dev:
- name: local-google-cloud-functions
- name: dev
providers:
google-app-engine: {}
google-cloud-functions:
- name: google-app-engine
- name: google-cloud-functions
default-project: garden-hello-world
8 changes: 4 additions & 4 deletions examples/hello-world/services/hello-container/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module:
description: Hello world container service
type: container
services:
hello-container:
- name: hello-container
command: [npm, start]
ports:
http:
- name: http
containerPort: 8080
endpoints:
- paths: [/hello]
Expand All @@ -20,9 +20,9 @@ module:
dependencies:
- hello-npm-package
test:
unit:
- name: unit
command: [npm, test]
integ:
- name: integ
command: [npm, run, integ]
dependencies:
- hello-function
4 changes: 2 additions & 2 deletions examples/hello-world/services/hello-function/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module:
name: hello-function
type: google-cloud-function
services:
hello-function:
- name: hello-function
entrypoint: helloFunction
test:
unit:
- name: unit
command: [npm, test]
build:
dependencies:
Expand Down
7 changes: 5 additions & 2 deletions examples/multi-container/garden.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
project:
name: multi-container
environments:
dev:
- name: local
providers:
kubernetes:
- name: local-kubernetes
- name: dev
providers:
- name: kubernetes
context: my-dev-context
2 changes: 1 addition & 1 deletion examples/multi-container/services/jworker/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module:
description: worker
type: container
services:
javaworker:
- name: javaworker
dependencies:
- redis
4 changes: 2 additions & 2 deletions examples/multi-container/services/postgres/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module:
type: container
image: postgres:9.4
services:
db:
- name: db
volumes:
- name: data
containerPath: /db-data
ports:
db:
- name: db
containerPort: 5432
4 changes: 2 additions & 2 deletions examples/multi-container/services/redis/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module:
type: container
image: redis:alpine
services:
redis:
- name: redis
ports:
redis:
- name: redis
protocol: TCP
containerPort: 6379
4 changes: 2 additions & 2 deletions examples/multi-container/services/result/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module:
description: Results presentation service
type: container
services:
result:
- name: result
command: [nodemon, server.js]
endpoints:
- paths: [/]
port: ui
ports:
ui:
- name: ui
protocol: TCP
containerPort: 80
4 changes: 2 additions & 2 deletions examples/multi-container/services/vote/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module:
description: voting service
type: container
services:
vote:
- name: vote
command: [python, app.py]
endpoints:
- paths: [/vote/]
port: interface
ports:
interface:
- name: interface
protocol: TCP
containerPort: 80
dependencies:
Expand Down
6 changes: 3 additions & 3 deletions garden.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project:
name: garden-framework
environments:
local:
- name: local
providers:
container: {}
local-kubernetes: {}
- name: container
- name: local-kubernetes
2 changes: 1 addition & 1 deletion gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ gulp.task("add-version-files", (cb) => {
proc.on("close", () => {
const results = JSON.parse(output)

for (const module of <any>Object.values(results.result)) {
for (const module of <any>results.result) {
const relPath = relative(__dirname, module.path)
const versionFilePath = join(__dirname, destDir, relPath, ".garden-version")
writeFileSync(versionFilePath, JSON.stringify(module.version))
Expand Down
3 changes: 1 addition & 2 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { PluginContext } from "../plugin-context"
import { BooleanParameter, Command, ParameterValues, StringParameter } from "./base"
import { BuildTask } from "../tasks/build"
import { values } from "lodash"
import { TaskResults } from "../task-graph"

export const buildArguments = {
Expand All @@ -36,7 +35,7 @@ export class BuildCommand extends Command<typeof buildArguments, typeof buildOpt
async action(ctx: PluginContext, args: BuildArguments, opts: BuildOptions): Promise<TaskResults> {
await ctx.clearBuilds()
const names = args.module ? args.module.split(",") : undefined
const modules = values(await ctx.getModules(names))
const modules = await ctx.getModules(names)

ctx.log.header({ emoji: "hammer", command: "build" })

Expand Down
7 changes: 3 additions & 4 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { PluginContext } from "../plugin-context"
import { DeployTask } from "../tasks/deploy"
import { BooleanParameter, Command, ParameterValues, StringParameter } from "./base"
import { TaskResults } from "../task-graph"
import { values } from "lodash"

export const deployArgs = {
service: new StringParameter({
Expand Down Expand Up @@ -39,7 +38,7 @@ export class DeployCommand extends Command<typeof deployArgs, typeof deployOpts>
const names = args.service ? args.service.split(",") : undefined
const services = await ctx.getServices(names)

if (Object.keys(services).length === 0) {
if (services.length === 0) {
ctx.log.warn({ msg: "No services found. Aborting." })
return {}
}
Expand All @@ -53,10 +52,10 @@ export class DeployCommand extends Command<typeof deployArgs, typeof deployOpts>
const force = opts.force
const forceBuild = opts["force-build"]

const modules = Array.from(new Set(values(services).map(s => s.module)))
const modules = Array.from(new Set(services.map(s => s.module)))

const result = await ctx.processModules(modules, watch, async (module) => {
const servicesToDeploy = values(await module.getServices()).filter(s => !!services[s.name])
const servicesToDeploy = await module.getServices()
for (const service of servicesToDeploy) {
await ctx.addTask(new DeployTask(ctx, service, force, forceBuild))
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { STATIC_DIR } from "../constants"
import { spawnSync } from "child_process"
import chalk from "chalk"
import Bluebird = require("bluebird")
import { values } from "lodash"
import moment = require("moment")

const imgcatPath = join(STATIC_DIR, "imgcat")
Expand All @@ -38,7 +37,7 @@ export class DevCommand extends Command {

await ctx.configureEnvironment()

const modules = values(await ctx.getModules())
const modules = await ctx.getModules()

if (modules.length === 0) {
if (modules.length === 0) {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { BooleanParameter, Command, ParameterValues, StringParameter } from "./b
import chalk from "chalk"
import { ServiceLogEntry } from "../types/plugin"
import Bluebird = require("bluebird")
import { values } from "lodash"
import { Service } from "../types/service"
import Stream from "ts-stream"

Expand Down Expand Up @@ -53,7 +52,7 @@ export class LogsCommand extends Command<typeof logsArgs, typeof logsOpts> {

// NOTE: This will work differently when we have Elasticsearch set up for logging, but is
// quite servicable for now.
await Bluebird.map(values(services), async (service: Service<any>) => {
await Bluebird.map(services, async (service: Service<any>) => {
await ctx.getServiceLogs(service, stream, opts.tail)
})

Expand Down
3 changes: 1 addition & 2 deletions src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import chalk from "chalk"
import { values } from "lodash"
import { BooleanParameter, Command, ParameterValues, StringParameter } from "./base"
import { PluginContext } from "../plugin-context"
import { Module } from "../types/module"
Expand Down Expand Up @@ -47,7 +46,7 @@ export class PushCommand extends Command<typeof pushArgs, typeof pushOpts> {
const names = args.module ? args.module.split(",") : undefined
const modules = await ctx.getModules(names)

const result = await pushModules(ctx, values(modules), !!opts["force-build"], !!opts["allow-dirty"])
const result = await pushModules(ctx, modules, !!opts["force-build"], !!opts["allow-dirty"])

ctx.log.info({ msg: "" })
ctx.log.info({ emoji: "heavy_check_mark", msg: chalk.green("Done!\n") })
Expand Down
5 changes: 2 additions & 3 deletions src/commands/run/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { RunResult } from "../../types/plugin"
import { BooleanParameter, Command, ParameterValues, StringParameter } from "../base"
import {
uniq,
values,
flatten,
} from "lodash"
import { printRuntimeContext } from "./index"
Expand Down Expand Up @@ -72,9 +71,9 @@ export class RunModuleCommand extends Command<typeof runArgs, typeof runOpts> {
const command = args.command ? args.command.split(" ") : []

// combine all dependencies for all services in the module, to be sure we have all the context we need
const services = values(await module.getServices())
const services = await module.getServices()
const depNames = uniq(flatten(services.map(s => s.config.dependencies)))
const deps = values(await ctx.getServices(depNames))
const deps = await ctx.getServices(depNames)

const runtimeContext = await module.prepareRuntimeContext(deps)

Expand Down
13 changes: 8 additions & 5 deletions src/commands/run/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import { ParameterError } from "../../exceptions"
import { PluginContext } from "../../plugin-context"
import { BuildTask } from "../../tasks/build"
import { RunResult } from "../../types/plugin"
import {
findByName,
getNames,
} from "../../util"
import { BooleanParameter, Command, ParameterValues, StringParameter } from "../base"
import { values } from "lodash"
import { printRuntimeContext } from "./index"

export const runArgs = {
Expand Down Expand Up @@ -51,13 +54,13 @@ export class RunTestCommand extends Command<typeof runArgs, typeof runOpts> {
const module = await ctx.getModule(moduleName)
const config = await module.getConfig()

const testSpec = config.test[testName]
const testSpec = findByName(config.test, testName)

if (!testSpec) {
throw new ParameterError(`Could not find test "${testName}" in module ${moduleName}`, {
moduleName,
testName,
availableTests: Object.keys(config.test),
availableTests: getNames(config.test),
})
}

Expand All @@ -74,10 +77,10 @@ export class RunTestCommand extends Command<typeof runArgs, typeof runOpts> {

const interactive = opts.interactive
const deps = await ctx.getServices(testSpec.dependencies)
const runtimeContext = await module.prepareRuntimeContext(values(deps))
const runtimeContext = await module.prepareRuntimeContext(deps)

printRuntimeContext(ctx, runtimeContext)

return ctx.testModule({ module, interactive, runtimeContext, silent: false, testName, testSpec })
return ctx.testModule({ module, interactive, runtimeContext, silent: false, testSpec })
}
}
15 changes: 8 additions & 7 deletions src/commands/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import { safeDump } from "js-yaml"
import { PluginContext } from "../plugin-context"
import { DeepPrimitiveMap } from "../types/common"
import { highlightYaml } from "../util"
import { Command } from "./base"
import Bluebird = require("bluebird")
import {
mapValues,
omit,
} from "lodash"

Expand All @@ -23,21 +23,22 @@ export class ScanCommand extends Command {
async action(ctx: PluginContext) {
const modules = await ctx.getModules()

const output = await Bluebird.props(mapValues(modules, async (m) => {
const output = await Bluebird.map(modules, async (m) => {
const config = await m.getConfig()
return {
name: m.name,
type: m.type,
path: m.path,
description: m.config.description,
description: config.description,
version: await m.getVersion(),
config: m.config,
config,
}
}))
})

const shortOutput = mapValues(output, m => omit(m, ["config"]))
const shortOutput = output.map(m => omit(m, ["config"]))

ctx.log.info(highlightYaml(safeDump(shortOutput, { noRefs: true, skipInvalid: true })))

return output
return <DeepPrimitiveMap><any>output
}
}
2 changes: 1 addition & 1 deletion src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class TestCommand extends Command<typeof testArgs, typeof testOpts> {

async action(ctx: PluginContext, args: Args, opts: Opts): Promise<TaskResults> {
const names = args.module ? args.module.split(",") : undefined
const modules = values(await ctx.getModules(names))
const modules = await ctx.getModules(names)

ctx.log.header({
emoji: "thermometer",
Expand Down
Loading

0 comments on commit f1d2548

Please sign in to comment.