Skip to content

Commit

Permalink
Added tests for caching support for CodeBuildStep
Browse files Browse the repository at this point in the history
  • Loading branch information
Hi-Fi committed Jun 15, 2022
1 parent cd6eb7d commit 79d33ac
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Template, Match } from '@aws-cdk/assertions';
import * as codebuild from '@aws-cdk/aws-codebuild';
import * as iam from '@aws-cdk/aws-iam';
import * as s3 from '@aws-cdk/aws-s3';
import { Duration, Stack } from '@aws-cdk/core';
import * as cdkp from '../../lib';
import { PIPELINE_ENV, TestApp, ModernTestGitHubNpmPipeline, AppWithOutput } from '../testhelpers';
Expand Down Expand Up @@ -274,3 +276,24 @@ test('exportedVariables', () => {
},
});
});

test('step has caching set', () => {
// WHEN
const myCachingBucket = new s3.Bucket(pipelineStack, 'MyCachingBucket');
new cdkp.CodePipeline(pipelineStack, 'Pipeline', {
synth: new cdkp.CodeBuildStep('Synth', {
cache: codebuild.Cache.bucket(myCachingBucket),
commands: ['/bin/true'],
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
}),
});

// THEN
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', {
Cache: {
Location: {
'Fn::Join': ['/', [{ Ref: 'MyCachingBucket8C98C553' }, { Ref: 'AWS::NoValue' }]],
},
},
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
/// !cdk-integ VariablePipelineStack pragma:set-context:@aws-cdk/core:newStyleStackSynthesis=true
import * as codebuild from '@aws-cdk/aws-codebuild';
import * as s3 from '@aws-cdk/aws-s3';
import { App, Stack, StackProps, RemovalPolicy } from '@aws-cdk/core';
import { Construct } from 'constructs';
Expand All @@ -24,8 +25,11 @@ class PipelineStack extends Stack {
selfMutation: false,
});

const cacheBucket = new s3.Bucket(this, 'TestCacheBucket');

const producer = new pipelines.CodeBuildStep('Produce', {
commands: ['export MY_VAR=hello'],
cache: codebuild.Cache.bucket(cacheBucket),
});

const consumer = new pipelines.CodeBuildStep('Consume', {
Expand All @@ -35,6 +39,7 @@ class PipelineStack extends Stack {
commands: [
'echo "The variable was: $THE_VAR"',
],
cache: codebuild.Cache.bucket(cacheBucket),
});

// WHEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,43 @@
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:Abort*",
"s3:DeleteObject*",
"s3:GetBucket*",
"s3:GetObject*",
"s3:List*",
"s3:PutObject",
"s3:PutObjectLegalHold",
"s3:PutObjectRetention",
"s3:PutObjectTagging",
"s3:PutObjectVersionTagging"
],
"Effect": "Allow",
"Resource": [
{
"Fn::GetAtt": [
"TestCacheBucketA6BDC126",
"Arn"
]
},
{
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"TestCacheBucketA6BDC126",
"Arn"
]
},
"/*"
]
]
}
]
},
{
"Action": [
"logs:CreateLogGroup",
Expand Down Expand Up @@ -932,7 +969,20 @@
"Type": "CODEPIPELINE"
},
"Cache": {
"Type": "NO_CACHE"
"Location": {
"Fn::Join": [
"/",
[
{
"Ref": "TestCacheBucketA6BDC126"
},
{
"Ref": "AWS::NoValue"
}
]
]
},
"Type": "S3"
},
"Description": "Pipeline step VariablePipelineStack/Pipeline/MyWave/Produce",
"EncryptionKey": "alias/aws/s3"
Expand Down Expand Up @@ -960,6 +1010,43 @@
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:Abort*",
"s3:DeleteObject*",
"s3:GetBucket*",
"s3:GetObject*",
"s3:List*",
"s3:PutObject",
"s3:PutObjectLegalHold",
"s3:PutObjectRetention",
"s3:PutObjectTagging",
"s3:PutObjectVersionTagging"
],
"Effect": "Allow",
"Resource": [
{
"Fn::GetAtt": [
"TestCacheBucketA6BDC126",
"Arn"
]
},
{
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"TestCacheBucketA6BDC126",
"Arn"
]
},
"/*"
]
]
}
]
},
{
"Action": [
"logs:CreateLogGroup",
Expand Down Expand Up @@ -1116,7 +1203,20 @@
"Type": "CODEPIPELINE"
},
"Cache": {
"Type": "NO_CACHE"
"Location": {
"Fn::Join": [
"/",
[
{
"Ref": "TestCacheBucketA6BDC126"
},
{
"Ref": "AWS::NoValue"
}
]
]
},
"Type": "S3"
},
"Description": "Pipeline step VariablePipelineStack/Pipeline/MyWave/Consume",
"EncryptionKey": "alias/aws/s3"
Expand Down Expand Up @@ -1202,6 +1302,11 @@
}
]
}
},
"TestCacheBucketA6BDC126": {
"Type": "AWS::S3::Bucket",
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
}
},
"Parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@
"data": "PipelineCodeBuildActionRoleDefaultPolicy1D62A6FE"
}
],
"/VariablePipelineStack/TestCacheBucket/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "TestCacheBucketA6BDC126"
}
],
"/VariablePipelineStack/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,43 @@
"aws:cdk:cloudformation:props": {
"policyDocument": {
"Statement": [
{
"Action": [
"s3:Abort*",
"s3:DeleteObject*",
"s3:GetBucket*",
"s3:GetObject*",
"s3:List*",
"s3:PutObject",
"s3:PutObjectLegalHold",
"s3:PutObjectRetention",
"s3:PutObjectTagging",
"s3:PutObjectVersionTagging"
],
"Effect": "Allow",
"Resource": [
{
"Fn::GetAtt": [
"TestCacheBucketA6BDC126",
"Arn"
]
},
{
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"TestCacheBucketA6BDC126",
"Arn"
]
},
"/*"
]
]
}
]
},
{
"Action": [
"logs:CreateLogGroup",
Expand Down Expand Up @@ -1220,7 +1257,20 @@
"buildSpec": "{\n \"version\": \"0.2\",\n \"env\": {\n \"exported-variables\": [\n \"MY_VAR\"\n ]\n },\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"export MY_VAR=hello\"\n ]\n }\n }\n}"
},
"cache": {
"type": "NO_CACHE"
"type": "S3",
"location": {
"Fn::Join": [
"/",
[
{
"Ref": "TestCacheBucketA6BDC126"
},
{
"Ref": "AWS::NoValue"
}
]
]
}
},
"description": "Pipeline step VariablePipelineStack/Pipeline/MyWave/Produce",
"encryptionKey": "alias/aws/s3"
Expand Down Expand Up @@ -1292,6 +1342,43 @@
"aws:cdk:cloudformation:props": {
"policyDocument": {
"Statement": [
{
"Action": [
"s3:Abort*",
"s3:DeleteObject*",
"s3:GetBucket*",
"s3:GetObject*",
"s3:List*",
"s3:PutObject",
"s3:PutObjectLegalHold",
"s3:PutObjectRetention",
"s3:PutObjectTagging",
"s3:PutObjectVersionTagging"
],
"Effect": "Allow",
"Resource": [
{
"Fn::GetAtt": [
"TestCacheBucketA6BDC126",
"Arn"
]
},
{
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"TestCacheBucketA6BDC126",
"Arn"
]
},
"/*"
]
]
}
]
},
{
"Action": [
"logs:CreateLogGroup",
Expand Down Expand Up @@ -1468,7 +1555,20 @@
"buildSpec": "{\n \"version\": \"0.2\",\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"echo \\\"The variable was: $THE_VAR\\\"\"\n ]\n }\n }\n}"
},
"cache": {
"type": "NO_CACHE"
"type": "S3",
"location": {
"Fn::Join": [
"/",
[
{
"Ref": "TestCacheBucketA6BDC126"
},
{
"Ref": "AWS::NoValue"
}
]
]
}
},
"description": "Pipeline step VariablePipelineStack/Pipeline/MyWave/Consume",
"encryptionKey": "alias/aws/s3"
Expand Down Expand Up @@ -1625,6 +1725,28 @@
"fqn": "@aws-cdk/pipelines.CodePipeline",
"version": "0.0.0"
}
},
"TestCacheBucket": {
"id": "TestCacheBucket",
"path": "VariablePipelineStack/TestCacheBucket",
"children": {
"Resource": {
"id": "Resource",
"path": "VariablePipelineStack/TestCacheBucket/Resource",
"attributes": {
"aws:cdk:cloudformation:type": "AWS::S3::Bucket",
"aws:cdk:cloudformation:props": {}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-s3.CfnBucket",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-s3.Bucket",
"version": "0.0.0"
}
}
},
"constructInfo": {
Expand Down

0 comments on commit 79d33ac

Please sign in to comment.