Skip to content

Commit

Permalink
feat: CICDPipelineStack() updates (#283)
Browse files Browse the repository at this point in the history
* adding cdk language prop to CICDPipelineStack

* adding enable key rotation override to pipeline key

* build

* allow command failure in generic actions

* allowing failure

* Revert "allowing failure"

This reverts commit be77733.

* Revert "allow command failure in generic actions"

This reverts commit 0617302.
  • Loading branch information
malachi-constant committed Mar 24, 2023
1 parent 6b0120f commit cca11f6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
28 changes: 25 additions & 3 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions src/cicd/pipelines.ts
Expand Up @@ -2,9 +2,10 @@ import * as cdk from "aws-cdk-lib";
import * as codepipeline from "aws-cdk-lib/aws-codepipeline";
import * as codestarnotifications from "aws-cdk-lib/aws-codestarnotifications";
import * as iam from "aws-cdk-lib/aws-iam";
import * as kms from "aws-cdk-lib/aws-kms";
import * as sns from "aws-cdk-lib/aws-sns";
import * as pipelines from "aws-cdk-lib/pipelines";
import { Construct, IConstruct } from "constructs";
import { Construct } from "constructs";
import { CICDActions } from "./actions";
import { toTitleCase } from "./utils";
import { BaseStack, BaseStackProps } from "../base";
Expand Down Expand Up @@ -60,6 +61,7 @@ export interface AddCustomStageProps {

export interface CICDPipelineStackProps extends BaseStackProps {
readonly pipelineName?: string;
readonly cdkLanguage?: string;
}

export interface AdditionalPipelineProps {
Expand All @@ -82,9 +84,10 @@ export class CICDPipelineStack extends BaseStack {
readonly pipelineName?: string;
readonly pipelineId?: string;
readonly config: Configurator;
readonly cdkLanguage: string;
public notificationRule?: codestarnotifications.NotificationRule;
public pipeline?: pipelines.CodePipeline;
public pipelineKey?: IConstruct;
public pipelineKey?: kms.CfnKey;
public sourceAction?: pipelines.CodePipelineSource;
public synthAction?: pipelines.CodeBuildStep;

Expand All @@ -96,6 +99,7 @@ export class CICDPipelineStack extends BaseStack {
this.pipelineId = id;
const config = props.config ?? "./ddk.json";
this.config = new Configurator(this, config, this.environmentId);
this.cdkLanguage = props.cdkLanguage ?? "typescript";
}

addSourceAction(props: SourceActionProps) {
Expand Down Expand Up @@ -123,6 +127,11 @@ export class CICDPipelineStack extends BaseStack {
}

addSynthAction(props: SynthActionProps = {}) {
const languageInstallCommand: any = {
typescript: "npm install",
python: "pip install -r requirements.txt",
};

this.synthAction =
props.synthAction ||
CICDActions.getSynthAction({
Expand All @@ -135,7 +144,9 @@ export class CICDPipelineStack extends BaseStack {
codeartifactRepository: props.codeartifactRepository,
codeartifactDomain: props.codeartifactDomain,
codeartifactDomainOwner: props.codeartifactDomainOwner,
additionalInstallCommands: props.additionalInstallCommands,
additionalInstallCommands: props.additionalInstallCommands
? [languageInstallCommand[this.cdkLanguage]].concat(props.additionalInstallCommands)
: [languageInstallCommand[this.cdkLanguage]],
});
return this;
}
Expand Down Expand Up @@ -250,11 +261,9 @@ export class CICDPipelineStack extends BaseStack {

synth() {
this.pipeline?.buildPipeline();
this.pipelineKey = this.pipeline?.pipeline.artifactBucket.encryptionKey?.node.defaultChild ?? undefined;
this.pipelineKey = this.pipeline?.pipeline.artifactBucket.encryptionKey?.node.defaultChild as kms.CfnKey;
this.pipelineKey.addPropertyOverride("EnableKeyRotation", true);

// if (this.pipelineKey) {
// this.pipelineKey = true;
// }
return this;
}
}
3 changes: 3 additions & 0 deletions test/cicd-pipeline-stack.test.ts
Expand Up @@ -107,6 +107,9 @@ test("Basic CICDPipeline", () => {
template.hasResourceProperties("AWS::CodePipeline::Pipeline", {
Name: "dummy-pipeline",
});
template.hasResourceProperties("AWS::KMS::Key", {
EnableKeyRotation: true,
});
});

test("CICDPipeline with manual approval set", () => {
Expand Down

0 comments on commit cca11f6

Please sign in to comment.