CDKv2: `DockerImageAsset` need to execute command before `docker build` / `cdk-asset`
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
I need to execute a shell command before executing `cdk-asset` (that triggers `docker build`) within the generated `CodeBuildAction`.
### Use Case
Preparing the environment for the `docker build` as it otherwise fails.
### Proposed Solution
Add a property to `DockerImageAssetProps`:
```
export interface DockerImageAssetProps extends DockerImageAssetOptions {
/**
* The directory where the Dockerfile is stored
*
* Any directory inside with a name that matches the CDK output folder (cdk.out by default) will be excluded from the asset
*/
readonly directory: string;
// New
prepareCommands : []string;
}
```
These prepareCommands will then be added to the `CodeBuildStep` that executes the `docker build`:
https://github.com/aws/aws-cdk/blob/244135b333007adc1188f0ad8690be4e7526353d/packages/%40aws-cdk/pipelines/lib/codepipeline/codepipeline.ts#L687
### Other Information
Hacky workaround: preprocess generated Cloudformation template using shell scripts after `cdk synth`.
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
v2
### Environment details (OS name and version, etc.)
not relevant
Contributor guide
Research direction
Read packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts around line 687 and trace how DockerImageAssetProps reaches the generated CodeBuildStep. Define the prepareCommands behavior and verify that generated CodeBuild configuration runs those commands before cdk-asset and the Docker build.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, docker, typescript
- Domain
- build-system, cloud, devops
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100