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

Commit

Permalink
feat(cd): update apps on change to bifravst
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Aug 5, 2019
1 parent 40c7001 commit ea7d1ff
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 130 deletions.
104 changes: 36 additions & 68 deletions cdk/resources/WebAppCD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,40 @@ import * as CloudFormation from '@aws-cdk/core'
import * as IAM from '@aws-cdk/aws-iam'
import * as CodeBuild from '@aws-cdk/aws-codebuild'
import * as CodePipeline from '@aws-cdk/aws-codepipeline'
import * as SSM from '@aws-cdk/aws-ssm'
import * as S3 from '@aws-cdk/aws-s3'

export const BuildActionCodeBuild = {
category: 'Build',
owner: 'AWS',
version: '1',
provider: 'CodeBuild',
}

/**
* This sets up the continuous delivery for a web-app
*/
export class WebAppCD extends CloudFormation.Construct {
public readonly codeBuildProject: CodeBuild.CfnProject
public constructor(
parent: CloudFormation.Stack,
id: string,
{
bifravstStackId,
bifravstAWS,
webApp,
githubToken,
buildSpec,
description,
sourceCodeActions,
}: {
bifravstAWS: {
owner: string
repo: string
branch: string
}
webApp: {
owner: string
repo: string
branch: string
sourceCodeActions: {
bifravst: {
action: CodePipeline.CfnPipeline.ActionDeclarationProperty
outputName: string
}
webApp: {
action: CodePipeline.CfnPipeline.ActionDeclarationProperty
outputName: string
}
}
bifravstStackId: string
githubToken: SSM.IStringParameter
buildSpec: string
description: string
},
Expand All @@ -52,7 +56,7 @@ export class WebAppCD extends CloudFormation.Construct {
},
})

const project = new CodeBuild.CfnProject(this, 'CodeBuildProject', {
this.codeBuildProject = new CodeBuild.CfnProject(this, 'CodeBuildProject', {
name: id,
description,
source: {
Expand All @@ -75,7 +79,7 @@ export class WebAppCD extends CloudFormation.Construct {
],
},
})
project.node.addDependency(codeBuildRole)
this.codeBuildProject.node.addDependency(codeBuildRole)

const bucket = new S3.Bucket(this, 'bucket', {
removalPolicy: CloudFormation.RemovalPolicy.RETAIN,
Expand All @@ -87,7 +91,7 @@ export class WebAppCD extends CloudFormation.Construct {
controlCodeBuild: new IAM.PolicyDocument({
statements: [
new IAM.PolicyStatement({
resources: [project.attrArn],
resources: [this.codeBuildProject.attrArn],
actions: ['codebuild:*'],
}),
],
Expand All @@ -114,63 +118,27 @@ export class WebAppCD extends CloudFormation.Construct {
{
name: 'Source',
actions: [
{
name: 'BifravstAWSSourceCode',
actionTypeId: {
category: 'Source',
owner: 'ThirdParty',
version: '1',
provider: 'GitHub',
},
outputArtifacts: [
{
name: 'BifravstAWS',
},
],
configuration: {
Branch: bifravstAWS.branch,
Owner: bifravstAWS.owner,
Repo: bifravstAWS.repo,
OAuthToken: githubToken.stringValue,
},
},
{
name: 'WebAppSourceCode',
actionTypeId: {
category: 'Source',
owner: 'ThirdParty',
version: '1',
provider: 'GitHub',
},
outputArtifacts: [
{
name: 'WebApp',
},
],
configuration: {
Branch: webApp.branch,
Owner: webApp.owner,
Repo: webApp.repo,
OAuthToken: githubToken.stringValue,
},
},
sourceCodeActions.bifravst.action,
sourceCodeActions.webApp.action,
],
},
{
name: 'Deploy',
actions: [
{
name: 'DeployWebApp',
inputArtifacts: [{ name: 'BifravstAWS' }, { name: 'WebApp' }],
actionTypeId: {
category: 'Build',
owner: 'AWS',
version: '1',
provider: 'CodeBuild',
},
inputArtifacts: [
{
name: sourceCodeActions.bifravst.outputName,
},
{
name: sourceCodeActions.webApp.outputName,
},
],
actionTypeId: BuildActionCodeBuild,
configuration: {
ProjectName: project.name,
PrimarySource: 'BifravstAWS',
ProjectName: this.codeBuildProject.name,
PrimarySource: sourceCodeActions.bifravst.outputName,
},
outputArtifacts: [
{
Expand All @@ -192,12 +160,12 @@ export class WebAppCD extends CloudFormation.Construct {
filters: [
{
jsonPath: '$.ref',
matchEquals: `refs/heads/${webApp.branch}`,
matchEquals: `refs/heads/${sourceCodeActions.webApp.action.configuration.Branch}`,
},
],
authentication: 'GITHUB_HMAC',
authenticationConfiguration: {
secretToken: githubToken.stringValue,
secretToken: sourceCodeActions.webApp.action.configuration.OAuthToken,
},
registerWithThirdParty: false,
})
Expand Down
Loading

0 comments on commit ea7d1ff

Please sign in to comment.