From cd6eb7d027461f26975b99884faef9729252d0c5 Mon Sep 17 00:00:00 2001 From: "John (Jack) Meyer" Date: Mon, 21 Feb 2022 21:13:08 -0800 Subject: [PATCH] Add support for caching --- packages/@aws-cdk/pipelines/README.md | 3 +++ .../pipelines/lib/codepipeline/codebuild-step.ts | 15 +++++++++++++++ .../pipelines/lib/codepipeline/codepipeline.ts | 7 +++++++ .../lib/codepipeline/private/codebuild-factory.ts | 3 +++ 4 files changed, 28 insertions(+) diff --git a/packages/@aws-cdk/pipelines/README.md b/packages/@aws-cdk/pipelines/README.md index 73fa4c26729ab..c6a8ed91928e5 100644 --- a/packages/@aws-cdk/pipelines/README.md +++ b/packages/@aws-cdk/pipelines/README.md @@ -728,6 +728,9 @@ new pipelines.CodeBuildStep('Synth', { subnetSelection: { subnetType: ec2.SubnetType.PRIVATE_WITH_NAT }, securityGroups: [mySecurityGroup], + // Control caching + cache: codebuild.Cache.bucket(new s3.Bucket(this, 'Cache')), + // Additional policy statements for the execution role rolePolicyStatements: [ new iam.PolicyStatement({ /* ... */ }), diff --git a/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts b/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts index 12bb058fceddb..398756fb6dff1 100644 --- a/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts +++ b/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts @@ -50,6 +50,13 @@ export interface CodeBuildStepProps extends ShellStepProps { */ readonly subnetSelection?: ec2.SubnetSelection; + /** + * Caching strategy to use. + * + * @default - No cache + */ + readonly cache?: codebuild.Cache; + /** * Policy statements to add to role used during the synth * @@ -139,6 +146,13 @@ export class CodeBuildStep extends ShellStep { */ public readonly subnetSelection?: ec2.SubnetSelection; + /** + * Caching strategy to use. + * + * @default - No cache + */ + public readonly cache?: codebuild.Cache; + /** * Policy statements to add to role used during the synth * @@ -196,6 +210,7 @@ export class CodeBuildStep extends ShellStep { this._partialBuildSpec = props.partialBuildSpec; this.vpc = props.vpc; this.subnetSelection = props.subnetSelection; + this.cache = props.cache; this.role = props.role; this.actionRole = props.actionRole; this.rolePolicyStatements = props.rolePolicyStatements; diff --git a/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts b/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts index 8081c5356d7c5..a764d341243a7 100644 --- a/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts +++ b/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts @@ -261,6 +261,13 @@ export interface CodeBuildOptions { */ readonly subnetSelection?: ec2.SubnetSelection; + /** + * Caching strategy to use. + * + * @default - No cache + */ + readonly cache?: cb.Cache; + /** * The number of minutes after which AWS CodeBuild stops the build if it's * not complete. For valid values, see the timeoutInMinutes field in the AWS diff --git a/packages/@aws-cdk/pipelines/lib/codepipeline/private/codebuild-factory.ts b/packages/@aws-cdk/pipelines/lib/codepipeline/private/codebuild-factory.ts index da442d882bd33..8ee148fb99ef5 100644 --- a/packages/@aws-cdk/pipelines/lib/codepipeline/private/codebuild-factory.ts +++ b/packages/@aws-cdk/pipelines/lib/codepipeline/private/codebuild-factory.ts @@ -161,6 +161,7 @@ export class CodeBuildFactory implements ICodePipelineActionFactory { partialBuildSpec: step.partialBuildSpec, vpc: step.vpc, subnetSelection: step.subnetSelection, + cache: step.cache, timeout: step.timeout, }), }); @@ -298,6 +299,7 @@ export class CodeBuildFactory implements ICodePipelineActionFactory { vpc: projectOptions.vpc, subnetSelection: projectOptions.subnetSelection, securityGroups: projectOptions.securityGroups, + cache: projectOptions.cache, buildSpec: projectBuildSpec, role: this.props.role, timeout: projectOptions.timeout, @@ -430,6 +432,7 @@ export function mergeCodeBuildOptions(...opts: Array