DEV Community

Alex Spinov
Alex Spinov

Posted on

Dagger Has a Free API: CI/CD Pipelines as Code That Run Anywhere

Your CI pipeline works on GitHub Actions but breaks on GitLab CI. Dagger runs the same pipeline everywhere — because it runs in containers.

What Is Dagger?

Dagger lets you write CI/CD pipelines in TypeScript, Python, or Go. They run in containers, so they work identically on your laptop, GitHub Actions, GitLab CI, Jenkins, or any CI system.

// ci/index.ts
import { dag, Container, Directory, object, func } from "@dagger.io/dagger"

@object()
class Ci {
  @func()
  async build(source: Directory): Promise<string> {
    return await dag
      .container()
      .from("node:20")
      .withDirectory("/app", source)
      .withWorkdir("/app")
      .withExec(["npm", "install"])
      .withExec(["npm", "run", "build"])
      .stdout()
  }

  @func()
  async test(source: Directory): Promise<string> {
    return await dag
      .container()
      .from("node:20")
      .withDirectory("/app", source)
      .withExec(["npm", "install"])
      .withExec(["npm", "test"])
      .stdout()
  }

  @func()
  async publishImage(source: Directory, registry: string): Promise<string> {
    const build = dag.container()
      .from("node:20-slim")
      .withDirectory("/app", await this.buildDir(source))
      .withWorkdir("/app")
      .withEntrypoint(["node", "dist/index.js"])

    return await build.publish(registry)
  }
}
Enter fullscreen mode Exit fullscreen mode
# Run locally — same as CI
dagger call build --source .
dagger call test --source .

# In GitHub Actions — same commands
# In GitLab CI — same commands
# In Jenkins — same commands
Enter fullscreen mode Exit fullscreen mode

Why Dagger

  • Runs anywhere — local, any CI system, same behavior
  • Caching — automatic layer caching, dramatically faster builds
  • Real code — TypeScript/Python/Go with IDE support, not YAML
  • Composable — functions call functions, share containers
  • Debuggable — run locally, set breakpoints, inspect containers
  • Dagger Cloud — shared cache across team and CI

Dagger vs Traditional CI

Feature GitHub Actions Dagger
Language YAML TypeScript/Python/Go
Local run act (limited) Native
Portability GitHub only Any CI
Caching Manual config Automatic
Debugging Push and pray Local debugger

Building CI/CD pipelines? Check out my developer tools or email spinov001@gmail.com.

Top comments (0)