- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4.3k
fix(ecr-assets): incorrect handling of nested excludes in .dockerignore #34810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| ➡️ PR build request submitted to  A maintainer must now check the pipeline and add the  | 
9e88188    to
    3913643      
    Compare
  
    | Please make sure that your PR title confirms to the conventional commit standard ( | 
| * @see {@link https://github.com/aws/aws-cdk/issues/13636} for more info on the bug this option fixes. | ||
| * @default true if the feature flag DOCKER_IGNORE_NESTED_EXCLUDE_FIX is set to true, otherwise false | ||
| */ | ||
| readonly copyNestedExcludes?: boolean; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you copy "excludes" ?
Does this mean respectedNestedIgnoreFiles ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"respect" seems to be a better description. I've renamed it to dockerIgnoreRespectNestedExcludes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a bit verbose. Can you shorten it? For example, do both ignore and exclude not refer to the same thing? So do we need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
respectNestedDockerIgnores?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"exclude" means something that is excluded from the .dockerignore, so an exclude and ignore are not the same thing, they're the opposite.
**            # Ignore
!build/*.js   # Exclude  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is verbose, but I don't think there's a good way to shorten it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, are you saying that:
In nested .dockerignore files, we do respect positive (ignore) declarations, but we didn't use to respect negative (dont-ignore) declarations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we were ignoring more files than necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I'm leaning towards this not needing a flag. Because we will only ever include more files into the bundle, right? We will never accidentally include too few files.
Which means the chances if this breaking someone are vanishingly small?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @rix0rrr , we were ignoring more files than necessary.
The behavior of including more files in the docker image is undefined. Chance of breaking change is still small regardless. If you think it's safe to remove the feature flag, I can do so.
3913643    to
    06574ad      
    Compare
  
    06574ad    to
    315d2ff      
    Compare
  
    af3d07b    to
    4e93672      
    Compare
  
    4e93672    to
    23d512a      
    Compare
  
    | AWS CodeBuild CI Report
 Powered by github-codebuild-logs, available on the AWS Serverless Application Repository | 
| Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). | 
| Comments on closed issues and PRs are hard for our team to see. | 
Issue #13636
Closes #13636.
Reason for this change
Fixes a bug where asset copying does not correctly process .dockerignore files. CDK did not copy files excluded by a nested exclude pattern in
.dockerignore.Description of changes
Added a new method in
DockerIgnoreStrategythat determines whether a directory is fully or partially ignored. The method isDockerIgnoreStrategy.completelyIgnoresand if it returns true, it means that the directory is ignored AND that all of its children are ignored as well. For directories that are ignored but not "completely" ignored, the copyDirectory function will still walk through them.As this changes the behaviour of asset copying, this can potientally be a breaking change. Therefore, a new feature flag is added which enables this fix. The feature flag is
DOCKER_IGNORE_NESTED_EXCLUDE_FIX.Describe any new or updated permissions being added
No new permissions are added.
Description of how you validated changes
Unit tests and integration tests are added.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license