Skip to content

Commit

Permalink
feat: add with-dependants deploy command flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Orzelius committed Jul 11, 2023
1 parent 06d967d commit c34851e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
21 changes: 19 additions & 2 deletions core/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { LogMonitor } from "../monitors/logs"
import { LoggerType, parseLogLevel } from "../logger/logger"
import { serveOpts } from "./serve"
import { gardenEnv } from "../constants"
import { DeployAction } from "../actions/deploy"

export const deployArgs = {
names: new StringsParameter({
Expand Down Expand Up @@ -92,6 +93,12 @@ export const deployOpts = {
`,
aliases: ["nodeps"],
}),
"with-dependants": new BooleanParameter({
help: deline`
Additionally deploy all deploy actions that are downstream dependants of the action(s) being deployed.
This can be useful when you know you need to redeploy dependants.
`,
}),
"disable-port-forwards": new BooleanParameter({
help: "Disable automatic port forwarding when running persistently. Note that you can also set GARDEN_DISABLE_PORT_FORWARDS=true in your environment.",
}),
Expand Down Expand Up @@ -208,6 +215,18 @@ export class DeployCommand extends Command<Args, Opts> {
log.info(chalk.gray(msg))
}

const skipRuntimeDependencies = opts["skip-dependencies"]
const withDependants = opts["with-dependants"]
if (withDependants && args.names && args.names.length > 0) {
const result = graph.getDependantsForMany({
kind: "Deploy",
names: deployActions.map((a) => a.name),
recursive: true,
filter: (a) => a.kind === "Deploy",
}) as DeployAction[]
deployActions.push(...result)
}

const skipped = opts.skip || []

deployActions = deployActions.filter((s) => !s.isDisabled() && !skipped.includes(s.name))
Expand All @@ -217,8 +236,6 @@ export class DeployCommand extends Command<Args, Opts> {
return { result: { aborted: true, success: true, ...emptyActionResults } }
}

const skipRuntimeDependencies = opts["skip-dependencies"]

const force = opts.force
const startSync = !!opts.sync

Expand Down
71 changes: 71 additions & 0 deletions core/test/unit/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const defaultDeployOpts = withDefaultGlobalOpts({
"port": defaultServerPort,
"cmd": undefined,
"disable-port-forwards": false,
"with-dependants": false,
})

describe("DeployCommand", () => {
Expand Down Expand Up @@ -258,6 +259,76 @@ describe("DeployCommand", () => {
})
})

context("when --with-dependants is passed", () => {
it("should deploy dependant deploys", async () => {
const garden = await makeTestGarden(projectRootA, { plugins: [testProvider()] })
const log = garden.log

const { result, errors } = await command.action({
garden,
log,
args: {
names: ["service-a"],
},
opts: {
...defaultDeployOpts,
"with-dependants": true,
},
})

if (errors) {
throw errors[0]
}

const keys = getAllProcessedTaskNames(result!.graphResults)

// c has nothing to do with service-a
expect(keys).to.not.include("deploy.service-c")
// b is a dependant
expect(keys).to.include("deploy.service-b")
})

it("should have no effect if no names are passed", async () => {
const garden = await makeTestGarden(projectRootA, { plugins: [testProvider()] })
const log = garden.log

const { result: resultWith, errors: errors1 } = await command.action({
garden,
log,
args: {
names: [],
},
opts: {
...defaultDeployOpts,
"with-dependants": true,
},
})
if (errors1) {
throw errors1[0]
}

const { result: resultWithout, errors: errors2 } = await command.action({
garden,
log,
args: {
names: [],
},
opts: {
...defaultDeployOpts,
"with-dependants": true,
},
})
if (errors2) {
throw errors2[0]
}

const keysWith = getAllProcessedTaskNames(resultWith!.graphResults)
const keysWithout = getAllProcessedTaskNames(resultWithout!.graphResults)

expect(keysWith).to.eql(keysWithout)
})
})

it("should be protected", async () => {
expect(command.protected).to.be.true
})
Expand Down
1 change: 1 addition & 0 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ the command stays running until explicitly aborted.
This always takes the precedence over sync mode if there are any conflicts, i.e. if the same Deploys are matched with both &#x60;--sync&#x60; and &#x60;--local&#x60; options.
| `--skip` | | array:string | The name(s) of Deploys you&#x27;d like to skip.
| `--skip-dependencies` | | boolean | Skip deploy, test and run dependencies. Build dependencies and runtime output reference dependencies are not skipped. This can be useful e.g. when your stack has already been deployed, and you want to run specific Deploys in sync mode without deploying or running dependencies that may have changed since you last deployed.
| `--with-dependants` | | boolean | Additionally deploy all deploy actions that are downstream dependants of the action(s) being deployed. This can be useful when you know you need to redeploy dependants.
| `--disable-port-forwards` | | boolean | Disable automatic port forwarding when running persistently. Note that you can also set GARDEN_DISABLE_PORT_FORWARDS&#x3D;true in your environment.
| `--forward` | | boolean | Create port forwards and leave process running after deploying. This is implied if any of --sync / --local or --logs are set.
| `--logs` | | boolean | Stream logs from the requested Deploy(s) (or services if using modules) during deployment, and leave the log streaming process running after deploying. Note: This option implies the --forward option.
Expand Down

0 comments on commit c34851e

Please sign in to comment.