Skip to content

Commit 9714c40

Browse files
authored
chore(codebuild): make examples compile (#17123)
---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 260df31 commit 9714c40

File tree

2 files changed

+52
-32
lines changed

2 files changed

+52
-32
lines changed

packages/@aws-cdk/aws-codebuild/README.md

+50-31
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $ npm i @aws-cdk/aws-codebuild
3030

3131
Import it into your code:
3232

33-
```ts
33+
```ts nofixture
3434
import * as codebuild from '@aws-cdk/aws-codebuild';
3535
```
3636

@@ -56,7 +56,6 @@ CodeBuild!`:
5656
Use an AWS CodeCommit repository as the source of this build:
5757

5858
```ts
59-
import * as codebuild from '@aws-cdk/aws-codebuild';
6059
import * as codecommit from '@aws-cdk/aws-codecommit';
6160

6261
const repository = new codecommit.Repository(this, 'MyRepo', { repositoryName: 'foo' });
@@ -70,10 +69,8 @@ new codebuild.Project(this, 'MyFirstCodeCommitProject', {
7069
Create a CodeBuild project with an S3 bucket as the source:
7170

7271
```ts
73-
import * as codebuild from '@aws-cdk/aws-codebuild';
74-
import * as s3 from '@aws-cdk/aws-s3';
75-
7672
const bucket = new s3.Bucket(this, 'MyBucket');
73+
7774
new codebuild.Project(this, 'MyProject', {
7875
source: codebuild.Source.s3({
7976
bucket: bucket,
@@ -140,7 +137,9 @@ const gitHubSource = codebuild.Source.gitHub({
140137
CodeBuild Projects can produce Artifacts and upload them to S3. For example:
141138

142139
```ts
143-
const project = codebuild.Project(stack, 'MyProject', {
140+
declare const bucket: s3.Bucket;
141+
142+
const project = new codebuild.Project(this, 'MyProject', {
144143
buildSpec: codebuild.BuildSpec.fromObject({
145144
version: '0.2',
146145
}),
@@ -193,7 +192,7 @@ new codebuild.Project(this, 'Project', {
193192
owner: 'awslabs',
194193
repo: 'aws-cdk',
195194
}),
196-
cache: codebuild.Cache.bucket(new Bucket(this, 'Bucket'))
195+
cache: codebuild.Cache.bucket(new s3.Bucket(this, 'Bucket'))
197196
});
198197
```
199198

@@ -214,7 +213,7 @@ new codebuild.Project(this, 'Project', {
214213
}),
215214

216215
// Enable Docker AND custom caching
217-
cache: codebuild.Cache.local(LocalCacheMode.DOCKER_LAYER, LocalCacheMode.CUSTOM)
216+
cache: codebuild.Cache.local(codebuild.LocalCacheMode.DOCKER_LAYER, codebuild.LocalCacheMode.CUSTOM)
218217
});
219218
```
220219

@@ -260,6 +259,8 @@ Note that the `WindowsBuildImage` version of the static methods accepts an optio
260259
which can be either `WindowsImageType.STANDARD`, the default, or `WindowsImageType.SERVER_2019`:
261260

262261
```ts
262+
declare const ecrRepository: ecr.Repository;
263+
263264
new codebuild.Project(this, 'Project', {
264265
environment: {
265266
buildImage: codebuild.WindowsBuildImage.fromEcrRepository(ecrRepository, 'v1.0', codebuild.WindowsImageType.SERVER_2019),
@@ -269,7 +270,7 @@ new codebuild.Project(this, 'Project', {
269270
objectKey: 'path/to/cert.pem',
270271
},
271272
},
272-
...
273+
// ...
273274
})
274275
```
275276

@@ -296,7 +297,7 @@ new codebuild.Project(this, 'Project', {
296297
environment: {
297298
buildImage: codebuild.LinuxGpuBuildImage.DLC_TENSORFLOW_2_1_0_INFERENCE,
298299
},
299-
...
300+
// ...
300301
})
301302
```
302303

@@ -315,7 +316,7 @@ new codebuild.Project(this, 'Project', {
315316
buildImage: codebuild.LinuxGpuBuildImage.awsDeepLearningContainersImage(
316317
'tensorflow-inference', '2.1.0-gpu-py36-cu101-ubuntu18.04', '123456789012'),
317318
},
318-
...
319+
// ...
319320
})
320321
```
321322

@@ -331,10 +332,9 @@ By default, logs will go to cloudwatch.
331332
new codebuild.Project(this, 'Project', {
332333
logging: {
333334
cloudWatch: {
334-
logGroup: new cloudwatch.LogGroup(this, `MyLogGroup`),
335+
logGroup: new logs.LogGroup(this, `MyLogGroup`),
335336
}
336337
},
337-
...
338338
})
339339
```
340340

@@ -347,7 +347,6 @@ new codebuild.Project(this, 'Project', {
347347
bucket: new s3.Bucket(this, `LogBucket`)
348348
}
349349
},
350-
...
351350
})
352351
```
353352

@@ -358,7 +357,7 @@ like GitHub:
358357

359358
```ts
360359
new codebuild.GitHubSourceCredentials(this, 'CodeBuildGitHubCreds', {
361-
accessToken: cdk.SecretValue.secretsManager('my-token'),
360+
accessToken: SecretValue.secretsManager('my-token'),
362361
});
363362
// GitHub Enterprise is almost the same,
364363
// except the class is called GitHubEnterpriseSourceCredentials
@@ -368,8 +367,8 @@ and BitBucket:
368367

369368
```ts
370369
new codebuild.BitBucketSourceCredentials(this, 'CodeBuildBitBucketCreds', {
371-
username: cdk.SecretValue.secretsManager('my-bitbucket-creds', { jsonField: 'username' }),
372-
password: cdk.SecretValue.secretsManager('my-bitbucket-creds', { jsonField: 'password' }),
370+
username: SecretValue.secretsManager('my-bitbucket-creds', { jsonField: 'username' }),
371+
password: SecretValue.secretsManager('my-bitbucket-creds', { jsonField: 'password' }),
373372
});
374373
```
375374

@@ -409,8 +408,10 @@ if you'd rather not have those permissions added,
409408
you can opt out of it when creating the project:
410409

411410
```ts
411+
declare const source: codebuild.Source;
412+
412413
const project = new codebuild.Project(this, 'Project', {
413-
// ...
414+
source,
414415
grantReportGroupPermissions: false,
415416
});
416417
```
@@ -419,10 +420,13 @@ Alternatively, you can specify an ARN of an existing resource group,
419420
instead of a simple name, in your buildspec:
420421

421422
```ts
423+
declare const source: codebuild.Source;
424+
422425
// create a new ReportGroup
423426
const reportGroup = new codebuild.ReportGroup(this, 'ReportGroup');
424427

425428
const project = new codebuild.Project(this, 'Project', {
429+
source,
426430
buildSpec: codebuild.BuildSpec.fromObject({
427431
// ...
428432
reports: {
@@ -438,6 +442,9 @@ const project = new codebuild.Project(this, 'Project', {
438442
If you do that, you need to grant the project's role permissions to write reports to that report group:
439443

440444
```ts
445+
declare const project: codebuild.Project;
446+
declare const reportGroup: codebuild.ReportGroup;
447+
441448
reportGroup.grantWrite(project);
442449
```
443450

@@ -456,8 +463,12 @@ project as a AWS CloudWatch event rule target:
456463

457464
```ts
458465
// start build when a commit is pushed
466+
import * as codecommit from '@aws-cdk/aws-codecommit';
459467
import * as targets from '@aws-cdk/aws-events-targets';
460468

469+
declare const codeCommitRepository: codecommit.Repository;
470+
declare const project: codebuild.Project;
471+
461472
codeCommitRepository.onCommit('OnCommit', {
462473
target: new targets.CodeBuildProject(project),
463474
});
@@ -469,6 +480,10 @@ To define Amazon CloudWatch event rules for build projects, use one of the `onXx
469480
methods:
470481

471482
```ts
483+
import * as targets from '@aws-cdk/aws-events-targets';
484+
declare const fn: lambda.Function;
485+
declare const project: codebuild.Project;
486+
472487
const rule = project.onStateChange('BuildStateChange', {
473488
target: new targets.LambdaFunction(fn)
474489
});
@@ -480,7 +495,11 @@ To define CodeStar Notification rules for Projects, use one of the `notifyOnXxx(
480495
They are very similar to `onXxx()` methods for CloudWatch events:
481496

482497
```ts
483-
const target = new chatbot.SlackChannelConfiguration(stack, 'MySlackChannel', {
498+
import * as chatbot from '@aws-cdk/aws-chatbot';
499+
500+
declare const project: codebuild.Project;
501+
502+
const target = new chatbot.SlackChannelConfiguration(this, 'MySlackChannel', {
484503
slackChannelConfigurationName: 'YOUR_CHANNEL_NAME',
485504
slackWorkspaceId: 'YOUR_SLACK_WORKSPACE_ID',
486505
slackChannelId: 'YOUR_SLACK_CHANNEL_ID',
@@ -495,6 +514,10 @@ CodeBuild Projects can get their sources from multiple places, and produce
495514
multiple outputs. For example:
496515

497516
```ts
517+
import * as codecommit from '@aws-cdk/aws-codecommit';
518+
declare const repo: codecommit.Repository;
519+
declare const bucket: s3.Bucket;
520+
498521
const project = new codebuild.Project(this, 'MyProject', {
499522
secondarySources: [
500523
codebuild.Source.codeCommit({
@@ -586,6 +609,8 @@ to access the resources that it needs by using the
586609
For example:
587610

588611
```ts
612+
declare const loadBalancer: elbv2.ApplicationLoadBalancer;
613+
589614
const vpc = new ec2.Vpc(this, 'MyVPC');
590615
const project = new codebuild.Project(this, 'MyProject', {
591616
vpc: vpc,
@@ -608,7 +633,7 @@ The only supported file system type is `EFS`.
608633
For example:
609634

610635
```ts
611-
new codebuild.Project(stack, 'MyProject', {
636+
new codebuild.Project(this, 'MyProject', {
612637
buildSpec: codebuild.BuildSpec.fromObject({
613638
version: '0.2',
614639
}),
@@ -635,9 +660,9 @@ It returns an object containing the batch service role that was created,
635660
or `undefined` if batch builds could not be enabled, for example if the project was imported.
636661

637662
```ts
638-
import * as codebuild from '@aws-cdk/aws-codebuild';
663+
declare const source: codebuild.Source;
639664

640-
const project = new codebuild.Project(this, 'MyProject', { ... });
665+
const project = new codebuild.Project(this, 'MyProject', { source, });
641666

642667
if (project.enableBatchBuilds()) {
643668
console.log('Batch builds were enabled');
@@ -652,9 +677,7 @@ The default is 60 minutes.
652677
An example of overriding the default follows.
653678

654679
```ts
655-
import * as codebuild from '@aws-cdk/aws-codebuild';
656-
657-
new codebuild.Project(stack, 'MyProject', {
680+
new codebuild.Project(this, 'MyProject', {
658681
timeout: Duration.minutes(90)
659682
});
660683
```
@@ -665,9 +688,7 @@ As an example, to allow your Project to queue for up to thirty (30) minutes befo
665688
use the following code.
666689

667690
```ts
668-
import * as codebuild from '@aws-cdk/aws-codebuild';
669-
670-
new codebuild.Project(stack, 'MyProject', {
691+
new codebuild.Project(this, 'MyProject', {
671692
queuedTimeout: Duration.minutes(30)
672693
});
673694
```
@@ -679,9 +700,7 @@ It is possible to limit the maximum concurrent builds to value between 1 and the
679700
By default there is no explicit limit.
680701

681702
```ts
682-
import * as codebuild from '@aws-cdk/aws-codebuild';
683-
684-
new codebuild.Project(stack, 'MyProject', {
703+
new codebuild.Project(this, 'MyProject', {
685704
concurrentBuildLimit: 1
686705
});
687706
```

packages/@aws-cdk/aws-codebuild/lib/untrusted-code-boundary-policy.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export interface UntrustedCodeBoundaryPolicyProps {
3939
*
4040
* @example
4141
*
42-
* iam.PermissionsBoundary.of(project).apply(new UntrustedCodeBoundaryPolicy(this, 'Boundary'));
42+
* declare const project: codebuild.Project;
43+
* iam.PermissionsBoundary.of(project).apply(new codebuild.UntrustedCodeBoundaryPolicy(this, 'Boundary'));
4344
*/
4445
export class UntrustedCodeBoundaryPolicy extends iam.ManagedPolicy {
4546
constructor(scope: Construct, id: string, props: UntrustedCodeBoundaryPolicyProps = {}) {

0 commit comments

Comments
 (0)