(assets): Warn if CDK_OUT Is Within Assets Directory
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
A few times over the years I've been bitten by the same situation; the directory which is specified with `--output` is within the same directory that assets are copied from into the `--output` directory. When assets are copied into the output directory, CDK ends up copying the contents of the output directory, as well as the target assets directory, into the new assets subdirectory. This recursively gets slower and slower the more deployments are made, and there isn't any output to indicate this is happening.
I would like to propose that CDK intelligently examine the location of output based on assets for the deployment and warn or exclude the output from the asset copy operation.
For what it's worth, this may only happen when using a construct like `DockerImageAsset` but I am unsure.
### Use Case
For example:
```
cdk deploy --all --require-approval=never --app "deploy --target=$(pwd)" --output ./.cdk/$(date +%s)
```
For the sake of saying, let's say the directory structure looks like this:
```
repo
|--services
|--svc-api
|--.cdk
|-- 000
|-- 111
|--src
|--...
```
What ends up happening is on next deploy, the entire contents, including `.cdk` are copied into the next deployment directory, so that `repo/serivces/svc-api/.cdk/222` contains `repo/serivces/svc-api/.cdk` which includes the `000` and `111` directories. `.cdk` will grow exponentially larger on disk with each following deploy, and the asset copy step that runs will take longer and longer.
I was experiencing a 10 minute delay locally, when I was reminded of the same situation being encountered in the past.
### Proposed Solution
A warning or error stating that the output directory should be outside of the assets directory, or intelligently ignoring the output directory when assets are copied into it.
An easier path might be to just use the root `.gitignore` settings to ignore files during asset copy, as `.cdk` in my example was already in `.gitignore`.
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.68.0
### Environment details (OS name and version, etc.)
Mac Ventura
Contributor guide
Research direction
Start by reproducing the issue with cdk deploy --all and a timestamped --output directory inside the asset source, especially with DockerImageAsset. Trace the asset copy operation and determine whether it can warn about or exclude the output directory; done means repeated deployments no longer recursively copy prior output, with a clear warning or documented exclusion behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100