DEV Community

Alex Spinov
Alex Spinov

Posted on

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

Why Dagger

Dagger lets you write CI/CD pipelines in Go, Python, or TypeScript — not YAML. Run them locally for testing, then use the same code in GitHub Actions, GitLab CI, or any CI system.

Install

curl -fsSL https://dl.dagger.io/dagger/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

Pipeline in TypeScript

import { dag, Container, Directory, object, func } from '@dagger.io/dagger';

@object()
class MyPipeline {
  @func()
  async build(src: Directory): Promise<Container> {
    return dag
      .container()
      .from('node:20-alpine')
      .withDirectory('/app', src)
      .withWorkdir('/app')
      .withExec(['npm', 'ci'])
      .withExec(['npm', 'run', 'build']);
  }

  @func()
  async test(src: Directory): Promise<string> {
    return (await this.build(src))
      .withExec(['npm', 'test'])
      .stdout();
  }

  @func()
  async publish(src: Directory, tag: string): Promise<string> {
    return (await this.build(src))
      .publish(`ghcr.io/myorg/myapp:${tag}`);
  }
}
Enter fullscreen mode Exit fullscreen mode
# Run locally
dagger call test --src .
dagger call publish --src . --tag v1.0.0
Enter fullscreen mode Exit fullscreen mode

Pipeline in Python

import dagger
from dagger import dag, function, object_type

@object_type
class MyPipeline:
    @function
    async def test(self, src: dagger.Directory) -> str:
        return await (
            dag.container()
            .from_("python:3.12-slim")
            .with_directory("/app", src)
            .with_workdir("/app")
            .with_exec(["pip", "install", "-r", "requirements.txt"])
            .with_exec(["pytest"])
            .stdout()
        )
Enter fullscreen mode Exit fullscreen mode

Use in GitHub Actions

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dagger/dagger-for-github@v6
        with:
          verb: call
          args: test --src .
Enter fullscreen mode Exit fullscreen mode

Key Features

  • Real code — Go, Python, TypeScript, not YAML
  • Local testing — run CI pipelines on your laptop
  • Caching — automatic, content-addressed caching
  • Portable — same pipeline on any CI platform
  • Composable — share pipeline modules as packages

Resources


Need to extract CI/CD pipeline data or build metrics? Check out my Apify tools or email spinov001@gmail.com for custom solutions.

Top comments (0)