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

feat: user no longer needs to run env config command #80

Merged
merged 1 commit into from
Apr 22, 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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class DeployCommand extends Command<typeof deployArgs, typeof deployOpts>

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,
Expand Down
10 changes: 9 additions & 1 deletion src/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/google/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. " +
Expand Down
9 changes: 1 addition & 8 deletions src/plugins/kubernetes/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 13 additions & 12 deletions src/plugins/kubernetes/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
11 changes: 5 additions & 6 deletions src/plugins/local/local-docker-swarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ContainerModule>): Promise<ServiceStatus> {
Expand Down
9 changes: 1 addition & 8 deletions src/plugins/local/local-google-cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down