#dagger/cmd/dagger/env.go at zenith · sip...

1 messages · Page 1 of 1 (latest)

fast drift
#

Re-reading the README.md - I think I skimmed over some important info...

  • Currently, dependencies must be relative paths to other environment directories on the local filesystem. Support for git:// envs is easy to add once requested

there's my answer.

verbal dove
#

Ah yeah, git deps haven't been added there yet.

But, due to some recent changes, I actually think for Go specifically you can create an environment outside of the dagger repo now, with one small extra step.

The process would be:

  1. same setup of needing to build dev engine/cli (./hack/dev and those env vars)
  2. your external repo outside of dagger needs a go.mod of course, so either need to initialize one or re-use an existing one
  3. in that go.mod, add replace dagger.io/dagger => github.com/sipsma/dagger/sdk/go zenith
  4. run go mod tidy
  5. from there, you should be able to just run dagger env init --name foo --sdk go in the root of your external repo, skipping --root flag
  6. then go ahead and follow the existing instructions
#

Let me know if that makes sense and if you have time to try it out if you are interested. I'll add that to the official instructions if so!

#

Also, yeah the whole process will get better soon since we are getting close to merging the first chunk of Zenith (just checks to start) into our actual main branch, which will result in everything getting much easier to get going with.

fast drift
#

hmm.. gave the above a shot, getting an error.

// go.mod
replace dagger.io/dagger => github.com/sipsma/dagger/sdk/go v0.3.2-0.20230830153407-ad236da3ca9b
export _EXPERIMENTAL_DAGGER_CLI_BIN=/Users/me/repos/misc_projects/dagger/bin/dagger
export _EXPERIMENTAL_DAGGER_RUNNER_HOST=docker-container://dagger-engine.dev
➜  ci git:(master) ✗ dagger env init --name f --sdk go
Error: failed to run codegen: failed to connect to engine: load universe: make request: input:1: loadUniverse failed to load universe: failed to load environment config: failed to unmarshal environment config: invalid character '\x00' looking for beginning of value
verbal dove
fast drift
#

I had exported path before, hack/dev builds a new dagger cli right?

➜  ci git:(master) ✗ which dagger
/Users/steven.tobias/repos/misc_projects/dagger/bin/dagger
➜  ci git:(master) ✗ dagger version
dagger devel () darwin/amd64
verbal dove
fast drift
#

ty!

verbal dove
# fast drift hmm.. gave the above a shot, getting an error. ``` // go.mod replace dagger.io/...

Hm so I was able to run dagger env init successfully direct on macos... On an m1 macbook specifically, but I'd be surprised if this was cpu architecture specific somehow.

I'm wondering also based on the error message if there could be something going on with caching. You can clear the whole cache via docker rm -fv dagger-engine.dev; docker volume rm dagger-engine.dev. You'll need to re-run ./hack/dev again so the dev engine runs again (but now with an empty cache)

#

Also worth double checking your git checkout is fully up to date and doesn't have stray files laying around (git clean -d -x -f will remove everything not part of the original git repo)

fast drift
#

aha! definitely something with the cache. Init successful

#

now this on checks though...

➜  ci git:(master) ✗ dagger checks
• Engine: f6033dbb5d29 (version devel ())
⧗ 3.63s ✔ 16 ∅ 7 ✘ 3
Error: failed to get environment ID: input:1: environment.load failed to load environment: failed to get envid file: process "go build -C /src -o /entrypoint -ldflags -s -d -w ." did not complete successfully: exit code: 1
verbal dove
fast drift
#

yeah I've got main.go.

Just simplified it to debug, same error as above.

package main

import (
    "context"
    "fmt"
    "dagger.io/dagger"
)

func main() {
    dag.Environment().
        WithCheck(UnitTest).
        Serve()
    //dependabot_job(client.Pipeline("Dependabot Job"), ctx)
}
func UnitTest(ctx context.Context) (*EnvironmentCheck, error) {
    return dag.EnvironmentCheck().WithDescription("ok"), nil
}

Produces:

24: exec go build -C /src -o /entrypoint -ldflags -s -d -w .
24: [0.13s] go: go.mod file not found in current directory or any parent directory; see 'go help modules'
24: exec go build -C /src -o /entrypoint -ldflags -s -d -w . ERROR: process "go build -C /src -o /entrypoint -ldflags -s -d -w ." did not complete successfully: exit code: 1

14: dagger --progress=plain checks
14: loading environment [0.54s]
14: dagger --progress=plain checks ERROR: failed to get environment ID: input:1: environment.load failed to load environment: failed to get envid file: process "go build -C /src -o /entrypoint -ldflags -s -d -w ." did not complete successfully: exit code: 1
verbal dove
fast drift
#

oh I feel dumb

#

didn't realize I had gotten to the actual build yet.

I had go.mod in the parent dir, but I'm writing /running in a subdirectory, ci

verbal dove
# fast drift didn't realize I had gotten to the actual build yet. I had go.mod in the paren...

No worries! And actually, if you are running in a subdir, that's where the --root flag comes into play. You need --root to point to the directory that contains the go.mod. So if you have your own separate go.mod in ci/, that works, but if you prefer to re-use the one from the parent dir you'll want to use --root .. when you init.

I don't think we've added a dagger subcommand for updating --root yet, so you can either manually edit dagger.json to have "root": ".." in it or just delete dagger.json and re-run dagger env init --name f --sdk go --root ..

fast drift
#

got it.

still running into an error "environment not found" though.

#
time="2023-08-30T20:58:50Z" level=debug msg="CHECK RESULT RESOLVER  [environmentCheck withSubcheck withSubcheck result] &{Name: Flags:[] Description:go test -v . Subchecks:[] EnvironmentName: ContainerID:}" client_hostname=steven.tobias client_id=4m7kkj4hjt697ul8o4lhlywnk register_client=false server_id=u66mdl25m2bmpii8fqr1w9sur spanID=d8db1ed546c9cb99 traceID=64820c74fabd2ecdb92409ff6baf8c4b
time="2023-08-30T20:58:50Z" level=debug log-sha256:d6d1029d414130abceda72515fe2ca3e8f20b0bc13ae962644413fd7e654ccf3:result="vertex:\"sha256:d6d1029d414130abceda72515fe2ca3e8f20b0bc13ae962644413fd7e654ccf3:result\" stream:STDERR data:\"environment  not found\\n\" timestamp:{seconds:1693429130 nanos:745881461}"

^ engine logs

#

unless it's obvious what's up here, maybe I should just wait it out haha this isn't exactly urgent

modest dirge
#

cc @versed night @candid dock

fast drift
#

....and I'm back.

Updated code... that works!

func main() {
    dag.Environment().
        WithCheck(UnitTest).
        Serve()
}

func UnitTest(ctx context.Context) (*EnvironmentCheckResult, error) {
    return dag.EnvironmentCheck().
        WithDescription("ok").
        WithContainer(dag.Container().From("golang:1.20")).
        Result(), nil
}

The missing piece here was making sure to return an EnvironmentCheckResult , and this needed a container via WithContainer

#

while it's not a fully complete test example, it makes a bit more sense now, and runs. I think I can build from here

modest dirge
#

Nice!