#go run main.go works but dagger run go run main.go doesn't same.

1 messages · Page 1 of 1 (latest)

serene dragon
#

Go Code:

package main

import (
    "context"
    "fmt"
    "log"
    "os"
    "path/filepath"

    "dagger.io/dagger"
)

func main() {
    workdir := os.TempDir()
    folder := workdir + string(os.PathSeparator)

    for _, subdir := range []string{"foo", "bar", "baz"} {
        folder = filepath.Join(folder, subdir)
        os.Mkdir(folder, 0600)

        for _, file := range []string{".txt", ".rar", ".out"} {
            os.WriteFile(filepath.Join(folder, subdir+file), []byte(subdir), 0600)
        }
    }

    ctx := context.Background()

    client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr), dagger.WithWorkdir(workdir))
    if err != nil {
        log.Println(err)
        return
    }
    defer client.Close()

    daggerdir := client.Host().Directory(".", dagger.HostDirectoryOpts{
        Include: []string{"**/*.rar", "**/*.txt"},
        Exclude: []string{"**.out"},
    })

    folder = "." + string(os.PathSeparator)
    for _, d := range []string{"foo", "bar", "baz"} {
        folder = filepath.Join(folder, d)
        entries, err := daggerdir.Entries(ctx, dagger.DirectoryEntriesOpts{Path: folder})
        if err != nil {
            log.Println(err)
            return
        }
        fmt.Printf("In %s: %v\n", folder, entries)
    }
}

This run ok, when running with go run main.go.
But when running the same file with dagger run go run main.go
It's Output is: cannot configure 'workdir' for existing session (please use --workdir or host.directory with absolute paths instead)

#

Also, a similar thing is happening in Python but a different error maybe.

import os
import sys
import tempfile
from pathlib import Path

import anyio
import dagger


async def main(workdir: anyio.Path):
    # workdir = tempfile.TemporaryDirectory()
    folder = Path(workdir)
    for subdir in ["foo", "bar", "baz"]:
        folder.joinpath(Path(subdir)).mkdir()
        for file in [".txt", ".out", ".rar"]:
            folder.joinpath(Path(subdir), str(subdir + file)).write_text(str(subdir))
        folder = folder / subdir

    cfg = dagger.Config(log_output=sys.stderr, workdir=workdir)

    async with dagger.Connection(cfg) as client:
        daggerdirectory = await client.host().directory(
            ".", include=["**/*.rar", "**/*.txt"], exclude=["**.out"]
        )

        folder = "." + os.sep
        for _, subdir in enumerate(["foo", "bar", "baz"]):
            folder = folder = Path(folder) / subdir
            entries = await daggerdirectory.entries(path=str(folder))
            print("In", subdir, ":", entries)


with tempfile.TemporaryDirectory() as workdir:
    anyio.run(main, anyio.Path(workdir))
#
$ python3 main.py                                                                                                   18:08:49
1: connect
1: > in init
1: starting engine 
⠧ Creating new Engine session1: starting engine [2.31s]
1: starting session 
⠙ Creating new Engine session1: starting session [0.32s]
1: connect DONE

7: upload .
7: > in host.directory .
7: transferring eyJvd25lcl9jbGllbnRfaWQiOiJlemN0ZGJkamk3bmhjYXl3eDN4MWFsbXFvIiwicGF0aCI6Ii4iLCJpbmNsdWRlX3BhdHRlcm5zIjpbIioqLyoucmFyIiwiKiovKi50eHQiXSwiZXhjbHVkZV9wYXR0ZXJucyI6WyIqKi5vdXQiXSwiZm9sbG93X3BhdGhzIjpudWxsLCJyZWFkX3NpbmdsZV9maWxlX29ubHkiOmZhbHNlLCJtYXhfZmlsZV9zaXplIjowfQ==: 
7: transferring eyJvd25lcl9jbGllbnRfaWQiOiJlemN0ZGJkamk3bmhjYXl3eDN4MWFsbXFvIiwicGF0aCI6Ii4iLCJpbmNsdWRlX3BhdHRlcm5zIjpbIioqLyoucmFyIiwiKiovKi50eHQiXSwiZXhjbHVkZV9wYXR0ZXJucyI6WyIqKi5vdXQiXSwiZm9sbG93X3BhdGhzIjpudWxsLCJyZWFkX3NpbmdsZV9maWxlX29ubHkiOmZhbHNlLCJtYXhfZmlsZV9zaXplIjowfQ==: 698B [0.02s]
7: upload . DONE

