diff --git a/README.md b/README.md index 68c0cfe3a8..8a8526660c 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,6 @@ it's pretty straightforward, promise :) To spin it up, `cd` to any of the directories under `examples/` and run: - garden env configure garden deploy If you've deployed the `hello-world` project, you can try querying the `/hello` endpoint: diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index 0d868e053d..9fda175525 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -38,6 +38,9 @@ export class DeployCommand extends Command const names = args.service ? args.service.split(",") : undefined + // TODO: make this a task + await ctx.configureEnvironment() + const result = await ctx.deployServices({ names, force: !!opts.force, diff --git a/src/plugin-context.ts b/src/plugin-context.ts index bbfdb8ebd5..b92e36c9b6 100644 --- a/src/plugin-context.ts +++ b/src/plugin-context.ts @@ -197,14 +197,22 @@ export function createPluginContext(garden: Garden): PluginContext { const handlers = garden.getActionHandlers("configureEnvironment") const env = garden.getEnvironment() + const statuses = await ctx.getEnvironmentStatus() + await Bluebird.each(toPairs(handlers), async ([name, handler]) => { + const status = statuses[name] || { configured: false } + + if (status.configured) { + return + } + const logEntry = garden.log.info({ entryStyle: EntryStyle.activity, section: name, msg: "Configuring...", }) - await handler({ ...commonParams(handler), env, logEntry }) + await handler({ ...commonParams(handler), status, env, logEntry }) logEntry.setSuccess("Configured") }) diff --git a/src/plugins/google/common.ts b/src/plugins/google/common.ts index c564c5ef84..a58f54cfe5 100644 --- a/src/plugins/google/common.ts +++ b/src/plugins/google/common.ts @@ -56,9 +56,7 @@ export async function getEnvironmentStatus() { return output } -export async function configureEnvironment({ ctx }: ConfigureEnvironmentParams) { - const status = await getEnvironmentStatus() - +export async function configureEnvironment({ ctx, status }: ConfigureEnvironmentParams) { if (!status.detail.sdkInstalled) { throw new ConfigurationError( "Google Cloud SDK is not installed. " + diff --git a/src/plugins/kubernetes/actions.ts b/src/plugins/kubernetes/actions.ts index 91ebb2fadf..2c9f20a126 100644 --- a/src/plugins/kubernetes/actions.ts +++ b/src/plugins/kubernetes/actions.ts @@ -87,15 +87,8 @@ export async function getEnvironmentStatus({ ctx, provider }: GetEnvironmentStat } export async function configureEnvironment( - { ctx, provider, env, logEntry }: ConfigureEnvironmentParams, + { ctx, provider, status, logEntry }: ConfigureEnvironmentParams, ) { - // TODO: use Helm 3 when it's released instead of this custom/manual stuff - const status = await getEnvironmentStatus({ ctx, provider, env, logEntry }) - - if (status.configured) { - return - } - const context = provider.config.context if (!status.detail.namespaceReady) { diff --git a/src/plugins/kubernetes/local.ts b/src/plugins/kubernetes/local.ts index 0539ebaa70..80a78b70c1 100644 --- a/src/plugins/kubernetes/local.ts +++ b/src/plugins/kubernetes/local.ts @@ -47,25 +47,26 @@ export async function getLocalEnvironmentStatus( } async function configureLocalEnvironment( - { ctx, provider, env, logEntry }: ConfigureEnvironmentParams, + { ctx, provider, env, status, logEntry }: ConfigureEnvironmentParams, ) { - const status = await getLocalEnvironmentStatus({ ctx, provider, env, logEntry }) - - if (status.configured) { - return - } - - await configureEnvironment({ ctx, provider, env, logEntry }) + await configureEnvironment({ ctx, provider, env, status, logEntry }) if (!isSystemGarden(provider)) { const sysGarden = await getSystemGarden(provider) + const sysProvider = { + name: provider.name, + config: sysGarden.config.providers[provider.name], + } + const sysStatus = await getEnvironmentStatus({ + ctx: sysGarden.pluginContext, + provider: sysProvider, + env, + }) await configureEnvironment({ ctx: sysGarden.pluginContext, env: sysGarden.getEnvironment(), - provider: { - name: provider.name, - config: sysGarden.config.providers[provider.name], - }, + provider: sysProvider, + status: sysStatus, logEntry, }) await sysGarden.pluginContext.deployServices({ logEntry }) diff --git a/src/plugins/local/local-docker-swarm.ts b/src/plugins/local/local-docker-swarm.ts index 0e9b89e7ee..bdcbac9642 100644 --- a/src/plugins/local/local-docker-swarm.ts +++ b/src/plugins/local/local-docker-swarm.ts @@ -11,8 +11,11 @@ import { exec } from "child-process-promise" import { DeploymentError } from "../../exceptions" import { PluginContext } from "../../plugin-context" import { - DeployServiceParams, ExecInServiceParams, GetServiceOutputsParams, GetServiceStatusParams, + ExecInServiceParams, + GetServiceOutputsParams, + GetServiceStatusParams, GardenPlugin, + DeployServiceParams, } from "../../types/plugin" import { ContainerModule } from "../container" import { @@ -230,11 +233,7 @@ async function getEnvironmentStatus() { } async function configureEnvironment() { - const status = await getEnvironmentStatus() - - if (!status.configured) { - await getDocker().swarmInit({}) - } + await getDocker().swarmInit({}) } async function getServiceStatus({ ctx, service }: GetServiceStatusParams): Promise { diff --git a/src/plugins/local/local-google-cloud-functions.ts b/src/plugins/local/local-google-cloud-functions.ts index 820e84cb17..2027d27ffd 100644 --- a/src/plugins/local/local-google-cloud-functions.ts +++ b/src/plugins/local/local-google-cloud-functions.ts @@ -106,14 +106,7 @@ async function getEnvironmentStatus({ ctx }: GetEnvironmentStatusParams) { return { configured: status.state === "ready" } } -async function configureEnvironment({ ctx, provider, env, logEntry }: ConfigureEnvironmentParams) { - const status = await getEnvironmentStatus({ ctx, provider, env }) - - // TODO: This check should happen ahead of calling this handler - if (status.configured) { - return - } - +async function configureEnvironment({ ctx, logEntry }: ConfigureEnvironmentParams) { const service = await getEmulatorService(ctx) // We mount the project root into the container, so we can exec deploy any function in there later. diff --git a/src/types/plugin.ts b/src/types/plugin.ts index 93efd4de13..ed047c41f3 100644 --- a/src/types/plugin.ts +++ b/src/types/plugin.ts @@ -45,7 +45,8 @@ export interface GetEnvironmentStatusParams extends PluginActionParamsBase { } export interface ConfigureEnvironmentParams extends PluginActionParamsBase { - env: Environment, + env: Environment + status: EnvironmentStatus } export interface DestroyEnvironmentParams extends PluginActionParamsBase {