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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悶 Inconsistent file mounting behavior when name isn't specified #7374

Open
sagikazarmark opened this issue May 14, 2024 · 0 comments
Open

Comments

@sagikazarmark
Copy link
Contributor

sagikazarmark commented May 14, 2024

What is the issue?

I'm supposed to be able to do this:

dag.Container().WithFile("", file)
 
dag.Directory().WithFile("", file)

When no path is specified, the file should be mounted in the current directory with it's current name.

Unfortunately, Dagger behaves differently in different scenarios which makes mounting files like this unreliable.

(The unfortunate consequence is every higher level API that allows mounting a file in a lower level container requires a second name parameter too)

Dagger version

dagger v0.11.4 (registry.dagger.io/engine) darwin/arm64

Steps to reproduce

package main

type Repro struct{}

func (m *Repro) EmptyDir() *Container {
	dir := dag.Directory().
		WithDirectory("bar", dag.Directory().WithFile("", dag.CurrentModule().Source().File("baz.conf")))

	return dag.Container().
		From("cgr.dev/chainguard/wolfi-base").
		WithDirectory("/etc/foo", dir).
		WithExec([]string{"tree", "/etc/foo"})
}

func (m *Repro) Dir() *Container {
	dir := dag.Directory().
		WithDirectory("bar", dag.Directory())

	dir2 := dir.Directory("bar").WithFile("", dag.CurrentModule().Source().File("baz.conf"))

	dir = dir.WithDirectory("bar", dir2)

	return dag.Container().
		From("cgr.dev/chainguard/wolfi-base").
		WithDirectory("/etc/foo", dir).
		WithExec([]string{"tree", "/etc/foo"})
}

func (m *Repro) Ctr() *Container {
	dir := dag.Directory().
		WithDirectory("bar", dag.Directory())

	ctr := dag.Container().
		From("cgr.dev/chainguard/wolfi-base").
		WithDirectory("/etc/foo", dir).
		WithExec([]string{"tree", "/etc/foo"})

	dir2 := ctr.Directory("/etc/foo/bar").WithFile("", dag.CurrentModule().Source().File("baz.conf"))

	return ctr.WithDirectory("/etc/foo/bar", dir2)
}

func (m *Repro) Ctr2() *Container {
	return dag.Container().
		From("cgr.dev/chainguard/wolfi-base").
		WithFile("/etc/foo/bar/", dag.CurrentModule().Source().File("baz.conf")).
		WithExec([]string{"tree", "/etc/foo"})
}

func (m *Repro) File(path *File) *Container {
	return dag.Container().
		From("cgr.dev/chainguard/wolfi-base").
		WithFile("/etc/foo/bar/", path).
		WithExec([]string{"tree", "/etc/foo"})
}
touch baz.conf
dagger call empty-dir stdout
dagger call dir stdout
dagger call ctr stdout
dagger call ctr2 stdout
dagger call file --path ./baz.conf stdout

nix run github:dagger/nix#dagger -- call empty-dir stdout
nix run github:dagger/nix#dagger -- call dir stdout
nix run github:dagger/nix#dagger -- call ctr stdout
nix run github:dagger/nix#dagger -- call ctr2 stdout
nix run github:dagger/nix#dagger -- call file --path ./baz.conf stdout

Log output

dagger call empty-dir stdout
/etc/foo
`-- bar
    `-- baz.conf

1 directories, 1 files

dagger call dir stdout
/etc/foo
`-- bar

0 directories, 1 files

dagger call ctr stdout
/etc/foo
`-- bar

1 directories, 0 files

dagger call ctr2 stdout
/etc/foo
`-- bar
    `-- bar

1 directories, 1 files

dagger call file --path ./baz.conf stdout
/etc/foo
`-- bar
    `-- bar

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

No branches or pull requests

1 participant