-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codebuild): add support for local cache modes (#2529)
Fixes #1956
- Loading branch information
Sander Knape
authored and
Elad Ben-Israel
committed
May 17, 2019
1 parent
cfe46f6
commit e7ad990
Showing
6 changed files
with
206 additions
and
25 deletions.
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,83 @@ | ||
import { IBucket } from "@aws-cdk/aws-s3"; | ||
import { Aws, Fn } from "@aws-cdk/cdk"; | ||
import { CfnProject } from "./codebuild.generated"; | ||
import { IProject } from "./project"; | ||
|
||
export interface BucketCacheOptions { | ||
/** | ||
* The prefix to use to store the cache in the bucket | ||
*/ | ||
readonly prefix?: string; | ||
} | ||
|
||
/** | ||
* Local cache modes to enable for the CodeBuild Project | ||
*/ | ||
export enum LocalCacheMode { | ||
/** | ||
* Caches Git metadata for primary and secondary sources | ||
*/ | ||
Source = 'LOCAL_SOURCE_CACHE', | ||
|
||
/** | ||
* Caches existing Docker layers | ||
*/ | ||
DockerLayer = 'LOCAL_DOCKER_LAYER_CACHE', | ||
|
||
/** | ||
* Caches directories you specify in the buildspec file | ||
*/ | ||
Custom = 'LOCAL_CUSTOM_CACHE', | ||
} | ||
|
||
/** | ||
* 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; } }; | ||
} | ||
|
||
/** | ||
* Create a local caching strategy. | ||
* @param modes the mode(s) to enable for local caching | ||
*/ | ||
public static local(...modes: LocalCacheMode[]): Cache { | ||
return { | ||
_toCloudFormation: () => ({ | ||
type: 'LOCAL', | ||
modes | ||
}), | ||
_bind: () => { return; } | ||
}; | ||
} | ||
|
||
/** | ||
* Create an S3 caching strategy. | ||
* @param bucket the S3 bucket to use for caching | ||
* @param options additional options to pass to the S3 caching | ||
*/ | ||
public static bucket(bucket: IBucket, options?: BucketCacheOptions): Cache { | ||
return { | ||
_toCloudFormation: () => ({ | ||
type: 'S3', | ||
location: Fn.join('/', [bucket.bucketName, options && options.prefix || Aws.noValue]) | ||
}), | ||
_bind: (project) => { | ||
bucket.grantReadWrite(project); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public abstract _toCloudFormation(): CfnProject.ProjectCacheProperty | undefined; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public abstract _bind(project: IProject): void; | ||
} |
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