Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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 @@ -379,3 +379,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: [
codebuild.FileSystemLocation.efs({
identifier: "myidentifier2",
location: "myclodation.mydnsroot.com:/loc",
mountPoint: "/media",
mountOptions: "opts"
})
]
});
```

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)
85 changes: 85 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/file-location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Construct } from '@aws-cdk/core';
import { CfnProject } from './codebuild.generated';
import { IProject } from './project';

/**
* The type returned from {@link IFileSystemLocation#bind}.
*/
export interface FileSystemConfig {
/**
* File system location wrapper property.
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-projectfilesystemlocation.html
*/
readonly location: CfnProject.ProjectFileSystemLocationProperty;
}

/**
* The interface of a CodeBuild FileSystemLocation.
* Implemented by {@link EfsFileSystemLocation}.
*/
export interface IFileSystemLocation {
/**
* Called by the project when a file system is added so it can perform
* binding operations on this file system location.
*/
bind(scope: Construct, project: IProject): FileSystemConfig;
}

/**
* FileSystemLocation provider definition for a CodeBuild Project.
*/
export class FileSystemLocation {
/**
* EFS file system provider.
* @param props the EFS File System location property.
*/
public static efs(props: EfsFileSystemLocationProps): IFileSystemLocation {
return new EfsFileSystemLocation(props);
}
}

/**
* EfsFileSystemLocation definition for a CodeBuild project.
*/
class EfsFileSystemLocation implements IFileSystemLocation {
constructor(private readonly props: EfsFileSystemLocationProps) {}

public bind(_scope: Construct, _project: IProject): FileSystemConfig {
return {
location: {
identifier: this.props.identifier,
location: this.props.location,
mountOptions: this.props.mountOptions,
mountPoint: this.props.mountPoint,
type: 'EFS',
},
};
}
}

/**
* Construction properties for {@link EfsFileSystemLocation}.
*/
export interface EfsFileSystemLocationProps {
/**
* The name used to access a file system created by Amazon EFS.
*/
readonly identifier: string;

/**
* A string that specifies the location of the file system, like Amazon EFS.
* @example 'fs-abcd1234.efs.us-west-2.amazonaws.com:/my-efs-mount-directory'.
*/
readonly location: string;

/**
* The mount options for a file system such as Amazon EFS.
* @default 'nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2'.
*/
readonly mountOptions?: string;

/**
* The location in the container where you mount the file system.
*/
readonly mountPoint: string;
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-codebuild/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './source-credentials';
export * from './artifacts';
export * from './cache';
export * from './build-spec';
export * from './file-location';

// AWS::CodeBuild CloudFormation Resources:
export * from './codebuild.generated';
34 changes: 34 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BuildSpec } from './build-spec';
import { Cache } from './cache';
import { CfnProject } from './codebuild.generated';
import { CodePipelineArtifacts } from './codepipeline-artifacts';
import { IFileSystemLocation } from './file-location';
import { NoArtifacts } from './no-artifacts';
import { NoSource } from './no-source';
import { ISource } from './source';
Expand Down Expand Up @@ -508,6 +509,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 - no file system locations
*/
readonly fileSystemLocations?: IFileSystemLocation[];
}

export interface ProjectProps extends CommonProjectProps {
Expand Down Expand Up @@ -657,6 +668,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 +712,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 +724,10 @@ export class Project extends ProjectBase {

this.validateCodePipelineSettings(artifacts);

for (const fileSystemLocation of props.fileSystemLocations || []) {
this.addFileSystemLocation(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,16 @@ export class Project extends ProjectBase {
}
}

/**
* Adds a fileSystemLocation to the Project.
*
* @param fileSystemLocation the fileSystemLocation to add
*/
public addFileSystemLocation(fileSystemLocation: IFileSystemLocation): void {
const fileSystemConfig = fileSystemLocation.bind(this, this);
this._fileSystemLocations.push(fileSystemConfig.location);
}

/**
* Adds a secondary artifact to the Project.
*
Expand Down Expand Up @@ -898,6 +926,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
Loading