Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
feat: enable CD for core stack only
Browse files Browse the repository at this point in the history
This allows to configure CD only for the core stack

Fixes #429

It also separates the Web App and the Device UI stack.

BREAKING CHANGE: the Web App stack is renamed

How to migrate:
- delete the `${STACK_NAME}-webapps` stack after
  deployment.
  This is technically not a breaking change,
  it will create a new stack for the web app and
  device ui and leave the old stack in place.
  • Loading branch information
coderbyheart committed Oct 8, 2020
1 parent b2a3e9d commit 3d3e18d
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 189 deletions.
58 changes: 56 additions & 2 deletions cdk/apps/Bifravst.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { App } from '@aws-cdk/core'
import { BifravstStack } from '../stacks/Bifravst'
import { WebAppsStack } from '../stacks/WebApps'
import { WebAppStack } from '../stacks/WebApp'
import {
BifravstLambdas,
CDKLambdas,
PackedLambdas,
} from '../prepare-resources'
import { DeviceUIStack } from '../stacks/DeviceUI'
import { FirmwareCIStack } from '../stacks/FirmwareCI'
import * as path from 'path'
import { readFileSync } from 'fs'
import { ContinuousDeploymentStack } from '../stacks/ContinuousDeployment'
import { extractRepoAndOwner } from '../helper/extract-repo-and-owner'
import { enabledInContext } from '../helper/enabledInContext'

export class BifravstApp extends App {
public constructor(args: {
Expand All @@ -16,10 +23,57 @@ export class BifravstApp extends App {
enableUnwiredApi: boolean
}) {
super()
// Core
new BifravstStack(this, {
...args,
isTest: false,
})
new WebAppsStack(this)
const checkFlag = enabledInContext(this.node)
// Web App
checkFlag({
key: 'webapp',
component: 'Web App',
onUndefined: 'enabled',
onEnabled: () => new WebAppStack(this),
})
// Device UI
checkFlag({
key: 'deviceui',
component: 'Device UI',
onUndefined: 'enabled',
onEnabled: () => new DeviceUIStack(this),
})
// Firmware CI
checkFlag({
key: 'firmware-ci',
component: 'Firmware CI',
onEnabled: () => {
new FirmwareCIStack(this, args)
},
})
// CD
checkFlag({
key: 'cd',
component: 'Continuous Deployment',
onEnabled: () => {
const pjson = JSON.parse(
readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'),
)
new ContinuousDeploymentStack(this, {
bifravstAWS: {
...extractRepoAndOwner(pjson.repository.url),
branch: pjson.deploy.branch ?? 'saga',
},
webApp: {
...extractRepoAndOwner(pjson.deploy.webApp.repository),
branch: pjson.deploy.webApp.branch ?? 'saga',
},
deviceUI: {
...extractRepoAndOwner(pjson.deploy.deviceUI.repository),
branch: pjson.deploy.deviceUI.branch ?? 'saga',
},
})
},
})
}
}
26 changes: 0 additions & 26 deletions cdk/apps/ContinuousDeployment.ts

This file was deleted.

14 changes: 0 additions & 14 deletions cdk/apps/FirmwareCI.ts

This file was deleted.

23 changes: 0 additions & 23 deletions cdk/cloudformation-cd.ts

This file was deleted.

22 changes: 0 additions & 22 deletions cdk/cloudformation-firmware-ci.ts

This file was deleted.

65 changes: 65 additions & 0 deletions cdk/helper/enabledInContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as CloudFormation from '@aws-cdk/core'
import * as chalk from 'chalk'

const ENABLED = 'enabled'
const DISABLED = 'disabled'

export const enabledInContext = (node: CloudFormation.ConstructNode) => ({
key,
component,
truthy,
onDisabled,
onEnabled,
onUndefined,
}: {
key: string
component: string
truthy?: string
onEnabled?: () => void
onDisabled?: () => void
onUndefined?: typeof ENABLED | typeof DISABLED
}): boolean => {
const v = node.tryGetContext(key)
if (
v === (truthy ?? '1') ||
(v === undefined && (onUndefined ?? DISABLED) === ENABLED)
) {
console.error(
chalk.gray(`Component`),
chalk.blueBright(component),
chalk.green('enabled.'),
chalk.gray(`Do not pass`),
chalk.grey.bold(`-c ${key}=${truthy ?? '1'}`),
chalk.gray(`to`),
chalk.grey.bold(`npx cdk deploy '*'`),
chalk.grey(`to disable.`),
)
onEnabled?.()
return true
}
const help = [
chalk.gray(`Component`),
chalk.grey.bold(component),
chalk.gray('disabled.'),
]
if ((onUndefined ?? DISABLED) === ENABLED) {
help.push(
chalk.gray(`Do not pass`),
chalk.grey.bold(`-c ${key}=${v}`),
chalk.gray(`to`),
chalk.grey.bold(`npx cdk deploy '*'`),
chalk.grey(`to enable.`),
)
} else {
help.push(
chalk.gray(`Pass`),
chalk.grey.bold(`-c ${key}=${truthy ?? '1'}`),
chalk.gray(`to`),
chalk.grey.bold(`npx cdk deploy '*'`),
chalk.grey(`to enable.`),
)
}
console.error(...help)
onDisabled?.()
return false
}
Loading

0 comments on commit 3d3e18d

Please sign in to comment.