From a39a748dfe69c069ef7ccd50dfaa16867b333930 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Wed, 12 Jun 2019 12:33:40 -0700 Subject: [PATCH] Rename BuildSources, and make some of them package-private. --- packages/@aws-cdk/aws-codebuild/README.md | 49 ++++--- .../@aws-cdk/aws-codebuild/lib/artifacts.ts | 47 ++---- .../lib/codepipeline-artifacts.ts | 14 ++ .../aws-codebuild/lib/codepipeline-source.ts | 15 ++ .../aws-codebuild/lib/no-artifacts.ts | 19 +++ .../@aws-cdk/aws-codebuild/lib/no-source.ts | 19 +++ .../aws-codebuild/lib/pipeline-project.ts | 6 +- .../@aws-cdk/aws-codebuild/lib/project.ts | 58 ++++---- .../aws-codebuild/lib/source-types.ts | 7 + packages/@aws-cdk/aws-codebuild/lib/source.ts | 122 +++++++--------- .../test/integ.project-bucket.ts | 2 +- ...teg.project-secondary-sources-artifacts.ts | 4 +- .../aws-codebuild/test/integ.project-shell.ts | 2 +- .../aws-codebuild/test/integ.project-vpc.ts | 2 +- .../aws-codebuild/test/test.codebuild.ts | 136 ++++++------------ .../aws-codebuild/test/test.project.ts | 33 +++-- .../aws-codepipeline-actions/README.md | 11 -- .../test.cloudformation-pipeline-actions.ts | 8 +- .../test/integ.pipeline-code-commit-build.ts | 4 +- .../test/test.pipeline.ts | 4 +- 20 files changed, 280 insertions(+), 282 deletions(-) create mode 100644 packages/@aws-cdk/aws-codebuild/lib/codepipeline-artifacts.ts create mode 100644 packages/@aws-cdk/aws-codebuild/lib/codepipeline-source.ts create mode 100644 packages/@aws-cdk/aws-codebuild/lib/no-artifacts.ts create mode 100644 packages/@aws-cdk/aws-codebuild/lib/no-source.ts create mode 100644 packages/@aws-cdk/aws-codebuild/lib/source-types.ts diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index 8bb4d088a57bb..0a5b216a41662 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -42,15 +42,10 @@ methods and attributes. ## Source Build projects are usually associated with a _source_, which is specified via -the `source` property which accepts a class that extends the `BuildSource` -abstract base class. The supported sources are: - -### `NoSource` - -This is the default and implies that no source is associated with this -build project. - -The `buildSpec` option is required in this case. +the `source` property which accepts a class that extends the `Source` +abstract base class. +The default is to have no source associated with the build project; +the `buildSpec` option is required in that case. Here's a CodeBuild project with no source which simply prints `Hello, CodeBuild!`: @@ -69,9 +64,10 @@ const repository = new codecommit.Repository(this, 'MyRepo', { repositoryName: ' new codebuild.Project(this, 'MyFirstCodeCommitProject', { source: new codebuild.CodeCommitSource({ repository }), }); +// or: codebuild.Source.codeCommit({ repository }) ``` -### `S3BucketSource` +### `S3Source` Create a CodeBuild project with an S3 bucket as the source: @@ -81,18 +77,17 @@ import s3 = require('@aws-cdk/aws-s3'); const bucket = new s3.Bucket(this, 'MyBucket'); new codebuild.Project(this, 'MyProject', { - source: new codebuild.S3BucketSource({ + source: new codebuild.S3Source({ bucket: bucket, path: 'path/to/file.zip', }), }); +// or: codebuild.Source.s3({ +// bucket: bucket, +// path: 'path/to/file.zip', +// }) ``` -### `CodePipelineSource` - -Used as a special source type when a CodeBuild project is used as a -CodePipeline action. - ### `GitHubSource` and `GitHubEnterpriseSource` These source types can be used to build code from a GitHub repository. @@ -107,6 +102,7 @@ const gitHubSource = new codebuild.GitHubSource({ codebuild.FilterGroup.inEventOf(codebuild.EventAction.PUSH).andBranchIs('master'), ], // optional, by default all pushes and Pull Requests will trigger a build }); +// or: codebuild.Source.gitHub({ ... }) ``` To provide GitHub credentials, please either go to AWS CodeBuild Console to connect @@ -121,6 +117,23 @@ aws codebuild import-source-credentials --server-type GITHUB --auth-type PERSONA This source type can be used to build code from a BitBucket repository. +## CodePipeline + +To add a CodeBuild Project as an Action to CodePipeline, +use the `PipelineProject` class instead of `Project`. +It's a simple class that doesn't allow you to specify `sources`, +`secondarySources`, `artifacts` or `secondaryArtifacts`, +as these are handled by setting input and output CodePipeline `Artifact` instances on the Action, +instead of setting them on the Project. + +```typescript +const project = new codebuild.PipelineProject(this, 'Project', { + // properties as above... +}) +``` + +For more details, see the readme of the `@aws-cdk/@aws-codepipeline` package. + ## Caching You can save time when your project builds by using a cache. A cache can store reusable pieces of your build environment and use them across multiple builds. Your build project can use one of two types of caching: Amazon S3 or local. In general, S3 caching is a good option for small and intermediate build artifacts that are more expensive to build than to download. Local caching is a good option for large intermediate build artifacts because the cache is immediately available on the build host. @@ -231,7 +244,7 @@ const project = new codebuild.Project(this, 'MyProject', { }), ], secondaryArtifacts: [ - new codebuild.S3BucketBuildArtifacts({ + new codebuild.S3Artifacts({ identifier: 'artifact2', bucket: bucket, path: 'some/path', @@ -324,7 +337,7 @@ const securityGroup = new ec2.SecurityGroup(stack, 'SecurityGroup1', { vpc: vpc, }); new Project(stack, 'MyProject', { - buildScriptAsset: new assets.ZipDirectoryAsset(stack, 'Bundle', { path: 'script_bundle' }), + buildScript: new assets.ZipDirectoryAsset(stack, 'Bundle', { path: 'script_bundle' }), securityGroups: [securityGroup], vpc: vpc }); diff --git a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts index 53c9e835a2766..aaa4cf45b735c 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts @@ -5,7 +5,7 @@ import { Project } from './project'; /** * Properties common to all Artifacts classes. */ -export interface BuildArtifactsProps { +export interface ArtifactsProps { /** * The artifact identifier. * This property is required on secondary artifacts. @@ -16,11 +16,15 @@ export interface BuildArtifactsProps { /** * Artifacts definition for a CodeBuild Project. */ -export abstract class BuildArtifacts { +export abstract class Artifacts { + public static s3(props: S3ArtifactsProps): S3Artifacts { + return new S3Artifacts(props); + } + public readonly identifier?: string; protected abstract readonly type: string; - constructor(props: BuildArtifactsProps) { + constructor(props: ArtifactsProps) { this.identifier = props.identifier; } @@ -47,38 +51,9 @@ export abstract class BuildArtifacts { } /** - * A `NO_ARTIFACTS` CodeBuild Project Artifact definition. - * This is the default artifact type, - * if none was specified when creating the Project - * (and the source was not specified to be CodePipeline). - * *Note*: the `NO_ARTIFACTS` type cannot be used as a secondary artifact, - * and because of that, you're not allowed to specify an identifier for it. - */ -export class NoBuildArtifacts extends BuildArtifacts { - protected readonly type = 'NO_ARTIFACTS'; - - constructor() { - super({}); - } -} - -/** - * CodePipeline Artifact definition for a CodeBuild Project. - * *Note*: this type cannot be used as a secondary artifact, - * and because of that, you're not allowed to specify an identifier for it. - */ -export class CodePipelineBuildArtifacts extends BuildArtifacts { - protected readonly type = 'CODEPIPELINE'; - - constructor() { - super({}); - } -} - -/** - * Construction properties for {@link S3BucketBuildArtifacts}. + * Construction properties for {@link S3Artifacts}. */ -export interface S3BucketBuildArtifactsProps extends BuildArtifactsProps { +export interface S3ArtifactsProps extends ArtifactsProps { /** * The name of the output bucket. */ @@ -119,10 +94,10 @@ export interface S3BucketBuildArtifactsProps extends BuildArtifactsProps { /** * S3 Artifact definition for a CodeBuild Project. */ -export class S3BucketBuildArtifacts extends BuildArtifacts { +export class S3Artifacts extends Artifacts { protected readonly type = 'S3'; - constructor(private readonly props: S3BucketBuildArtifactsProps) { + constructor(private readonly props: S3ArtifactsProps) { super(props); } diff --git a/packages/@aws-cdk/aws-codebuild/lib/codepipeline-artifacts.ts b/packages/@aws-cdk/aws-codebuild/lib/codepipeline-artifacts.ts new file mode 100644 index 0000000000000..4d7352edbb5d6 --- /dev/null +++ b/packages/@aws-cdk/aws-codebuild/lib/codepipeline-artifacts.ts @@ -0,0 +1,14 @@ +import { Artifacts } from './artifacts'; + +/** + * CodePipeline Artifact definition for a CodeBuild Project. + * *Note*: this type cannot be used as a secondary artifact, + * and because of that, you're not allowed to specify an identifier for it. + */ +export class CodePipelineArtifacts extends Artifacts { + protected readonly type = 'CODEPIPELINE'; + + constructor() { + super({}); + } +} diff --git a/packages/@aws-cdk/aws-codebuild/lib/codepipeline-source.ts b/packages/@aws-cdk/aws-codebuild/lib/codepipeline-source.ts new file mode 100644 index 0000000000000..fb72a6b605a4a --- /dev/null +++ b/packages/@aws-cdk/aws-codebuild/lib/codepipeline-source.ts @@ -0,0 +1,15 @@ +import { Source } from './source'; +import { CODEPIPELINE_SOURCE_ARTIFACTS_TYPE } from './source-types'; + +/** + * CodePipeline Source definition for a CodeBuild Project. + * *Note*: this type cannot be used as a secondary source, + * and because of that, you're not allowed to specify an identifier for it. + */ +export class CodePipelineSource extends Source { + public readonly type = CODEPIPELINE_SOURCE_ARTIFACTS_TYPE; + + constructor() { + super({}); + } +} diff --git a/packages/@aws-cdk/aws-codebuild/lib/no-artifacts.ts b/packages/@aws-cdk/aws-codebuild/lib/no-artifacts.ts new file mode 100644 index 0000000000000..c99aa11cdbd55 --- /dev/null +++ b/packages/@aws-cdk/aws-codebuild/lib/no-artifacts.ts @@ -0,0 +1,19 @@ +import { Artifacts } from './artifacts'; + +/** + * A `NO_ARTIFACTS` CodeBuild Project Artifact definition. + * This is the default artifact type, + * if none was specified when creating the Project + * (and the source was not specified to be CodePipeline). + * *Note*: the `NO_ARTIFACTS` type cannot be used as a secondary artifact, + * and because of that, you're not allowed to specify an identifier for it. + * + * This class is private to the @aws-codebuild package. + */ +export class NoArtifacts extends Artifacts { + protected readonly type = 'NO_ARTIFACTS'; + + constructor() { + super({}); + } +} diff --git a/packages/@aws-cdk/aws-codebuild/lib/no-source.ts b/packages/@aws-cdk/aws-codebuild/lib/no-source.ts new file mode 100644 index 0000000000000..eb45884c6f1e7 --- /dev/null +++ b/packages/@aws-cdk/aws-codebuild/lib/no-source.ts @@ -0,0 +1,19 @@ +import { Source } from './source'; +import { NO_SOURCE_TYPE } from './source-types'; + +/** + * A `NO_SOURCE` CodeBuild Project Source definition. + * This is the default source type, + * if none was specified when creating the Project. + * *Note*: the `NO_SOURCE` type cannot be used as a secondary source, + * and because of that, you're not allowed to specify an identifier for it. + * + * This class is private to the aws-codebuild package. + */ +export class NoSource extends Source { + public readonly type = NO_SOURCE_TYPE; + + constructor() { + super({}); + } +} diff --git a/packages/@aws-cdk/aws-codebuild/lib/pipeline-project.ts b/packages/@aws-cdk/aws-codebuild/lib/pipeline-project.ts index 7d6e4e4193e09..979850701a862 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/pipeline-project.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/pipeline-project.ts @@ -1,7 +1,7 @@ import cdk = require('@aws-cdk/cdk'); -import { CodePipelineBuildArtifacts } from './artifacts'; +import { CodePipelineArtifacts } from './codepipeline-artifacts'; +import { CodePipelineSource } from './codepipeline-source'; import { CommonProjectProps, Project } from './project'; -import { CodePipelineSource } from './source'; // tslint:disable-next-line:no-empty-interface export interface PipelineProjectProps extends CommonProjectProps { @@ -14,7 +14,7 @@ export class PipelineProject extends Project { constructor(scope: cdk.Construct, id: string, props?: PipelineProjectProps) { super(scope, id, { source: new CodePipelineSource(), - artifacts: new CodePipelineBuildArtifacts(), + artifacts: new CodePipelineArtifacts(), ...props }); } diff --git a/packages/@aws-cdk/aws-codebuild/lib/project.ts b/packages/@aws-cdk/aws-codebuild/lib/project.ts index db24bd78f3277..c31de3e368a04 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/project.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/project.ts @@ -7,11 +7,15 @@ import events = require('@aws-cdk/aws-events'); import iam = require('@aws-cdk/aws-iam'); import kms = require('@aws-cdk/aws-kms'); import { Aws, Construct, IResource, Lazy, PhysicalName, Resource, ResourceIdentifiers, Stack } from '@aws-cdk/cdk'; -import { BuildArtifacts, CodePipelineBuildArtifacts, NoBuildArtifacts } from './artifacts'; +import { Artifacts } from './artifacts'; import { BuildSpec, mergeBuildSpecs } from './build-spec'; import { Cache } from './cache'; import { CfnProject } from './codebuild.generated'; -import { BuildSource, NoSource, SourceType } from './source'; +import { CodePipelineArtifacts } from './codepipeline-artifacts'; +import { NoArtifacts } from './no-artifacts'; +import { NoSource } from './no-source'; +import { Source } from './source'; +import { CODEPIPELINE_SOURCE_ARTIFACTS_TYPE, NO_SOURCE_TYPE } from './source-types'; const CODEPIPELINE_TYPE = 'CODEPIPELINE'; const S3_BUCKET_ENV = 'SCRIPT_S3_BUCKET'; @@ -385,14 +389,14 @@ export interface CommonProjectProps { * * @default - No asset build script. */ - readonly buildScriptAsset?: assets.Asset; + readonly buildScript?: assets.ZipDirectoryAsset; /** * The script in the asset to run. * * @default build.sh */ - readonly buildScriptAssetEntrypoint?: string; + readonly buildScriptEntrypoint?: string; /** * Service Role to assume while running the build. @@ -504,15 +508,15 @@ export interface ProjectProps extends CommonProjectProps { * * @default - NoSource */ - readonly source?: BuildSource; + readonly source?: Source; /** * Defines where build artifacts will be stored. - * Could be: PipelineBuildArtifacts, NoBuildArtifacts and S3BucketBuildArtifacts. + * Could be: PipelineBuildArtifacts, NoArtifacts and S3Artifacts. * - * @default NoBuildArtifacts + * @default NoArtifacts */ - readonly artifacts?: BuildArtifacts; + readonly artifacts?: Artifacts; /** * The secondary sources for the Project. @@ -521,7 +525,7 @@ export interface ProjectProps extends CommonProjectProps { * @default - No secondary sources. * @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-multi-in-out.html */ - readonly secondarySources?: BuildSource[]; + readonly secondarySources?: Source[]; /** * The secondary artifacts for the Project. @@ -530,7 +534,7 @@ export interface ProjectProps extends CommonProjectProps { * @default - No secondary artifacts. * @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-multi-in-out.html */ - readonly secondaryArtifacts?: BuildArtifacts[]; + readonly secondaryArtifacts?: Artifacts[]; } /** @@ -610,10 +614,10 @@ export class Project extends ProjectBase { */ public readonly projectName: string; - private readonly source: BuildSource; + private readonly source: Source; private readonly buildImage: IBuildImage; - private readonly _secondarySources: BuildSource[]; - private readonly _secondaryArtifacts: BuildArtifacts[]; + private readonly _secondarySources: Source[]; + private readonly _secondaryArtifacts: Artifacts[]; private _securityGroups: ec2.ISecurityGroup[] = []; constructor(scope: Construct, id: string, props: ProjectProps) { @@ -621,8 +625,8 @@ export class Project extends ProjectBase { physicalName: props.projectName, }); - if (props.buildScriptAssetEntrypoint && !props.buildScriptAsset) { - throw new Error('To use buildScriptAssetEntrypoint, supply buildScriptAsset as well.'); + if (props.buildScriptEntrypoint && !props.buildScript) { + throw new Error('To use buildScriptEntrypoint, supply buildScript as well.'); } this.role = props.role || new iam.Role(this, 'Role', { @@ -650,13 +654,13 @@ export class Project extends ProjectBase { const environmentVariables = props.environmentVariables || {}; let buildSpec = props.buildSpec; - if (props.buildScriptAsset) { - environmentVariables[S3_BUCKET_ENV] = { value: props.buildScriptAsset.s3BucketName }; - environmentVariables[S3_KEY_ENV] = { value: props.buildScriptAsset.s3ObjectKey }; + if (props.buildScript) { + environmentVariables[S3_BUCKET_ENV] = { value: props.buildScript.s3BucketName }; + environmentVariables[S3_KEY_ENV] = { value: props.buildScript.s3ObjectKey }; - const runScript = this.buildImage.runScriptBuildspec(props.buildScriptAssetEntrypoint || 'build.sh'); + const runScript = this.buildImage.runScriptBuildspec(props.buildScriptEntrypoint || 'build.sh'); buildSpec = buildSpec ? mergeBuildSpecs(buildSpec, runScript) : runScript; - props.buildScriptAsset.grantRead(this.role); + props.buildScript.grantRead(this.role); } // Render the source and add in the buildspec @@ -665,7 +669,7 @@ export class Project extends ProjectBase { throw new Error(`Badge is not supported for source type ${this.source.type}`); } - if (this.source.type === SourceType.None && (buildSpec === undefined || !buildSpec.isImmediate)) { + if (this.source.type === NO_SOURCE_TYPE && (buildSpec === undefined || !buildSpec.isImmediate)) { throw new Error("If the Project's source is NoSource, you need to provide a concrete buildSpec"); } @@ -758,7 +762,7 @@ export class Project extends ProjectBase { * @param secondarySource the source to add as a secondary source * @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-multi-in-out.html */ - public addSecondarySource(secondarySource: BuildSource): void { + public addSecondarySource(secondarySource: Source): void { if (!secondarySource.identifier) { throw new Error('The identifier attribute is mandatory for secondary sources'); } @@ -772,7 +776,7 @@ export class Project extends ProjectBase { * @param secondaryArtifact the artifact to add as a secondary artifact * @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-multi-in-out.html */ - public addSecondaryArtifact(secondaryArtifact: BuildArtifacts): any { + public addSecondaryArtifact(secondaryArtifact: Artifacts): any { if (!secondaryArtifact.identifier) { throw new Error("The identifier attribute is mandatory for secondary artifacts"); } @@ -785,7 +789,7 @@ export class Project extends ProjectBase { */ protected validate(): string[] { const ret = new Array(); - if (this.source.type === SourceType.CodePipeline) { + if (this.source.type === CODEPIPELINE_SOURCE_ARTIFACTS_TYPE) { if (this._secondarySources.length > 0) { ret.push('A Project with a CodePipeline Source cannot have secondary sources. ' + "Use the CodeBuild Pipeline Actions' `extraInputs` property instead"); @@ -925,13 +929,13 @@ export class Project extends ProjectBase { return props.artifacts; } if (this.source._toSourceJSON().type === CODEPIPELINE_TYPE) { - return new CodePipelineBuildArtifacts(); + return new CodePipelineArtifacts(); } else { - return new NoBuildArtifacts(); + return new NoArtifacts(); } } - private validateCodePipelineSettings(artifacts: BuildArtifacts) { + private validateCodePipelineSettings(artifacts: Artifacts) { const sourceType = this.source._toSourceJSON().type; const artifactsType = artifacts.toArtifactsJSON().type; diff --git a/packages/@aws-cdk/aws-codebuild/lib/source-types.ts b/packages/@aws-cdk/aws-codebuild/lib/source-types.ts new file mode 100644 index 0000000000000..fb9137ec66e8c --- /dev/null +++ b/packages/@aws-cdk/aws-codebuild/lib/source-types.ts @@ -0,0 +1,7 @@ +export const NO_SOURCE_TYPE = 'NO_SOURCE'; +export const CODEPIPELINE_SOURCE_ARTIFACTS_TYPE = 'CODEPIPELINE'; +export const S3_SOURCE_TYPE = 'S3'; +export const CODECOMMIT_SOURCE_TYPE = 'CODECOMMIT'; +export const GITHUB_SOURCE_TYPE = 'GITHUB'; +export const GITHUB_ENTERPRISE_SOURCE_TYPE = 'GITHUB_ENTERPRISE'; +export const BITBUCKET_SOURCE_TYPE = 'BITBUCKET'; diff --git a/packages/@aws-cdk/aws-codebuild/lib/source.ts b/packages/@aws-cdk/aws-codebuild/lib/source.ts index 5595bcc58b065..27d4fd155dd75 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/source.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/source.ts @@ -3,11 +3,18 @@ import iam = require('@aws-cdk/aws-iam'); import s3 = require('@aws-cdk/aws-s3'); import { CfnProject } from './codebuild.generated'; import { Project } from './project'; +import { + BITBUCKET_SOURCE_TYPE, + CODECOMMIT_SOURCE_TYPE, + GITHUB_ENTERPRISE_SOURCE_TYPE, + GITHUB_SOURCE_TYPE, + S3_SOURCE_TYPE +} from './source-types'; /** * Properties common to all Source classes. */ -export interface BuildSourceProps { +export interface SourceProps { /** * The source identifier. * This property is required on secondary sources. @@ -18,12 +25,32 @@ export interface BuildSourceProps { /** * Source provider definition for a CodeBuild Project. */ -export abstract class BuildSource { +export abstract class Source { + public static s3(props: S3SourceProps): S3Source { + return new S3Source(props); + } + + public static codeCommit(props: CodeCommitSourceProps): CodeCommitSource { + return new CodeCommitSource(props); + } + + public static gitHub(props: GitHubSourceProps): GitHubSource { + return new GitHubSource(props); + } + + public static gitHubEnterprise(props: GitHubEnterpriseSourceProps): GitHubEnterpriseSource { + return new GitHubEnterpriseSource(props); + } + + public static bitBucket(props: BitBucketSourceProps): BitBucketSource { + return new BitBucketSource(props); + } + public readonly identifier?: string; - public abstract readonly type: SourceType; + public abstract readonly type: string; public readonly badgeSupported: boolean = false; - constructor(props: BuildSourceProps) { + constructor(props: SourceProps) { this.identifier = props.identifier; } @@ -60,25 +87,10 @@ export abstract class BuildSource { } } -/** - * A `NO_SOURCE` CodeBuild Project Source definition. - * This is the default source type, - * if none was specified when creating the Project. - * *Note*: the `NO_SOURCE` type cannot be used as a secondary source, - * and because of that, you're not allowed to specify an identifier for it. - */ -export class NoSource extends BuildSource { - public readonly type: SourceType = SourceType.None; - - constructor() { - super({}); - } -} - /** * The construction properties common to all build sources that are backed by Git. */ -export interface GitBuildSourceProps extends BuildSourceProps { +interface GitSourceProps extends SourceProps { /** * The depth of history to download. Minimum value is 0. * If this value is 0, greater than 25, or not provided, @@ -90,10 +102,10 @@ export interface GitBuildSourceProps extends BuildSourceProps { /** * A common superclass of all build sources that are backed by Git. */ -export abstract class GitBuildSource extends BuildSource { +abstract class GitSource extends Source { private readonly cloneDepth?: number; - protected constructor(props: GitBuildSourceProps) { + protected constructor(props: GitSourceProps) { super(props); this.cloneDepth = props.cloneDepth; @@ -381,7 +393,7 @@ export class FilterGroup { /** * The construction properties common to all third-party build sources that are backed by Git. */ -export interface ThirdPartyGitBuildSourceProps extends GitBuildSourceProps { +interface ThirdPartyGitSourceProps extends GitSourceProps { /** * Whether to send notifications on your build's start and end. * @@ -409,13 +421,13 @@ export interface ThirdPartyGitBuildSourceProps extends GitBuildSourceProps { /** * A common superclass of all third-party build sources that are backed by Git. */ -export abstract class ThirdPartyGitBuildSource extends GitBuildSource { +abstract class ThirdPartyGitSource extends GitSource { public readonly badgeSupported: boolean = true; protected readonly webhookFilters: FilterGroup[]; private readonly reportBuildStatus: boolean; private readonly webhook?: boolean; - protected constructor(props: ThirdPartyGitBuildSourceProps) { + protected constructor(props: ThirdPartyGitSourceProps) { super(props); this.webhook = props.webhook; @@ -445,15 +457,15 @@ export abstract class ThirdPartyGitBuildSource extends GitBuildSource { /** * Construction properties for {@link CodeCommitSource}. */ -export interface CodeCommitSourceProps extends GitBuildSourceProps { +export interface CodeCommitSourceProps extends GitSourceProps { readonly repository: codecommit.IRepository; } /** * CodeCommit Source definition for a CodeBuild project. */ -export class CodeCommitSource extends GitBuildSource { - public readonly type: SourceType = SourceType.CodeCommit; +export class CodeCommitSource extends GitSource { + public readonly type = CODECOMMIT_SOURCE_TYPE; private readonly repo: codecommit.IRepository; constructor(props: CodeCommitSourceProps) { @@ -479,9 +491,9 @@ export class CodeCommitSource extends GitBuildSource { } /** - * Construction properties for {@link S3BucketSource}. + * Construction properties for {@link S3Source}. */ -export interface S3BucketSourceProps extends BuildSourceProps { +export interface S3SourceProps extends SourceProps { readonly bucket: s3.IBucket; readonly path: string; } @@ -489,12 +501,12 @@ export interface S3BucketSourceProps extends BuildSourceProps { /** * S3 bucket definition for a CodeBuild project. */ -export class S3BucketSource extends BuildSource { - public readonly type: SourceType = SourceType.S3; +export class S3Source extends Source { + public readonly type = S3_SOURCE_TYPE; private readonly bucket: s3.IBucket; private readonly path: string; - constructor(props: S3BucketSourceProps) { + constructor(props: S3SourceProps) { super(props); this.bucket = props.bucket; this.path = props.path; @@ -514,23 +526,10 @@ export class S3BucketSource extends BuildSource { } } -/** - * CodePipeline Source definition for a CodeBuild Project. - * *Note*: this type cannot be used as a secondary source, - * and because of that, you're not allowed to specify an identifier for it. - */ -export class CodePipelineSource extends BuildSource { - public readonly type: SourceType = SourceType.CodePipeline; - - constructor() { - super({}); - } -} - /** * Construction properties for {@link GitHubSource} and {@link GitHubEnterpriseSource}. */ -export interface GitHubSourceProps extends ThirdPartyGitBuildSourceProps { +export interface GitHubSourceProps extends ThirdPartyGitSourceProps { /** * The GitHub account/user that owns the repo. * @@ -549,8 +548,8 @@ export interface GitHubSourceProps extends ThirdPartyGitBuildSourceProps { /** * GitHub Source definition for a CodeBuild project. */ -export class GitHubSource extends ThirdPartyGitBuildSource { - public readonly type: SourceType = SourceType.GitHub; +export class GitHubSource extends ThirdPartyGitSource { + public readonly type = GITHUB_SOURCE_TYPE; private readonly httpsCloneUrl: string; constructor(props: GitHubSourceProps) { @@ -568,7 +567,7 @@ export class GitHubSource extends ThirdPartyGitBuildSource { /** * Construction properties for {@link GitHubEnterpriseSource}. */ -export interface GitHubEnterpriseSourceProps extends ThirdPartyGitBuildSourceProps { +export interface GitHubEnterpriseSourceProps extends ThirdPartyGitSourceProps { /** * The HTTPS URL of the repository in your GitHub Enterprise installation. */ @@ -585,8 +584,8 @@ export interface GitHubEnterpriseSourceProps extends ThirdPartyGitBuildSourcePro /** * GitHub Enterprise Source definition for a CodeBuild project. */ -export class GitHubEnterpriseSource extends ThirdPartyGitBuildSource { - public readonly type: SourceType = SourceType.GitHubEnterprise; +export class GitHubEnterpriseSource extends ThirdPartyGitSource { + public readonly type = GITHUB_ENTERPRISE_SOURCE_TYPE; private readonly httpsCloneUrl: string; private readonly ignoreSslErrors?: boolean; @@ -607,7 +606,7 @@ export class GitHubEnterpriseSource extends ThirdPartyGitBuildSource { /** * Construction properties for {@link BitBucketSource}. */ -export interface BitBucketSourceProps extends ThirdPartyGitBuildSourceProps { +export interface BitBucketSourceProps extends ThirdPartyGitSourceProps { /** * The BitBucket account/user that owns the repo. * @@ -626,8 +625,8 @@ export interface BitBucketSourceProps extends ThirdPartyGitBuildSourceProps { /** * BitBucket Source definition for a CodeBuild project. */ -export class BitBucketSource extends ThirdPartyGitBuildSource { - public readonly type: SourceType = SourceType.BitBucket; +export class BitBucketSource extends ThirdPartyGitSource { + public readonly type = BITBUCKET_SOURCE_TYPE; private readonly httpsCloneUrl: any; constructor(props: BitBucketSourceProps) { @@ -669,19 +668,6 @@ export class BitBucketSource extends ThirdPartyGitBuildSource { } } -/** - * Source types for CodeBuild Project - */ -export enum SourceType { - None = 'NO_SOURCE', - CodeCommit = 'CODECOMMIT', - CodePipeline = 'CODEPIPELINE', - GitHub = 'GITHUB', - GitHubEnterprise = 'GITHUB_ENTERPRISE', - BitBucket = 'BITBUCKET', - S3 = 'S3', -} - function set2Array(set: Set): T[] { const ret: T[] = []; set.forEach(el => ret.push(el)); diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.ts index 93383eb9eef38..7f64afc8f5a9e 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.ts @@ -12,7 +12,7 @@ const bucket = new s3.Bucket(stack, 'MyBucket', { }); new codebuild.Project(stack, 'MyProject', { - source: new codebuild.S3BucketSource({ + source: new codebuild.S3Source({ bucket, path: 'path/to/my/source.zip', }), diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-secondary-sources-artifacts.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-secondary-sources-artifacts.ts index 8f33a229d4561..954a026ddbcf5 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-secondary-sources-artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-secondary-sources-artifacts.ts @@ -15,14 +15,14 @@ new codebuild.Project(stack, 'MyProject', { version: '0.2', }), secondarySources: [ - new codebuild.S3BucketSource({ + new codebuild.S3Source({ bucket, path: 'some/path', identifier: 'AddSource1', }), ], secondaryArtifacts: [ - new codebuild.S3BucketBuildArtifacts({ + new codebuild.S3Artifacts({ bucket, path: 'another/path', name: 'name', diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.ts index 1f00f2953829a..d0e23266ca0be 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.ts @@ -8,7 +8,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-cdk-codebuild-project-shell'); new Project(stack, 'MyProject', { - buildScriptAsset: new assets.ZipDirectoryAsset(stack, 'Bundle', { path: 'script_bundle' }) + buildScript: new assets.ZipDirectoryAsset(stack, 'Bundle', { path: 'script_bundle' }) }); app.synth(); diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.ts index 9d118d04ed81b..d019c3d2e6e02 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.ts @@ -18,7 +18,7 @@ const securityGroup = new ec2.SecurityGroup(stack, 'SecurityGroup1', { vpc, }); new Project(stack, 'MyProject', { - buildScriptAsset: new assets.ZipDirectoryAsset(stack, 'Bundle', { path: 'script_bundle' }), + buildScript: new assets.ZipDirectoryAsset(stack, 'Bundle', { path: 'script_bundle' }), securityGroups: [securityGroup], vpc }); diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index c71fc625ac0b0..f78af2f5f2425 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -6,6 +6,8 @@ import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; import codebuild = require('../lib'); +import { CodePipelineSource } from '../lib/codepipeline-source'; +import { NoSource } from '../lib/no-source'; // tslint:disable:object-literal-key-quotes @@ -14,10 +16,7 @@ export = { 'with CodePipeline source'(test: Test) { const stack = new cdk.Stack(); - const source = new codebuild.CodePipelineSource(); - new codebuild.Project(stack, 'MyProject', { - source - }); + new codebuild.PipelineProject(stack, 'MyProject'); expect(stack).toMatch({ "Resources": { @@ -144,7 +143,7 @@ export = { const repo = new codecommit.Repository(stack, 'MyRepo', { repositoryName: 'hello-cdk' }); - const source = new codebuild.CodeCommitSource({ repository: repo, cloneDepth: 2 }); + const source = codebuild.Source.codeCommit({ repository: repo, cloneDepth: 2 }); new codebuild.Project(stack, 'MyProject', { source @@ -298,7 +297,7 @@ export = { const bucket = new s3.Bucket(stack, 'MyBucket'); new codebuild.Project(stack, 'MyProject', { - source: new codebuild.S3BucketSource({ + source: new codebuild.S3Source({ bucket, path: 'path/to/source.zip', }), @@ -475,7 +474,7 @@ export = { const stack = new cdk.Stack(); new codebuild.Project(stack, 'Project', { - source: new codebuild.GitHubSource({ + source: codebuild.Source.gitHub({ owner: 'testowner', repo: 'testrepo', cloneDepth: 3, @@ -520,7 +519,7 @@ export = { const pushFilterGroup = codebuild.FilterGroup.inEventOf(codebuild.EventAction.PUSH); new codebuild.Project(stack, 'MyProject', { - source: new codebuild.GitHubEnterpriseSource({ + source: codebuild.Source.gitHubEnterprise({ httpsCloneUrl: 'https://github.testcompany.com/testowner/testrepo', ignoreSslErrors: true, cloneDepth: 4, @@ -570,7 +569,7 @@ export = { const stack = new cdk.Stack(); new codebuild.Project(stack, 'Project', { - source: new codebuild.BitBucketSource({ + source: codebuild.Source.bitBucket({ owner: 'testowner', repo: 'testrepo', cloneDepth: 5, @@ -635,7 +634,7 @@ export = { description: 'Example', }); new codebuild.Project(stack, 'MyProject', { - source: new codebuild.S3BucketSource({ + source: new codebuild.S3Source({ bucket, path: 'path/to/source.zip', }), @@ -684,7 +683,7 @@ export = { test.throws(() => new codebuild.Project(stack, 'MyProject', { - source: new codebuild.S3BucketSource({ + source: new codebuild.S3Source({ bucket, path: 'path/to/source.zip', }), @@ -705,7 +704,7 @@ export = { }); test.throws(() => new codebuild.Project(stack, 'MyProject', { - source: new codebuild.S3BucketSource({ + source: codebuild.Source.s3({ bucket, path: 'path/to/source.zip', }), @@ -765,7 +764,7 @@ export = { buildSpec: codebuild.BuildSpec.fromObject({ version: '0.2', }), - artifacts: new codebuild.S3BucketBuildArtifacts({ + artifacts: codebuild.Artifacts.s3({ path: 'some/path', name: 'some_name', bucket, @@ -795,7 +794,10 @@ export = { version: '0.2', }), secondarySources: [ - new codebuild.CodePipelineSource(), + new codebuild.S3Source({ + bucket: new s3.Bucket(stack, 'MyBucket'), + path: 'path', + }), ], }); }, /identifier/); @@ -805,11 +807,9 @@ export = { 'are not allowed for a Project with CodePipeline as Source'(test: Test) { const stack = new cdk.Stack(); - const project = new codebuild.Project(stack, 'MyProject', { - source: new codebuild.CodePipelineSource(), - }); + const project = new codebuild.PipelineProject(stack, 'MyProject'); - project.addSecondarySource(new codebuild.S3BucketSource({ + project.addSecondarySource(new codebuild.S3Source({ bucket: new s3.Bucket(stack, 'MyBucket'), path: 'some/path', identifier: 'id', @@ -826,13 +826,13 @@ export = { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); const project = new codebuild.Project(stack, 'MyProject', { - source: new codebuild.S3BucketSource({ + source: new codebuild.S3Source({ bucket, path: 'some/path', }), }); - project.addSecondarySource(new codebuild.S3BucketSource({ + project.addSecondarySource(new codebuild.S3Source({ bucket, path: 'another/path', identifier: 'source1', @@ -861,7 +861,7 @@ export = { version: '0.2', }), secondaryArtifacts: [ - new codebuild.S3BucketBuildArtifacts({ + new codebuild.S3Artifacts({ bucket: new s3.Bucket(stack, 'MyBucket'), path: 'some/path', name: 'name', @@ -875,11 +875,9 @@ export = { 'are not allowed for a Project with CodePipeline as Source'(test: Test) { const stack = new cdk.Stack(); - const project = new codebuild.Project(stack, 'MyProject', { - source: new codebuild.CodePipelineSource(), - }); + const project = new codebuild.PipelineProject(stack, 'MyProject'); - project.addSecondaryArtifact(new codebuild.S3BucketBuildArtifacts({ + project.addSecondaryArtifact(new codebuild.S3Artifacts({ bucket: new s3.Bucket(stack, 'MyBucket'), path: 'some/path', name: 'name', @@ -897,13 +895,13 @@ export = { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); const project = new codebuild.Project(stack, 'MyProject', { - source: new codebuild.S3BucketSource({ + source: new codebuild.S3Source({ bucket, path: 'some/path', }), }); - project.addSecondaryArtifact(new codebuild.S3BucketBuildArtifacts({ + project.addSecondaryArtifact(new codebuild.S3Artifacts({ bucket, path: 'another/path', name: 'name', @@ -928,10 +926,7 @@ export = { 'both source and artifacs are set to CodePipeline'(test: Test) { const stack = new cdk.Stack(); - new codebuild.Project(stack, 'MyProject', { - source: new codebuild.CodePipelineSource(), - artifacts: new codebuild.CodePipelineBuildArtifacts() - }); + new codebuild.PipelineProject(stack, 'MyProject'); expect(stack).to(haveResource('AWS::CodeBuild::Project', { "Source": { @@ -956,62 +951,16 @@ export = { test.done(); }, - - 'if source is set to CodePipeline, and artifacts are not set, they are defaulted to CodePipeline'(test: Test) { - const stack = new cdk.Stack(); - - new codebuild.Project(stack, 'MyProject', { - source: new codebuild.CodePipelineSource() - }); - - expect(stack).to(haveResource('AWS::CodeBuild::Project', { - "Source": { - "Type": "CODEPIPELINE" - }, - "Artifacts": { - "Type": "CODEPIPELINE" - }, - "ServiceRole": { - "Fn::GetAtt": [ - "MyProjectRole9BBE5233", - "Arn" - ] - }, - "Environment": { - "Type": "LINUX_CONTAINER", - "PrivilegedMode": false, - "Image": "aws/codebuild/standard:1.0", - "ComputeType": "BUILD_GENERAL1_SMALL" - } - })); - - test.done(); - }, - - 'fails if one of source/artifacts is set to CodePipeline and the other isn\'t'(test: Test) { - const stack = new cdk.Stack(); - - test.throws(() => new codebuild.Project(stack, 'MyProject', { - source: new codebuild.CodePipelineSource(), - artifacts: new codebuild.NoBuildArtifacts() - }), /Both source and artifacts must be set to CodePipeline/); - - test.throws(() => new codebuild.Project(stack, 'YourProject', { - source: new codebuild.CodeCommitSource({ - repository: new codecommit.Repository(stack, 'MyRepo', { repositoryName: 'boo' }) - }), - artifacts: new codebuild.CodePipelineBuildArtifacts() - }), /Both source and artifacts must be set to CodePipeline/); - - test.done(); - } - } + }, }, 'events'(test: Test) { const stack = new cdk.Stack(); const project = new codebuild.Project(stack, 'MyProject', { - source: new codebuild.CodePipelineSource() + source: new codebuild.S3Source({ + bucket: new s3.Bucket(stack, 'MyBucket'), + path: 'path', + }), }); project.onBuildFailed('OnBuildFailed', { target: { bind: () => ({ arn: 'ARN', id: 'ID' }) }}); @@ -1130,8 +1079,7 @@ export = { 'environment variables can be overridden at the project level'(test: Test) { const stack = new cdk.Stack(); - new codebuild.Project(stack, 'Project', { - source: new codebuild.CodePipelineSource(), + new codebuild.PipelineProject(stack, 'Project', { environment: { environmentVariables: { FOO: { value: '1234' }, @@ -1196,7 +1144,12 @@ export = { '.metricXxx() methods can be used to obtain Metrics for CodeBuild projects'(test: Test) { const stack = new cdk.Stack(); - const project = new codebuild.Project(stack, 'MyBuildProject', { source: new codebuild.CodePipelineSource() }); + const project = new codebuild.Project(stack, 'MyBuildProject', { + source: new codebuild.S3Source({ + bucket: new s3.Bucket(stack, 'MyBucket'), + path: 'path', + }), + }); const metricBuilds = project.metricBuilds(); test.same(metricBuilds.dimensions!.ProjectName, project.projectName); @@ -1224,7 +1177,10 @@ export = { test.throws(() => { new codebuild.Project(stack, 'MyProject', { - source: new codebuild.CodePipelineSource(), + source: new codebuild.S3Source({ + bucket: new s3.Bucket(stack, 'MyBucket'), + path: 'path', + }), environment: invalidEnvironment, }); }, /Windows images do not support the Small ComputeType/); @@ -1236,7 +1192,7 @@ export = { const stack = new cdk.Stack(); interface BadgeValidationTestCase { - source: codebuild.BuildSource, + source: codebuild.Source, shouldPassValidation: boolean } @@ -1244,10 +1200,10 @@ export = { const bucket = new s3.Bucket(stack, 'MyBucket'); const cases: BadgeValidationTestCase[] = [ - { source: new codebuild.NoSource(), shouldPassValidation: false }, - { source: new codebuild.CodePipelineSource(), shouldPassValidation: false }, + { source: new NoSource(), shouldPassValidation: false }, + { source: new CodePipelineSource(), shouldPassValidation: false }, { source: new codebuild.CodeCommitSource({ repository: repo }), shouldPassValidation: false }, - { source: new codebuild.S3BucketSource({ bucket, path: 'path/to/source.zip' }), shouldPassValidation: false }, + { source: new codebuild.S3Source({ bucket, path: 'path/to/source.zip' }), shouldPassValidation: false }, { source: new codebuild.GitHubSource({ owner: 'awslabs', repo: 'aws-cdk' }), shouldPassValidation: true }, { source: new codebuild.GitHubEnterpriseSource({ httpsCloneUrl: 'url' }), shouldPassValidation: true }, { source: new codebuild.BitBucketSource({ owner: 'awslabs', repo: 'aws-cdk' }), shouldPassValidation: true } diff --git a/packages/@aws-cdk/aws-codebuild/test/test.project.ts b/packages/@aws-cdk/aws-codebuild/test/test.project.ts index 8f7372d58b471..06a4350721561 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.project.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.project.ts @@ -5,7 +5,6 @@ import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; import path = require('path'); import codebuild = require('../lib'); -import { Cache, LocalCacheMode } from '../lib/cache'; // tslint:disable:object-literal-key-quotes @@ -16,7 +15,10 @@ export = { // WHEN new codebuild.Project(stack, 'Project', { - source: new codebuild.CodePipelineSource(), + source: new codebuild.S3Source({ + bucket: new Bucket(stack, 'Bucket'), + path: 'path', + }), buildSpec: codebuild.BuildSpec.fromSourceFilename('hello.yml'), }); @@ -36,7 +38,6 @@ export = { // WHEN new codebuild.Project(stack, 'Project', { - source: new codebuild.CodePipelineSource(), buildSpec: codebuild.BuildSpec.fromObject({ phases: ['say hi'] }) }); @@ -56,7 +57,6 @@ export = { test.throws(() => { new codebuild.Project(stack, 'Project', { - source: new codebuild.NoSource(), }); }, /you need to provide a concrete buildSpec/); @@ -69,7 +69,6 @@ export = { test.throws(() => { new codebuild.Project(stack, 'Project', { - source: new codebuild.NoSource(), buildSpec: codebuild.BuildSpec.fromSourceFilename('bla.yml'), }); }, /you need to provide a concrete buildSpec/); @@ -157,8 +156,8 @@ export = { // WHEN new codebuild.Project(stack, 'Project', { - buildScriptAsset: new assets.ZipDirectoryAsset(stack, 'Asset', { path: path.join(__dirname, 'script_bundle') }), - buildScriptAssetEntrypoint: 'build.sh', + buildScript: new assets.ZipDirectoryAsset(stack, 'Asset', { path: path.join(__dirname, 'script_bundle') }), + buildScriptEntrypoint: 'build.sh', }); // THEN @@ -198,8 +197,11 @@ export = { // WHEN new codebuild.Project(stack, 'Project', { - source: new codebuild.CodePipelineSource(), - cache: Cache.bucket(new Bucket(stack, 'Bucket'), { + source: new codebuild.S3Source({ + bucket: new Bucket(stack, 'SourceBucket'), + path: 'path', + }), + cache: codebuild.Cache.bucket(new Bucket(stack, 'Bucket'), { prefix: "cache-prefix" }) }); @@ -231,8 +233,12 @@ export = { // WHEN new codebuild.Project(stack, 'Project', { - source: new codebuild.CodePipelineSource(), - cache: Cache.local(LocalCacheMode.Custom, LocalCacheMode.DockerLayer, LocalCacheMode.Source) + source: new codebuild.S3Source({ + bucket: new Bucket(stack, 'Bucket'), + path: 'path', + }), + cache: codebuild.Cache.local(codebuild.LocalCacheMode.Custom, codebuild.LocalCacheMode.DockerLayer, + codebuild.LocalCacheMode.Source) }); // THEN @@ -256,7 +262,10 @@ export = { // WHEN new codebuild.Project(stack, 'Project', { - source: new codebuild.CodePipelineSource() + source: new codebuild.S3Source({ + bucket: new Bucket(stack, 'Bucket'), + path: 'path', + }), }); // THEN diff --git a/packages/@aws-cdk/aws-codepipeline-actions/README.md b/packages/@aws-cdk/aws-codepipeline-actions/README.md index c671db8b4bfa3..511dc036e7908 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/README.md +++ b/packages/@aws-cdk/aws-codepipeline-actions/README.md @@ -183,17 +183,6 @@ new codepipeline.Pipeline(this, 'MyPipeline', { }); ``` -The `PipelineProject` utility class is a simple sugar around the `Project` -class, it's equivalent to: - -```ts -const project = new codebuild.Project(this, 'MyProject', { - source: new codebuild.CodePipelineSource(), - artifacts: new codebuild.CodePipelineBuildArtifacts(), - // rest of the properties from PipelineProject are passed unchanged... -} -``` - The default category of the CodeBuild Action is `Build`; if you want a `Test` Action instead, override the `type` property: diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts index f9fcedf104f00..6636a35bca7c3 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts @@ -1,5 +1,5 @@ import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert'; -import { CodePipelineBuildArtifacts, CodePipelineSource, Project } from '@aws-cdk/aws-codebuild'; +import codebuild = require('@aws-cdk/aws-codebuild'); import { Repository } from '@aws-cdk/aws-codecommit'; import codepipeline = require('@aws-cdk/aws-codepipeline'); import { Role } from '@aws-cdk/aws-iam'; @@ -37,11 +37,7 @@ export = { /** Build! */ - const buildArtifacts = new CodePipelineBuildArtifacts(); - const project = new Project(stack, 'MyBuildProject', { - source: new CodePipelineSource(), - artifacts: buildArtifacts, - }); + const project = new codebuild.PipelineProject(stack, 'MyBuildProject'); const buildOutput = new codepipeline.Artifact('OutputYo'); const buildAction = new cpactions.CodeBuildAction({ diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts index 684adf25b73f1..f8c6bbe4fffad 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts @@ -19,9 +19,7 @@ const sourceAction = new cpactions.CodeCommitSourceAction({ pollForSourceChanges: true, }); -const project = new codebuild.Project(stack, 'MyBuildProject', { - source: new codebuild.CodePipelineSource(), -}); +const project = new codebuild.PipelineProject(stack, 'MyBuildProject'); const buildAction = new cpactions.CodeBuildAction({ actionName: 'build', project, diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts index d66abf0b94a25..c57d945c65adc 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts @@ -33,9 +33,7 @@ export = { actions: [source], }); - const project = new codebuild.Project(stack, 'MyBuildProject', { - source: new codebuild.CodePipelineSource() - }); + const project = new codebuild.PipelineProject(stack, 'MyBuildProject'); pipeline.addStage({ name: 'build', actions: [