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

[Bug]: Files don't work when copying from outside running directory #673

Closed
arjenvdhave opened this issue Dec 7, 2022 · 7 comments · Fixed by #814
Closed

[Bug]: Files don't work when copying from outside running directory #673

arjenvdhave opened this issue Dec 7, 2022 · 7 comments · Fixed by #814
Labels
bug An issue with the library

Comments

@arjenvdhave
Copy link

Testcontainers version

v0.16.0

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host arch

x86_64 GNU/Linux

Go version

1.19

Docker version

Client:
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.19.2
 Git commit:        baeda1f82a
 Built:             Thu Oct 27 21:30:31 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.19.2
  Git commit:       3056208812
  Built:            Thu Oct 27 21:29:34 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.6.10
  GitCommit:        770bd0108c32f3fb5c73ae1264f7e503fe7b2661.m
 runc:
  Version:          1.1.4
  GitCommit:        
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  compose: Docker Compose (Docker Inc., 2.13.0)

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 134
 Server Version: 20.10.21
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: false
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 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.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 770bd0108c32f3fb5c73ae1264f7e503fe7b2661.m
 runc version: 
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 6.0.10-arch2-1
 Operating System: EndeavourOS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 31.08GiB
 Name: arjen-dell
 ID: 3CVQ:MB6O:CG3P:4X6U:3NIR:LOV6:NWHO:QAH7:7OYO:MMMN:ZJX3:ZTXE
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

What happened?

When using the Files to copy a directory from my host to the container it doesn't copy the contents of the dir but the complete path.

req := testcontainers.ContainerRequest{
		Image: "amacneil/dbmate",
		Files: []testcontainers.ContainerFile{{
			HostFilePath:      "/home/myname/migrations/",
			ContainerFilePath: "/tmp",
			FileMode:          700,
		}},
		WaitingFor: wait.ForExit(),
		Cmd:        []string{"up"},
	}

I expect that the contents of /home/myname/migrations/ is copied into /tmp in the container.
Instead it creates /tmp/home/myname/migrations/

I also tried using ../../migrations as a path but this would create a migrations dir in the root instead of in the configured /tmp

Relevant log output

No response

Additional information

No response

@arjenvdhave arjenvdhave added the bug An issue with the library label Dec 7, 2022
@mdelapenya
Copy link
Collaborator

Hi @arjenvdhave sorry for the radio silence, I started paternity leave on Dec 10th, until the end of January. I'm going to check the repro code you shared. Will ping you here with my results

@mdelapenya
Copy link
Collaborator

mdelapenya commented Feb 10, 2023

Mmm IIUC your expectations are on the contents of the TAR file produced by the CopyDirToContainer: you see all the files in the target directory BUT using the entire, original file path.

So, given this example:

/home/myname/migrations
  - a.txr
  - b.txt
  - dir
      - d.txt

you would expect all the files, and subdirs to be hanging from migrations, only, and the current behaviour keeps the original path. Is this correct?

If so, I'm able to reproduce it in the current tests, passing an absolute path as the ContainerFile.HostFilePath. Will investigate if it's related on how the TAR code is honouring the original path, or if it's elsewhere

Thanks for the report!

@mdelapenya
Copy link
Collaborator

I think I have a working prototype, but want check with you all first: do we expect that the TAR file should compress the file from the last directory from HostFilePath?

If so, using your example "/home/myname/migrations/", will create a TAR file from migrations, not containing the previous, parent file paths.

If this assumption is correct, simply changing how the current TAR code generates the file headers would be enough

@arjenvdhave
Copy link
Author

This sounds like how i expect it should be working.
It should work like the -v from a docker run correct?

if I do docker run -v $(pwd)/some-dir/some-dir2:/tmp/ someImage it will mount all contents of $(pwd)/some-dir/some-dir2 in /tmp and not all the parent directories

@mdelapenya
Copy link
Collaborator

Makes sense to me. I'm preparing a PR now

@mdelapenya
Copy link
Collaborator

@arjenvdhave feel free to comment on the PR 🙏 A review is also much appreciated

@arjenvdhave
Copy link
Author

Tnx, i looked at the code and it looks ok
however i just started with golang :)

so not sure if my opinion is trust worthy 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants