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 · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. 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
  2. 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", "./..."})
  3. 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
  4. 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
  5. 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
  6. 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

Known gotchas

Related routes

Build a Dagger module in Go that exposes a function accepting a directory, runs linting and tests as parallel pipeline steps, and caches dependency layers between runs
dagger.io · 5 steps · unrated
Use Dagger to define a portable CI pipeline in Go that builds, tests, and pushes a container image using the Dagger Go SDK with module composition
dagger.io · 5 steps · unrated
Run a Dagger service (e.g., a database container) as a sidecar bound to a test container using Dagger Services, ensuring the service is health-checked before tests start
dagger.io · 5 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans