-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Components stack to CI Pipeline (#31)
- Loading branch information
1 parent
ff2ed28
commit 8893fcf
Showing
6 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import {Construct, Stack} from "@aws-cdk/core"; | ||
import {BuildSpec, Cache, LocalCacheMode, Project} from "@aws-cdk/aws-codebuild"; | ||
import {CodeBuildAction, CodeBuildActionProps} from "@aws-cdk/aws-codepipeline-actions"; | ||
import {Artifact, IStage} from "@aws-cdk/aws-codepipeline"; | ||
import {Effect, PolicyStatement} from "@aws-cdk/aws-iam"; | ||
|
||
import {EnvConstructProps} from "../../../types"; | ||
import {ServiceCiConfig} from "../../../patterns/serviceCiConfig"; | ||
|
||
interface ComponentsCiConfigProps extends EnvConstructProps { | ||
inputArtifact: Artifact; | ||
buildStage: IStage; | ||
deployStage: IStage; | ||
} | ||
|
||
export class ComponentsCiConfig extends ServiceCiConfig { | ||
constructor(scope: Construct, id: string, props: ComponentsCiConfigProps) { | ||
super(scope, id, {envSettings: props.envSettings}); | ||
|
||
props.deployStage.addAction(this.createDeployAction({ | ||
project: this.createDeployProject(props), | ||
}, props)); | ||
} | ||
|
||
private createDeployAction(actionProps: Partial<CodeBuildActionProps>, props: ComponentsCiConfigProps) { | ||
return new CodeBuildAction(<CodeBuildActionProps>{ | ||
...actionProps, | ||
project: actionProps.project, | ||
actionName: `${props.envSettings.projectEnvName}-deploy-components`, | ||
input: props.inputArtifact, | ||
runOrder: 1, | ||
}); | ||
} | ||
|
||
private createDeployProject(props: ComponentsCiConfigProps) { | ||
const stack = Stack.of(this); | ||
const project = new Project(this, "ComponentsDeployProject", { | ||
projectName: `${props.envSettings.projectEnvName}-deploy-components`, | ||
buildSpec: BuildSpec.fromObject({ | ||
version: '0.2', | ||
phases: { | ||
pre_build: {commands: ['make -C infra/cdk install']}, | ||
build: {commands: ['make -C infra/cdk deploy-components']} | ||
}, | ||
cache: { | ||
paths: [...this.defaultCachePaths], | ||
}, | ||
}), | ||
environmentVariables: {...this.defaultEnvVariables}, | ||
cache: Cache.local(LocalCacheMode.CUSTOM), | ||
}); | ||
|
||
project.addToRolePolicy(new PolicyStatement({ | ||
effect: Effect.ALLOW, | ||
actions: [ | ||
'cloudformation:*', | ||
], | ||
resources: [ | ||
`arn:aws:cloudformation:${stack.region}:${stack.account}:stack/CDKToolkit/*`, | ||
`arn:aws:cloudformation:${stack.region}:${stack.account}:stack/${props.envSettings.projectEnvName}-ComponentsStack/*`, | ||
], | ||
})); | ||
|
||
project.addToRolePolicy(new PolicyStatement({ | ||
effect: Effect.ALLOW, | ||
actions: [ | ||
'iam:*', | ||
'logs:*', | ||
's3:*', | ||
'sqs:*', | ||
'events:*', | ||
], | ||
resources: ['*'], | ||
})); | ||
|
||
return project; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters