{"id":"c90b922d-7a2a-4cef-b8ab-c1e7252ff42a","task":"Build and run a Dagger pipeline in Go that containerizes an application, runs tests in isolation, and pushes to a registry only if tests pass, using Dagger's native caching","domain":"Dagger","steps":["Initialize a Dagger Go module with dagger init --sdk=go --name=ci and scaffold a main.go with a Dagger function that accepts a *dagger.Client context and a source *dagger.Directory parameter","In the pipeline function, build a container from the source directory using client.Container().From(baseImage).WithDirectory(\"/app\", source).WithWorkdir(\"/app\").WithExec([]string{\"go\", \"build\", \"./...\"})","Run tests in a separate container derived from the build output using .WithExec([]string{\"go\", \"test\", \"-race\", \"./...\"}); call .Sync(ctx) to execute and return an error if tests fail, preventing the pipeline from continuing","Only if Sync returns nil, proceed to push the image to a registry using .Publish(ctx, registryRef) where registryRef includes the digest-addressable tag; capture and return the pushed digest as the function output","Use WithMountedCache on the Go module cache directory pointing to a client.CacheVolume(\"go-modules\") so dependency downloads are reused across pipeline runs without manual cache key management","Invoke the Dagger pipeline locally with dagger call ci --source=. and in CI with dagger run go run ./ci.go, ensuring the same pipeline code executes identically in both environments"],"gotchas":["Dagger caches container layers and function outputs by content hash; if the build context includes files that change on every run (such as a timestamp file or a git-dirty working tree), caching is effectively disabled and every run rebuilds from scratch","Dagger's WithExec does not stream output to the terminal by default; a long-running step such as a test suite produces no visible output until it completes or fails, making it appear hung; use Stdout(ctx) or Stderr(ctx) to surface output progressively","Publishing to a private registry requires passing registry credentials to Dagger via client.SetSecret and using WithRegistryAuth on the container; credentials stored only as environment variables on the host are not automatically available inside Dagger containers"],"contributor":"waymark-seed","created":"2026-06-13T05:09:50Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/c90b922d-7a2a-4cef-b8ab-c1e7252ff42a"}