aws / aws/aws-cdk

(pipelines): bundle assets in the `assets` project instead of `synth`

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

Description

### Description

Whenever you use a Docker image in a stack deployed by the `pipelines` module, it gets built in the `assets` project. However, if you use an `asset` bundled in docker (for example, by using a `lambda_nodejs_function` or a `s3_deployment`), the assets get bundled in the `synth` project.

Ideally all assets would be built in the same project, so they can be built in parallel.

### Use Case

I want to use `s3_deployment` inside a `pipeline` to deploy a React app. This is already possible, but the bundling happens in the `synth` step, and not in parallel with the other assets. This adds 15+ minutes to every deploy.

### Proposed Solution

In the `synth` step, just copy or zip the code from the asset, and do the bundling in the `assets` step. This could be a feature flag or an option, so as to not break anyone's workflow that might depend on the current behavior.

I might even just be missing information here and there might be an escape hatch or something else to control this. In this case, the solution might just be documenting that.

### Other information

This is what I've added to my stack:

```typescript
new s3deploy.BucketDeployment(this, 'DeployWithInvalidation', {
sources: [
s3deploy.Source.asset('projects/frontend', {
bundling: {
image: DockerImage.fromRegistry(
'public.ecr.aws/docker/library/node:lts-alpine'
),
command: [
'sh',
'-c',
'yarn install && yarn full-build && cp -R ./build/* /asset-output/',
],
environment: {
// redacted
REACT_APP_API_URL: props.apiURL,
},
},
}),
],
destinationBucket: siteBucket,
distribution,
distributionPaths: ['/*'],
});
```

### Acknowledge

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

Contributor guide

Open the contributing guide

Research direction

Start in the pipelines module and trace how assets move through the synth and assets steps, using the s3_deployment and lambda_nodejs_function cases described here. Done means bundled assets can be built in the assets project, preferably in parallel, without breaking current workflows; determine whether an option or documentation is needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, typescript
Domain
build-system, ci-cd, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.