#dagger/cmd/dagger/env.go at zenith · sip...
1 messages · Page 1 of 1 (latest)
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.
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:
- same setup of needing to build dev engine/cli (
./hack/devand those env vars) - your external repo outside of dagger needs a go.mod of course, so either need to initialize one or re-use an existing one
- in that
go.mod, addreplace dagger.io/dagger => github.com/sipsma/dagger/sdk/go zenith - run
go mod tidy - from there, you should be able to just run
dagger env init --name foo --sdk goin the root of your external repo, skipping--rootflag - 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.
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
That error is most likely from using an older CLI; you'll want to set PATH=/Users/me/repos/misc_projects/dagger/bin/dagger:$PATH, rather than _EXPERIMENTAL_DAGGER_CLI_BIN
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
Yes, ./hack/dev rebuilds the CLI and rebuilds the engine and runs it in docker at docker-container://dagger-engine.dev.
I'll give this a quick shot on MacOS directly too; I do most stuff on Linux and it's possible some detail is off somewhere that could cause this.
ty!
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)
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
Did you create the main.go yet? You'll need to have that. Obviously the error message isn't really very helpful yet 🙂 In general at the moment you can see more error output if you run with dagger --progress=plain, we need to fix the nicer output to not swallow errors as much still
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
oh okay the line that's buried in that output is go.mod file not found in current directory or any parent directory. So you probably just need a go mod init testdagger (or replace testdagger with whatever you want)
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
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 ..
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
cc @versed night @candid dock
....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
Nice!