Skip to content
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

dockerignore: Exclamation mark with the pattern ** isn't including all sub directories's files but only the top level one #2919

Closed
roi-meir opened this issue Jan 7, 2021 · 1 comment

Comments

@roi-meir
Copy link

roi-meir commented Jan 7, 2021

Description
I the dockerignore file exclamation mark with the pattern ** isn't including all sub directories's files but only the top level one.
This issue prevent building a dockerignore file that allow coping of only specific extensions.
I'm not sure if it is the intended behaviour or not but I didn't see it documented anywhere.

Steps to reproduce the issue:

  1. Create the following directory structure:
top_level_python_file.py
top_level_txt_file.txt
subdir/subdir_python_file.py
  1. Create a .dockerignore with the following lines
*
!**/*.py
  1. Run docker build with COPY . .

Describe the results you received:
only top_level_python_file.py is copied and not subdir_python_file.py

Describe the results you expected:
I expected all the files ending with .py to be copied.

Additional information you deem important (e.g. issue happens only occasionally):
The same happens where the pattern is !subdir/**/*.py. In such case the file subdir/another_subdir/subdir_python_file.py also won't be copied.

I think it happens because the code in archive.go that check for prefix of the pattern and not use the pattern regex

  	dirSlash := relFilePath + string(filepath.Separator)
	for _, pat := range pm.Patterns() {
		if !pat.Exclusion() {
			continue
		}
		if strings.HasPrefix(pat.String()+string(filepath.Separator), dirSlash) {
			// found a match - so can't skip this dir
			return nil
		}
	}

I will be happy to suggest a patch if you think this issue is indeed a bug and not the intended behaviour.

Output of docker version:

Client: Docker Engine - Community
 Cloud integration: 1.0.4
 Version:           20.10.2
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        2291f61
 Built:             Mon Dec 28 16:12:42 2020
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.2
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8891c58
  Built:            Mon Dec 28 16:15:23 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  scan: Docker Scan (Docker Inc., v0.5.0)

Server:
 Containers: 66
  Running: 0
  Paused: 0
  Stopped: 66
 Images: 301
 Server Version: 20.10.2
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc version: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.19.121-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 1.942GiB
 Name: docker-desktop
 ID: 3E45:LCYJ:JIUZ:T63O:PEUY:LQFM:N6HQ:UVEX:4DYI:RSGO:ZUR3:KVBX
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 41
  Goroutines: 46
  System Time: 2021-01-07T22:18:06.382286871Z
  EventsListeners: 3
 HTTP Proxy: gateway.docker.internal:3128
 HTTPS Proxy: gateway.docker.internal:3129
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine


Additional environment details (AWS, VirtualBox, physical, etc.):

@roi-meir roi-meir changed the title Exclamation mark with the pattern ** isn't including all sub directories's files but only the top level one. Exclamation mark with the pattern ** isn't including all sub directories's files but only the top level one Jan 7, 2021
@roi-meir roi-meir changed the title Exclamation mark with the pattern ** isn't including all sub directories's files but only the top level one dockerignore: Exclamation mark with the pattern ** isn't including all sub directories's files but only the top level one Jan 7, 2021
@roi-meir
Copy link
Author

roi-meir commented Jan 8, 2021

I see now that this issue is a duplicate of moby/moby#30018 so I'm closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants