Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin refactor pt2 #71

Merged
merged 8 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"check-coverage": true,
"per-file": true,
"lines": 0,
"statements": 0,
"functions": 0,
"branches": 0,
"reporter": [
"html",
"text"
Expand Down
20 changes: 10 additions & 10 deletions examples/hello-world/garden.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
project:
name: hello-world
global:
providers:
container: {}
npm-package: {}
variables:
my-variable: hello-variable
environments:
local:
providers:
docker:
type: kubernetes
kubernetes:
context: docker-for-desktop
gcf:
type: local-google-cloud-functions
local-google-cloud-functions: {}
dev:
providers:
docker:
type: google-app-engine
gcf:
type: google-cloud-functions
google-app-engine: {}
google-cloud-functions:
default-project: garden-hello-world
variables:
my-variable: hello-variable
3 changes: 1 addition & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { BuildCommand } from "./commands/build"
import { EnvironmentCommand } from "./commands/environment/index"
import { DeployCommand } from "./commands/deploy"
import { CallCommand } from "./commands/call"
import { defaultPlugins } from "./plugins"
import { TestCommand } from "./commands/test"
import { DevCommand } from "./commands/dev"
import { LogsCommand } from "./commands/logs"
Expand Down Expand Up @@ -282,7 +281,7 @@ export class GardenCli {
)
}

const garden = await Garden.factory(root, { env, logger, plugins: defaultPlugins })
const garden = await Garden.factory(root, { env, logger })
return command.action(garden.pluginContext, argsForAction, optsForAction)
}

Expand Down
24 changes: 5 additions & 19 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

import { PluginContext } from "../plugin-context"
import { BooleanParameter, Command, ParameterValues, StringParameter } from "./base"
import { DeployTask } from "../tasks/deploy"
import { values } from "lodash"
import { Service } from "../types/service"
import chalk from "chalk"
import { TaskResults } from "../task-graph"

Expand Down Expand Up @@ -40,27 +37,16 @@ export class DeployCommand extends Command<typeof deployArgs, typeof deployOpts>
ctx.log.header({ emoji: "rocket", command: "Deploy" })

const names = args.service ? args.service.split(",") : undefined
const services = await ctx.getServices(names)

const result = await deployServices(ctx, values(services), !!opts.force, !!opts["force-build"])
const result = await ctx.deployServices({
names,
force: !!opts.force,
forceBuild: !!opts["force-build"],
})

ctx.log.info("")
ctx.log.info({ emoji: "heavy_check_mark", msg: chalk.green("Done!\n") })

return result
}
}

export async function deployServices(
ctx: PluginContext,
services: Service<any>[],
force: boolean,
forceBuild: boolean,
) {
for (const service of services) {
const task = new DeployTask(ctx, service, force, forceBuild)
await ctx.addTask(task)
}

return await ctx.processTasks()
}
7 changes: 1 addition & 6 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { join } from "path"
import { STATIC_DIR } from "../constants"
import { spawnSync } from "child_process"
import chalk from "chalk"
import { deployServices } from "./deploy"
import { values } from "lodash"
import { sleep } from "../util"

const imgcatPath = join(__dirname, "..", "..", "bin", "imgcat")
Expand All @@ -37,10 +35,7 @@ export class DevCommand extends Command {
console.log(chalk.gray.italic(` Good afternoon, Jon! Let's get your environment wired up...\n`))

await ctx.configureEnvironment()

const services = values(await ctx.getServices())

await deployServices(ctx, services, false, false)
await ctx.deployServices({})

ctx.log.info({ msg: "" })
const watchEntry = ctx.log.info({ emoji: "koala", msg: `Waiting for code changes...` })
Expand Down
23 changes: 5 additions & 18 deletions src/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import Bluebird = require("bluebird")
import { mapValues } from "lodash"
import * as yaml from "js-yaml"
import { PluginContext } from "../plugin-context"
import {
EnvironmentStatusMap,
} from "../types/plugin"
ContextStatus,
PluginContext,
} from "../plugin-context"
import { Command } from "./base"
import { Service } from "../types/service"
import { highlightYaml } from "../util"

export class StatusCommand extends Command {
name = "status"
alias = "s"
help = "Outputs the status of your environment"

async action(ctx: PluginContext) {
const envStatus: EnvironmentStatusMap = await ctx.getEnvironmentStatus()
const services = await ctx.getServices()

const serviceStatus = await Bluebird.props(
mapValues(services, (service: Service<any>) => ctx.getServiceStatus(service)),
)

const status = {
providers: envStatus,
services: serviceStatus,
}
async action(ctx: PluginContext): Promise<ContextStatus> {
const status = await ctx.getStatus()
const yamlStatus = yaml.safeDump(status, { noRefs: true, skipInvalid: true })

// TODO: do a nicer print of this by default and add --yaml/--json options (maybe globally) for exporting
Expand Down
Loading