fix(container): honor .dockerignore when building a container #277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
What's changed?
When building a container, honor
.dockerignore
present at the root of the build context.Also bumping the version in the same PR (0.4.15 => 0.4.16 since it's a bug fix).
Bonus: we don't need
tar-fs
library anymore!Why do we need this?
Today,
.dockerignore
file at the root of the build context is ignored. Whatever file you list inside it, it will be present in the built image if you doCOPY . .
for example.The library used under the hood (dockerode) supports this, but not if we pass a tar stream when building. We need to pass a list of files so files in
.dockerignore
can be excluded.So, the only way seems to be to list all the files in the build context, and pass them to dockerode so it can filter afterwards.
How have you tested it?
Pretty simple example:
serverless.yml
:The
container/
folder looks like:Dockerfile
is:And
.dockerignore
contains:Once deployed (
serverless deploy
), the files shown are just:hello
anddir1/dir2/test
. Other files have been excluded. This can also be checked in the built image.Checklist
Details