Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/@aws-cdk/aws-codebuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,33 @@ const project = new codebuild.Project(this, 'MyProject', {

project.connections.allowTo(loadBalancer, ec2.Port.tcp(443));
```

## Project File System Location EFS

Add support for CodeBuild to build on AWS EFS file system mounts using
the new ProjectFileSystemLocation .
The `fileSystemLocations` property which accepts a list `ProjectFileSystemLocation`
as represented by the interface `IFileSystemLocations`
The only supported file system type is `EFS`

For Example:

```ts
new codebuild.Project(stack, 'MyProject', {
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
}),
fileSystemLocations: [{
identifier: "myidentifier",
location: "fs-c8d04839.efs.eu-west-2.amazonaws.com:/mnt",
mountOptions: "nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2",
mountPoint: "/media",
type: "EFS"

}]
});
```

Here's a CodeBuild project with a simple example that creates a project mounted on AWS EFS:

[Minimal Example](./test/integ.project-file-system-location.ts)
50 changes: 50 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,16 @@ export interface CommonProjectProps {
* @default true
*/
readonly allowAllOutbound?: boolean;

/**
* An ProjectFileSystemLocation objects for a CodeBuild build project.
*
* A ProjectFileSystemLocation object specifies the identifier, location, mountOptions, mountPoint,
* and type of a file system created using Amazon Elastic File System.
*
* @default false
*/
readonly fileSystemLocations?: IFileSystemLocation[];
}

export interface ProjectProps extends CommonProjectProps {
Expand Down Expand Up @@ -657,6 +667,7 @@ export class Project extends ProjectBase {
private readonly _secondarySourceVersions: CfnProject.ProjectSourceVersionProperty[];
private readonly _secondaryArtifacts: CfnProject.ArtifactsProperty[];
private _encryptionKey?: kms.IKey;
private readonly _fileSystemLocations: CfnProject.ProjectFileSystemLocationProperty[];

constructor(scope: Construct, id: string, props: ProjectProps) {
super(scope, id, {
Expand Down Expand Up @@ -700,6 +711,7 @@ export class Project extends ProjectBase {

this._secondarySources = [];
this._secondarySourceVersions = [];
this._fileSystemLocations = [];
for (const secondarySource of props.secondarySources || []) {
this.addSecondarySource(secondarySource);
}
Expand All @@ -711,6 +723,11 @@ export class Project extends ProjectBase {

this.validateCodePipelineSettings(artifacts);

for (const fileSystemLocation of props.fileSystemLocations || []) {
this.validateFileSystemLocation(fileSystemLocation);
this.addFileSystemLocations(fileSystemLocation);
}

const resource = new CfnProject(this, 'Resource', {
description: props.description,
source: {
Expand All @@ -720,6 +737,7 @@ export class Project extends ProjectBase {
artifacts: artifactsConfig.artifactsProperty,
serviceRole: this.role.roleArn,
environment: this.renderEnvironment(props.environment, environmentVariables),
fileSystemLocations: this.renderFileSystemLocations(),
// lazy, because we have a setter for it in setEncryptionKey
encryptionKey: Lazy.stringValue({ produce: () => this._encryptionKey && this._encryptionKey.keyArn }),
badgeEnabled: props.badge,
Expand Down Expand Up @@ -770,6 +788,15 @@ export class Project extends ProjectBase {
}
}

/**
* Adds a fileSystemLocation to the Project.
*
* @param fileSystemLocation the fileSystemLocation to add
*/
public addFileSystemLocations(fileSystemLocation: IFileSystemLocation): void {
this._fileSystemLocations.push(fileSystemLocation);
}

/**
* Adds a secondary artifact to the Project.
*
Expand Down Expand Up @@ -898,6 +925,12 @@ export class Project extends ProjectBase {
};
}

private renderFileSystemLocations(): CfnProject.ProjectFileSystemLocationProperty[] | undefined {
return this._fileSystemLocations.length === 0
? undefined
: this._fileSystemLocations;
}

private renderSecondarySources(): CfnProject.SourceProperty[] | undefined {
return this._secondarySources.length === 0
? undefined
Expand Down Expand Up @@ -1005,6 +1038,12 @@ export class Project extends ProjectBase {
throw new Error('Both source and artifacts must be set to CodePipeline');
}
}

private validateFileSystemLocation(fileSystemLocation: IFileSystemLocation) {
if (fileSystemLocation.type !== "EFS") {
throw new Error('The only supported type for fileSystemLocation is EFS');
}
}
}

/**
Expand Down Expand Up @@ -1515,3 +1554,14 @@ export enum BuildEnvironmentVariableType {
*/
SECRETS_MANAGER = 'SECRETS_MANAGER'
}

/**
* The abstract interface of a CodeBuild FileSystemLocation.
*/
export interface IFileSystemLocation {
readonly identifier: string;
readonly location: string;
readonly mountOptions?: string;
readonly mountPoint: string;
readonly type: string;
}
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-codebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@
"docs-public-apis:@aws-cdk/aws-codebuild.S3SourceProps.path",
"docs-public-apis:@aws-cdk/aws-codebuild.SourceConfig.sourceProperty",
"docs-public-apis:@aws-cdk/aws-codebuild.SourceConfig.buildTriggers",
"props-default-doc:@aws-cdk/aws-codebuild.SourceConfig.buildTriggers"
"props-default-doc:@aws-cdk/aws-codebuild.SourceConfig.buildTriggers",
"docs-public-apis:@aws-cdk/aws-codebuild.IFileSystemLocation.identifier",
"docs-public-apis:@aws-cdk/aws-codebuild.IFileSystemLocation.location",
"docs-public-apis:@aws-cdk/aws-codebuild.IFileSystemLocation.mountPoint",
"docs-public-apis:@aws-cdk/aws-codebuild.IFileSystemLocation.type",
"docs-public-apis:@aws-cdk/aws-codebuild.IFileSystemLocation.mountOptions"
]
},
"stability": "stable"
Expand Down
Loading