aws / aws/aws-cdk

(pipelines): support caching in simple synth action

Open
#13,043 8 comments 30 reactions 0 assignees View on GitHub
@aws-cdk/pipelines effort/medium feature-request p1
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

Allow for [caching](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-codebuild-readme.html#caching) in [SimpleSynthAction](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_pipelines.SimpleSynthAction.html)

### Use Case

Allowing for caching in the SimpleSynthAction makes it easy to decrease build times - e.g. caching incremental typescript lambda builds, caching npm packages, or even re-use unchanged resources - which can become quite incredible when using CDK Pipelines (like when a re-build is triggered after a pipeline self-mutate).

### Proposed Solution

This would simply add a couple additional optional fields (`cache` and `cachePaths`) onto the SimpleSynthAction static methods, which could be used like:

```typescript
SimpleSynthAction.standardNpmSynth({
sourceArtifact,
cloudAssemblyArtifact,
installCommand: 'npm ci --cache .npm',
buildCommand: "npm run ci-build",
cachePaths: ['dist/**/*', '.npm/**/*', './.git/objects/**/*', '.git-hash'],
cache: Cache.bucket(new Bucket(this, 'Cache'))
});
```

Currently, you can either create the whole build configuration yourself or copy and modify the source of the SimpleSynthAction, but these both seem untenable considering how easy it is to pass these options to the constructed internals.

### Other

These parameters just get passed along into the SimpleSynthAction without any direct transformation, so this is really simple:

```typescript
const buildSpec = BuildSpec.fromObject({
....
cache: {
paths: this.props.cachePaths
}
});
```

and

```typescript
const project = new PipelineProject(scope, 'CdkBuildProject', {
...
cache: this.props.cache
});
```

[SimpleSynthAction docs](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_pipelines.SimpleSynthAction.html)
[SimpleSynthAction source](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/pipelines/lib/synths/simple-synth-action.ts)
[CodeBuild caching](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-codebuild-readme.html#caching)

* [x] :wave: I may be able to implement this feature request
* [ ] :warning: This feature might incur a breaking change

---

This is a :rocket: Feature Request

Contributor guide

Open the contributing guide

Research direction

Start with packages/@aws-cdk/pipelines/lib/synths/simple-synth-action.ts and read the SimpleSynthAction static methods and their options. Verify how cachePaths reaches BuildSpec and cache reaches PipelineProject; done means the optional inputs are accepted and forwarded, with the documented caching use case supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, devops
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.