DEV Community

Alex Spinov
Alex Spinov

Posted on

Dagger Has a Free API — Portable CI/CD Pipelines That Run Anywhere

Dagger: Write CI/CD Pipelines in Your Language, Run Them Anywhere

Dagger lets you write CI/CD pipelines in Go, Python, or TypeScript — not YAML. Pipelines run identically on your laptop and in CI. No more "works in CI but not locally" debugging.

The Problem With YAML Pipelines

  • No type checking, no IDE support
  • Cannot run locally — must push to test
  • Vendor lock-in (GitHub Actions, GitLab CI, Jenkins)
  • Complex logic in YAML = nightmare

The Free API

Python

import dagger
import anyio

async def main():
    async with dagger.Connection() as client:
        # Build
        src = client.host().directory(".")
        build = (
            client.container()
            .from_("python:3.12-slim")
            .with_directory("/app", src)
            .with_workdir("/app")
            .with_exec(["pip", "install", "-r", "requirements.txt"])
            .with_exec(["pytest", "tests/"])
        )
        # Run tests
        await build.stdout()

        # Publish image
        await (
            build
            .with_entrypoint(["python", "app.py"])
            .publish("registry.example.com/my-app:latest")
        )

anyio.run(main)
Enter fullscreen mode Exit fullscreen mode

Go

func main() {
    ctx := context.Background()
    client, _ := dagger.Connect(ctx)
    defer client.Close()

    src := client.Host().Directory(".")

    // Build and test
    out, _ := client.Container().
        From("golang:1.22").
        WithDirectory("/src", src).
        WithWorkdir("/src").
        WithExec([]string{"go", "test", "./..."}).
        Stdout(ctx)

    fmt.Println(out)
}
Enter fullscreen mode Exit fullscreen mode

Why Dagger

Feature Dagger GitHub Actions Jenkins
Language Go/Python/TS YAML Groovy/YAML
Run locally Yes No No
Type safety Yes No Partial
Vendor lock-in None GitHub Jenkins
Caching Built-in Manual Manual

Real-World Use Case

A team spent 2 hours daily debugging CI failures that could not be reproduced locally. After switching to Dagger, engineers run the exact same pipeline on their laptops. CI debugging time dropped to near zero.

Quick Start

curl -fsSL https://dl.dagger.io/dagger/install.sh | sh
dagger init --sdk=python
dagger call build --source=.
Enter fullscreen mode Exit fullscreen mode

Resources


Need CI/CD data automation? Check out my tools on Apify or email spinov001@gmail.com for custom DevOps solutions.

Top comments (0)