Skip to content

Commit

Permalink
feat: add several update-related commands (like rollback), refactor u…
Browse files Browse the repository at this point in the history
…pdate submodule
  • Loading branch information
mvayngrib committed Aug 3, 2018
1 parent 56371e7 commit 929a870
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 83 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"eslint": "^3.15.0",
"eslint-plugin-json": "^1.2.0",
"inquirer": "^5.1.0",
"lexicographic-semver": "^1.0.0",
"listr": "^0.13.0",
"lodash": "^4.17.4",
"marked": "^0.3.9",
Expand Down
24 changes: 22 additions & 2 deletions src/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const run = async (fn) => {
;(matchedCommand || program).outputHelp()
}

process.exit()
return
}

Expand Down Expand Up @@ -290,22 +291,41 @@ const balanceCommand = program
.allowUnknownOption(false)
.action(createAction('balance'))

const versionCommand = program
.command('get-current-version')
.description(`check your current MyCloud version`)
.allowUnknownOption(false)
.action(createAction('getCurrentVersion'))

const listPreviousVersionsCommand = program
.command('list-previous-versions')
.description('list previous versions of your MyCloud deployment')
.allowUnknownOption(false)
.action(createAction('listPreviousVersions'))

const updateCommand = program
.command('update')
.option('-t, --tag <versionTag>')
.option('-f, --force', 'force update even if deployment is ahead of or equal to the specified version tag')
.option('-c, --show-release-candidates', 'set if you want to list release candidate versions')
// .option('-p, --provider <providerPermalink>', 'if you want to update from someone other than Tradle')
.description('updates your MyCloud to a given version')
.description('update your MyCloud')
.allowUnknownOption(false)
.action(createAction('update'))

const updateManuallyCommand = program
.command('update-manually')
.option('-t, --template-url <templateUrl>', 'stack template url')
.description('[ADVANCED] update your MyCloud to a given stack template')
.allowUnknownOption(false)
.action(createAction('updateManually'))

const rollbackCommand = program
.command('rollback')
.option('-t, --tag <versionTag>')
.option('-c, --show-release-candidates', 'set if you want to list release candidate versions')
// .option('-p, --provider <providerPermalink>', 'if you want to update from someone other than Tradle')
.description('rolls your MyCloud back to a previous version')
.description('roll your MyCloud back to a version you previously deployed')
.allowUnknownOption(false)
.action(createAction('rollback'))

Expand Down
35 changes: 16 additions & 19 deletions src/conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { AWSClients,
WaitStackOpts,
VersionInfo,
GetUpdateInfoResp,
ApplyUpdateOpts,
} from './types'
import { Errors as CustomErrors } from './errors'
import * as validate from './validate'
Expand Down Expand Up @@ -714,8 +715,14 @@ export class Conf {
}

public getCurrentVersion = async ():Promise<VersionInfo> => {
const { version } = await this.info()
return version
const versions = await this.exec({
args: ['listmyversions --limit 1'],
noWarning: true
})

return versions[0]
// const { version } = await this.info()
// return version
}

public listUpdates = async ({ provider }: {
Expand Down Expand Up @@ -774,6 +781,11 @@ export class Conf {
})
}

public updateManually = async (opts: ApplyUpdateOpts) => {
await this.applyUpdateAsCurrentUser(opts)
await this.waitForStackUpdate()
}

public rollback = async (opts: UpdateOpts) => {
this._ensureRemote(false)
this._ensureStackNameKnown()
Expand All @@ -785,25 +797,10 @@ export class Conf {
})
}

public applyUpdateAsCurrentUser = async (update) => {
public applyUpdateAsCurrentUser = async (update: ApplyUpdateOpts) => {
this._ensureRemote(false)
this._ensureStackNameKnown()
const { templateUrl, notificationTopics } = update
// const opts = [
// `--stack-name "${this.stackId}"`,
// `--template-url "${templateUrl}"`,
// '--capabilities CAPABILITY_NAMED_IAM',
// ]

// if (notificationTopics) {
// const arns = notificationTopics.map(t => `"${t}"`).join(' ')
// opts.push(`--notification-arns ${arns}`)
// }

// const { code, stderr, stdout } = shelljs.exec(
// `aws cloudformation update-stack ${opts.join(' ')}`,
// { silent: true }
// )

const params:AWS.CloudFormation.UpdateStackInput = {
StackName: this.stackId || this.stackName,
TemplateURL: templateUrl,
Expand Down
4 changes: 4 additions & 0 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ export const init = async (conf: Conf) => {
region
})

if (!stackInfos.length) {
throw new Error('no stacks found')
}

return stackInfos.map(({ name, id }) => ({
name,
value: { name, id }
Expand Down
6 changes: 6 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface UpdateOpts {
export interface VersionInfo {
tag: string
sortableTag: string
templateUrl?: string
}

export type InvokeOpts = {
Expand All @@ -70,3 +71,8 @@ export interface GetUpdateInfoResp {
update: VersionInfo
upToDate: boolean
}

export interface ApplyUpdateOpts {
templateUrl: string
notificationTopics?: string[]
}
Loading

0 comments on commit 929a870

Please sign in to comment.