6: copy . (exclude **.out) (include **/*.rar, **/*.txt)
6: > in host.directory .
6: copy . (exclude **.out) (include **/*.rar, **/*.txt) DONE
In foo : ['bar', 'foo.rar', 'foo.txt']
In bar : ['bar.rar', 'bar.txt', 'baz']
In baz : ['baz.rar', 'baz.txt']
void basin
#

I think this is the issue?

with tempfile.TemporaryDirectory() as workdir:
    anyio.run(main, anyio.Path(workdir))
#

when you use python main that's probably using a different workdir that's set differently than dagger run since what I see in the errors is that the dagger run version can't find some files

void basin
#

can you check from your code what workdir is gets resolved to with one approach and the other?

serene dragon
serene dragon
serene dragon
#

And it's related.

gritty lintel
#

Hey @serene dragon , can you check your CLI version and SDK versions as well? 🙏

serene dragon
#
  1. CLI version
$ dagger version
dagger v0.8.4 darwin/amd64
  1. SDK Version(s)
    Go: dagger.io/dagger v0.8.4
    Python: Version: 0.8.4
    NodeJS: "@dagger.io/dagger": "^0.8.4"

  2. workdir path
    3.1 Without using dagger CLI
    Go:/var/folders/wn/dgdwddk92p70njkbwc55l8gw0000gn/T/
    Python: /var/folders/wn/dgdwddk92p70njkbwc55l8gw0000gn/T/tmpotbmedlh
    NodeJS:/var/folders/wn/dgdwddk92p70njkbwc55l8gw0000gn/T
    3.2 With Using dagger CLI
    Go:/var/folders/wn/dgdwddk92p70njkbwc55l8gw0000gn/T/
    Python:/var/folders/wn/dgdwddk92p70njkbwc55l8gw0000gn/T/tmpbf6bwsuu
    NodeJS:/var/folders/wn/dgdwddk92p70njkbwc55l8gw0000gn/T

void basin
#

I'd assume this is related because of the virtual env thing

#

dagger run won't use the python virtual env

#

not sure what's the python equivalent command to run the command withing the venv

#

@serene dragon just googled really quick and I think that the main reason is that you need to use your venv python binary to be consistent.

so basically dagger run ./venv/bin/python main.py

fleet agate
#

I normally create and start a python venv before installing the SDK or running the pipeline python3 -m venv .venv && source .venv/bin/activate - in case that helps

serene dragon
#

I have been using and running a virtual environment.
After running dagger run ./venv/bin/python main.py and dagger run ./venv/bin/python3 main.py
In both cases I got fork/exec ./venv/bin/python3: no such file or directory
While

$ ls .venv/bin                                                        16:57:12
Activate.ps1  activate.fish markdown-it   pip3.11       python3
activate      gql-cli       pip           pygmentize    python3.11
activate.csh  httpx         pip3          python
#

The issue which I am facing, is this running fine on your devices?

serene dragon
void basin
#

seems like you're not capturing the error in the initial Mkdir call and it's failong for me. So can't really repro

#

It's Output is: cannot configure 'workdir' for existing session (please use --workdir or host.directory with absolute paths instead)

that message is expected

void basin
strong jay
void basin
#

sending python PR in a bit 🙏

void basin
serene dragon
#

But I logged the error, it says, permission denied to create the file.

void basin
#

ok, we can close this right @serene dragon ?

#

since there's not much left to do here

serene dragon
# void basin > It's Output is: cannot configure 'workdir' for existing session (please use --...
  1. I think the examples in the documentation should be able to run with or without dagger run.
    So, maybe we can create an issue for the same, though like you mentioned here #1145698713331834990 message, we will go through this then draft a proper one.
Discord

Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

void basin
serene dragon
void basin
#

thx for reporting @serene dragon . We'll fix it promptly

serene dragon
#

I was asking for a formal issue, because I'd like to assist on this.

fleet agate
mossy oyster
#

Sorry if I don't have all the context, but we want to phase out any examples using configs like workdir or config_path. We're moving focus to the CLI. The target is Zenith, until then we're adapting to dagger run which is a stepping stone in that direction. In Zenith there's no automatic engine provisioning, so no configs related to that as well. The connection will be managed automatically and so (in Zenith) we're using a default client instead of getting a client instance from a manual connection call.

fleet agate