#Accessing parent host directory

1 messages · Page 1 of 1 (latest)

frosty galleon
#

I have my dagger plans in a directory called "ci". I want to be able to access files in the parent directory (project root):

$ tree .
.
├── a.txt
├── b.txt
└── ci
    ├── go.mod
    ├── go.sum
    └── main.go

I'm trying something like this:

src := client.Host().Directory("..")        
ubuntu := client.Container().From("ubuntu").
  WithMountedDirectory("/work", src).       
  WithWorkdir("/work").                     
  WithExec([]string{"ls"})                  

But this gives the following:

panic: input:1: host.directory path ".." escapes workdir; use an absolute path instead

Any hints?

late obsidian
#

You have to compute the path yourself

rose quail
#

Hey @frosty galleon , what you'll want to do is set the engine's workdir to be .. to allow the pipeline to operate from that context. Here's an example creating a dagger client in go with the engine's workdir at ..:

client, err := dagger.Connect(ctx, dagger.WithWorkdir(".."))
ashen pond
#

TIL... I've been putting go.mod in the parent directory to execute dagger pipelines instead of a ci subdirectory. As my source code is typically in the parent directory. The docs are not very clear that selecting the parent directory (relative path) as working dir is possible. Probably something that can be added to the docs with some guidance on where to actually put the pipeline code vs app code.

frosty galleon
opal spruce