#Can Go entrypoint access host directories?

1 messages · Page 1 of 1 (latest)

hollow carbon
#

I'm tried to use the Go SDK on a small go project but it seems I cannot access my host from an entrypoint function.

package main

import (
    "dagger.io/dagger"
    "strings"
)

func main() {
    dagger.ServeCommands(Build)
}

func Build(ctx dagger.Context) (string, error) {
    files, err := ctx.Client().Host().Directory(".").Entries(ctx)
    return strings.Join(files, ","), err
}
dagger do -c ./ci build

# ... logs

█◀┴─┴─╯ █ ERROR [build]
┃       ┃ input:1: host.directory.entries error from sender: context canceled 

Is it me doing something wrong or this capabilities isn't supported for now?

torn grotto
rapid zodiac
#

@hollow carbon Helder is correct, but you will have access to all the files in your project root dir (which is by default your current working directory when invoking dagger do, but can be specified with --project too).

If you only need to access one or a few plaintext files, you can also use the (kind of ugly) workaround of something like dagger do foo --bar "$(cat /the/file/you/want/to/access)", in which case you are essentially just sending the file as a string to the command

hollow carbon
rapid zodiac
# hollow carbon Oh interesting, how can you call for files located at the project root dir? Beca...

Oh so I think you might be hitting a bug I fixed in this PR here: https://github.com/dagger/dagger/pull/5308/files#diff-805c89cdd46f77747c10dfe7ede1a9134caf73687d63abcb0581fb08b8f83fa0R368

Previously, we weren't setting the workdir of the entrypoint process to the actual project dir (mounted at /src). So it's workdir was just /
So when you were trying to load ., you were trying to load the entire / in. I think that gets an error because there are special/weird files under /proc and /sys that can't be imported.

#

As a workaround, you could just import /src instead of . for now. Then when that fix in the PR above is in you can go back to .