Skip to content

Commit

Permalink
feat(stepfunctions-tasks): support complete overridings of start buil…
Browse files Browse the repository at this point in the history
…d of codebuild.
  • Loading branch information
zxkane committed Sep 30, 2020
1 parent 9aea4ae commit 45cc7d5
Show file tree
Hide file tree
Showing 7 changed files with 511 additions and 25 deletions.
37 changes: 30 additions & 7 deletions packages/@aws-cdk/aws-codebuild/lib/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IBucket } from '@aws-cdk/aws-s3';
import { Aws, Fn } from '@aws-cdk/core';
import { CfnProject } from './codebuild.generated';
import { IProject } from './project';

export interface BucketCacheOptions {
Expand Down Expand Up @@ -30,14 +29,38 @@ export enum LocalCacheMode {
CUSTOM = 'LOCAL_CUSTOM_CACHE',
}

/**
* Cache config property
*/
export interface CacheProperty {
/**
* The location of cache.
*
* @default - no location specified
*/
readonly location?: string;

/**
* The local cache modes of cache.
*
* @default - no cache mode
*/
readonly modes?: string[];

/**
* The type of cache.
*/
readonly type: string;
}

/**
* Cache options for CodeBuild Project.
* A cache can store reusable pieces of your build environment and use them across multiple builds.
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/build-caching.html
*/
export abstract class Cache {
public static none(): Cache {
return { _toCloudFormation: () => undefined, _bind: () => { return; } };
return { config: () => undefined, _bind: () => { return; } };
}

/**
Expand All @@ -46,9 +69,9 @@ export abstract class Cache {
*/
public static local(...modes: LocalCacheMode[]): Cache {
return {
_toCloudFormation: () => ({
config: () => ({
type: 'LOCAL',
modes,
modes: modes.map(mode => mode.toString()),
}),
_bind: () => { return; },
};
Expand All @@ -61,7 +84,7 @@ export abstract class Cache {
*/
public static bucket(bucket: IBucket, options?: BucketCacheOptions): Cache {
return {
_toCloudFormation: () => ({
config: () => ({
type: 'S3',
location: Fn.join('/', [bucket.bucketName, options && options.prefix || Aws.NO_VALUE]),
}),
Expand All @@ -72,9 +95,9 @@ export abstract class Cache {
}

/**
* @internal
* Get cache overriding config when starting CodeBuild project.
*/
public abstract _toCloudFormation(): CfnProject.ProjectCacheProperty | undefined;
public abstract config(): CacheProperty | undefined;

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ export class Project extends ProjectBase {
// empty will not remove existing encryptionKeys during an update (ref. t/D17810523)
encryptionKey: Lazy.stringValue({ produce: () => this._encryptionKey ? this._encryptionKey.keyArn : 'alias/aws/s3' }),
badgeEnabled: props.badge,
cache: cache._toCloudFormation(),
cache: cache.config(),
name: this.physicalName,
timeoutInMinutes: props.timeout && props.timeout.toMinutes(),
secondarySources: Lazy.anyValue({ produce: () => this.renderSecondarySources() }),
Expand Down
17 changes: 12 additions & 5 deletions packages/@aws-cdk/aws-stepfunctions-tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,19 @@ const codebuildProject = new codebuild.Project(stack, 'Project', {
const task = new tasks.CodeBuildStartBuild(stack, 'Task', {
project: codebuildProject,
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
environmentVariablesOverride: {
ZONE: {
type: codebuild.BuildEnvironmentVariableType.PLAINTEXT,
value: sfn.JsonPath.stringAt('$.envVariables.zone'),
},
environmentOverride: {
environmentVariables: {
ZONE: {
type: codebuild.BuildEnvironmentVariableType.PLAINTEXT,
value: sfn.JsonPath.stringAt('$.envVariables.zone'),
},
}
},
codebuild.Source.gitHub({
branchOrRef: sfn.JsonPath.stringAt('$.commitHash'),
owner,
repo,
}),
});
```

Expand Down
Loading

0 comments on commit 45cc7d5

Please sign in to comment.