ecr-assets: incomplete .dockerignore support
See original GitHub issueIntroduced by #4104.
CDK does not handle the common “exclude everything except” pattern for .dockerignore files:
# Ignore everything
*
# Allow files and directories
!/src/**
Quote from Docker docs:
… you may want to specify which files to include in the context, rather than which to exclude. To achieve this, specify * as the first pattern, followed by one or more ! exception patterns.
With the current implementation the first ‘star’ glob effectively excludes everything from the asset folder dyring synth stage. Consequently, deploy stage fails to build the docker image.
Reproduction Steps
- Create a
.dockerignore
file next to youDockerfile
with * pattern, like this:# Ignore everything * # Allow files and directories !/src/**
- Run
cdk deploy
Error Log
unable to prepare context: unable to evaluate symlinks in Dockerfile path: CreateFile C:\Dev\GitHub\playground\EcsWindowsCluster\src\Deployment\cdk.out\asset.1ebc9d3ac2033816c4abb63e4afd69d350b4aba8704cc9236b82ea520b74f4b0\Dockerfile: The system cannot find the file specified.
❌ win failed: Error: docker build --tag 305168429857.dkr.ecr.eu-west-1.amazonaws.com/cdk/win:latest cdk.out\asset.1ebc9d3ac2033816c4abb63e4afd69d350b4aba8704cc9236b82ea520b74f4b0 exited with error code 1
docker build --tag 305168429857.dkr.ecr.eu-west-1.amazonaws.com/cdk/win:latest cdk.out\asset.1ebc9d3ac2033816c4abb63e4afd69d350b4aba8704cc9236b82ea520b74f4b0 exited with error code 1
Environment
- CLI Version : 1.12.0 (build 923055e)
- OS : Windows
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
ecr-assets: incomplete .dockerignore support #20712 - GitHub
Describe the bug When creating a DockerImageAsset based on a directory with a .dockerignore file, the ignore list is not parsed correctly in ......
Read more >aws-cdk/aws-ecr-assets module - AWS Documentation
dockerignore . The ignoreMode property controls how the set of ignore patterns is interpreted. The recommended setting for Docker image assets is IgnoreMode....
Read more >@aws-cdk/aws-ecr-assets | Yarn - Package Manager
This module allows bundling Docker images as assets. Images from Dockerfile. Images are built from a local Docker context directory (with a Dockerfile...
Read more >monocdk: Versions - Openbase
Starting with this release, Node 12 is no longer supported and customers ... aws-ecr-assets: support the --platform option when building docker images ...
Read more >@aws-cdk/aws-ecr-assets - npm
dockerignore . The ignoreMode property controls how the set of ignore patterns is interpreted. The recommended setting for Docker image assets ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have today the same problem with:
cdk 1.103.0 (build bc13a66)
@aws-cdk/assets 1.103.0
OS: osx 11.3.1
typescript language
Here’s what I’ve found:
copyDirectory
walks through each directory recursively, making sure they’re not excluded. If the directory is excluded, its files and sub-directories won’t be explored:https://github.com/aws/aws-cdk/blob/dcd8d1e8ccc7330ea14e292b5ccc855e0e15bbdf/packages/%40aws-cdk/assets/lib/fs/copy.ts#L21-L23
shouldExclude
on the other hand matches.dockerignore
lines against the path it’s being provided:https://github.com/aws/aws-cdk/blob/dcd8d1e8ccc7330ea14e292b5ccc855e0e15bbdf/packages/%40aws-cdk/assets/lib/fs/utils.ts#L20
So in the case of
publish/good.txt
,publish
is evaluated against each.dockerignore
line.*
matchespublish
, and excludes the directory!publish\*
does not matchpublish
copyDirectory
leaves the directory early, without having checked its filesWe need to figure out how to affect either
shouldExclude
orcopyDirectory
to prevent the recursion from stopping early