Gathering detailed insights and metrics for @balena/dockerignore
Gathering detailed insights and metrics for @balena/dockerignore
Gathering detailed insights and metrics for @balena/dockerignore
Gathering detailed insights and metrics for @balena/dockerignore
dockerignore is a file filter library compatible with Docker and the node-ignore API
npm install @balena/dockerignore
99.7
Supply Chain
99.5
Quality
79.8
Maintenance
100
Vulnerability
99.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3 Stars
256 Commits
4 Watching
1 Branches
16 Contributors
Updated on 21 Feb 2023
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-6.7%
185,487
Compared to previous day
Last week
3.4%
1,082,067
Compared to previous week
Last month
7.7%
4,531,477
Compared to previous month
Last year
20.9%
43,151,168
Compared to previous year
10
dockerignore
is a file filter library fully compatible with Docker's .dockerignore
file, exposing the
same API as the popular ignore package for the
.gitignore
format.
dockerignore
is also:
.dockerignore
format.docker build
on Windows and Linux.ignore
?The .dockerignore
spec has several differences from .gitignore
:
*
in .gitignore
matches everything, whereas in .dockerignore
it only matches files in the
current directory (like glob). This difference is important when whitelisting after a *
rule.abc
in .gitignore
matches all abc
files and directories, however deeply nested, whereas
in .dockerignore
it matches only at ./abc
and not in subdirectories like ./somedir/abc
..gitignore
, when a parent directory is ignored, subdirectories cannot be re-added (using
!
) since git
simply avoids walking through the subtree as an optimization. With
.dockerignore
, a subdirectory can be re-added even if a parent directory has been ignored.ignore
?The entire API. dockerignore
started as a fork of
node-ignore, and even reuses the same index.d.ts
file
for TypeScript definitions. Under the hood, node-ignore
's matching logic was rewritten to closely
match Docker's implementation (modeled mainly around
dockerignore.go
and fileutils.go).
dockerignore
works with Node.js version 8 and above, on Linux, macOS and Windows.
The code is compiled with Babel.
1npm install --save @balena/dockerignore
1const ignore = require('@balena/dockerignore') 2const ig = ignore().add(['.abc/*', '!.abc/d/'])
Typescript type definitions are also included:
1import ignore from '@balena/dockerignore' 2const ig = ignore().add(['.abc/*', '!.abc/d/'])
1const paths = [ 2 '.abc/a.js', // filtered out 3 '.abc/d/e.js' // included 4] 5 6ig.filter(paths) // ['.abc/d/e.js'] 7ig.ignores('.abc/a.js') // true
1paths.filter(ig.createFilter()); // ['.abc/d/e.js']
1ig.filter(['.abc\\a.js', '.abc\\d\\e.js']) 2// if the code above runs on windows, the result will be 3// ['.abc\\d\\e.js']
dockerignore
behaves just like the Docker CLI ("docker build") in relation to the backslash (\
)
and forward slash (/
) characters:
OS | Location | Slash (/ ) | Backslash (\ ) |
---|---|---|---|
Linux, macOS | .dockerignore | Path separator | Escape character |
Linux, macOS | filter() , ignores() | Path separator | Part of file name |
Windows | .dockerignore | Path separator | Path separator |
Windows | filter() , ignores() | Path separator | Path separator |
This means that forward slashes can be used in the .dockerignore
file for cross-platform
compatibility. This is consistent with how Windows works generally: both forward slashes
and backslashes are accepted as path separators by the Command Prompt (cmd.exe) or
PowerShell, and by library functions like the Golang
filepath.Clean or the Node.js
path.normalize.
The use of the backslash as an escape character (Linux and macOS only) is not documented in the
.dockerignore
specification. "Reasonable" uses are probably to escape the few characters that
have a special meaning in the .dockerignore
file, namely "*#!\"
(excluding the double quotes),
as opposed to characters that have a special meaning in regular
expressions
generally. The "escaping" behavior for any other characters (e.g. '\\b'
) is undefined and subject
to implementation-specific interpretation that may change at any time.
Leading and trailing slashes (or backslashes on Windows) are removed from .dockerignore
patterns,
so '/a'
, 'a/'
and '/a/'
are all equivalent to 'a'
in a .dockerignore
file, and they all
anchor to the "leftmost" directory when matching against relative paths. For example, pattern 'a'
is compared with 'x'
for a given path 'x/y/z'
. This follows Docker's Golang implementation for
compatibility. Conversely, a given absolute path will not match a non-wildcard pattern. More
examples:
1 ignore().add('a').ignores('a') // true 2 ignore().add('/a').ignores('a') // true 3 ignore().add('/a/').ignores('a') // true 4 ignore().add('a').ignores('/a') // false 5 ignore().add('/a').ignores('/a') // false 6 ignore().add('/a/').ignores('/a') // false
Considering pattern slash removal, the cases above may be reduced to:
1 ignore().add('a').ignores('a') // true 2 ignore().add('a').ignores('/a') // false
The 'false' outcome for these examples may appear to mismatch the behavior of "docker build", when the source argument for the Dockerfile ADD or COPY instructions is an absolute path (starting with a slash). The explanation is that docker converts absolute source paths to relative paths (relative to the "build context") prior to pattern matching: https://github.com/moby/moby/blob/v19.03.8/pkg/archive/archive.go#L806 https://github.com/moby/moby/blob/v19.03.8/pkg/archive/archive.go#L825
... while dockerignore
mirrors the implementation of the pattern matcher itself. The advice is
for your application to do the same as the docker CLI: use relative paths for pattern matching.
This is also generally more portable across different environments: development machine, CI
pipelines, servers or end user devices.
A pattern starting with '#'
(hash) is ignored as a comment. The hash can be prefixed with
a slash or backslash in order to match a file name that also starts with a hash:
1ignore().add('#abc').ignores('#abc') // false 2ignore().add('/#abc').ignores('#abc') // true 3ignore().add('\\#abc').ignores('#abc') // true
This works because of the leading slash removal from patterns described in Absolute Paths.
Patterns starting with '!'
(exclamation mark) define matching exclusions (exceptions) as
documented in the .dockerignore
specification. For
compatibility with Docker's implementation, patterns starting with '/!'
or '!/'
(but not
'/!/'
) will also be considered exclusion patterns, in addition to slash removal described in
Absolute Paths. Backslash escaping as '\\!'
may be used in order to match a
file or directory name that starts with the exclamation mark, but this is only possible on Linux
and macOS, not on Windows. Again, it only behaves this way for compatibility with Docker's
implementation.
Matching is case-insensitive by default, following the ignore
API
(ignorecase).
Note however that Docker performs case-sensitive matching.
Use the ignorecase: false
option to align with Docker's behavior:
1const ig = ignore({ ignorecase: false }) // for case-sensitive matching
String|Ignore
An ignore pattern string, or the Ignore
instanceArray.<pattern>
Array of ignore patterns.Adds a rule or several rules to the current manager.
Returns this
pattern
could either be a line of ignore pattern or a string of multiple ignore patterns, which means we could just ignore().add()
the content of a ignore file:
1ignore() 2.add(fs.readFileSync(filenameOfGitignore).toString()) 3.filter(filenames)
pattern
could also be an ignore
instance, so that we could easily inherit the rules of another Ignore
instance.
Returns Boolean
whether pathname
should be ignored.
1ig.ignores('.abc/a.js') // true
Filters the given array of pathnames, and returns the filtered array.
Array.<path>
The array of pathname
s to be filtered.Creates a filter function which could filter an array of paths with Array.prototype.filter
.
Returns function(path)
the filter function.
Contributions are always welcome!
npm install
docker build
)The initial work on this project was done by Pranay Prakash (@pranaygp) / â–²ZEIT, Kael Zhang (@kaelzhang) and the node-ignore contributors.
Paulo Castro (@pdcastro) / balena.io forked the repository in year 2020 (encouraged by Zeit) and put in a substantial effort on Windows support, cross-platform compatibility and testing, leading to release 1.0.0.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
Found 3/10 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
33 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More