Cirrus CI Documentation

repository·master·Indexed 18 days ago

https://github.com/cirruslabs/cirrus-ci-docs

Official documentation for Cirrus CI, a cloud-native continuous integration platform. Includes guides on configuring pipelines via .cirrus.yml, using the GraphQL API, managing WebHooks, and implementing Docker-based environments. Covers advanced features such as macOS builds with Anka, AWS service integrations (EC2, EKS, S3), GitHub Annotations for JUnit reports, Cirrus CLI for local task execution, and Persistent Workers for custom hardware.

Tokens
43.2K
Snippets
148
Records
202
Agent score
58%

What's inside Cirrus CI

  1. Use Cirrus CLI to run Dockerized tasks locally or in any CI

    master

    Cirrus CLI is an open-source, CI-agnostic tool that allows you to run isolated tasks in any environment where Docker is installed. It uses the Cirrus configuration format (.cirrus.yml) to execute tasks inside Docker containers, ensuring that the environment used locally on a developer's machine is identical to the environment used in a remote CI provider.

    Key benefits include:

    • Environment Parity: Run the exact same tasks locally as in CI to eliminate "works on my machine" issues.
    • Isolation: All tasks execute in isolated Docker containers for stability.
    • Caching: Supports local disk caching or HTTP-based remote caching.
    • Portability: Use the same configuration across different CI vendors or run it manually via the CLI.
    task:
      env:
        matrix:
          VERSION: 1.15
          VERSION: 1.14
      name: Tests (Go $VERSION)
      container:
        image: golang:$VERSION # official Go Docker image
      modules_cache:
        folder: $GOPATH/pkg/mod
        fingerprint_script: cat go.sum
      get_script: go get ./...
      build_script: go build ./...
      test_script: go test ./...
  2. Choose a Cirrus CI pricing plan

    master

    Cirrus CI offers different pricing models based on your repository type and infrastructure needs:

    • Free Public Repositories: Free access to Cirrus Cloud Clusters for public repositories. You can also bring your own infrastructure or configure persistent workers.
    • Private Personal Repositories: A $10/month plan providing access to community clusters for both public and private repositories, plus the ability to bring your own infrastructure or use persistent workers.
    • Private Organization Repositories: Free access to community clusters for public repositories. For private repositories, you can use Compute Credits to access community clusters or Bring Your Own Infrastructure (which costs $10/seat/month).
  3. Configuration capabilities in Cirrus CI

    master

    Cirrus CI uses a powerful configuration format that supports advanced CI workflows. Key configuration features include:

    • Matrix Builds: Run tasks across multiple combinations of parameters.
    • Dependencies between tasks: Define execution order and requirements.
    • Conditional Task Execution: Run tasks only when specific conditions are met.
    • Local HTTP Cache: Speed up builds using cached assets.
    • Dockerfile as a CI environment: Use a Dockerfile to define your build environment.
    • Monorepo Support: Specialized functions for managing monorepos.
  4. Understand the Cirrus CI Terms of Service

    master

    The Cirrus CI Service (including websites, API, and blog) is governed by the Terms of Service. By using the service, you agree to these terms. Key points include:

    • Ownership: You retain all rights and ownership of your Customer Source Code. Cirrus Labs claims no ownership or control over it.
    • Content: "Content" refers to data generated by Cirrus CI on your behalf (like metrics) and does not include your source code.
    • Changes: Cirrus Labs may change terms or prices. For price changes, you will be notified at least 30 days in advance. Continued use of the service after changes constitutes acceptance.
    • Termination: You can cancel your subscription at any time via the GitHub Marketplace. Cirrus Labs may terminate or suspend subscriptions at its discretion.
  5. What is a task in Cirrus CI?

    master

    A task is the fundamental unit of work in Cirrus CI. It defines a sequence of instructions to execute within a specific execution environment.

    Tasks can be named using the name field for rich, human-readable descriptions. While you can use the task_name: syntax as syntactic sugar, using a dedicated name field is recommended for complex names.

    Note: Individual instructions within a task (like test_script) must be named using a prefix rather than a standalone name field.

    task:
      name: Tests (macOS)
      test_script: ./run-tests.sh
  6. Introduction to Starlark in Cirrus CI

    master

    Cirrus CI allows you to use Starlark to define tasks and logic instead of relying solely on declarative YAML. Starlark is a procedural programming language similar to Python that is ideal for embedding logic safely. It is used to generate configuration dynamically, such as parsing files in the repository or making HTTP requests to check build statuses.

    Key benefits include:

    • No compilation required.
    • Instant execution on any platform via a Go-based interpreter.
    • Built-in support for loading external modules for configuration sharing.
  7. How the Cirrus CI build lifecycle works

    master

    The Cirrus CI build lifecycle is triggered by GitHub webhook events. When a change is pushed, Cirrus CI parses the Git branch and SHA to create a new build.

    1. Configuration Retrieval: Cirrus CI uses GitHub APIs to download the .cirrus.yml file associated with the specific SHA.
    2. Task Creation: The .cirrus.yml file is evaluated to generate corresponding tasks.
    3. Scheduling: Tasks are dispatched to a scheduling service which manages resources on supported computing services.
    4. Provisioning: The scheduling service creates a VM instance or Docker container and runs a start-up script to download and execute the Cirrus CI agent (a self-contained Go executable).
    5. Execution: The agent requests commands for the task and streams logs, caches, artifacts, and exit codes back to Cirrus CI.
    6. Cleanup: Once tasks are complete, the scheduling service cleans up the used VM or container.

    Communication involves API calls for orchestration and unidirectional communication from the agent back to Cirrus CI for real-time status reporting, health checks, and GitHub status updates.

  8. Use task `alias` for simplified dependencies

    master

    When tasks have complex names (e.g., names containing environment variables or matrix values), you can use the alias field to provide a short, stable name. This makes managing depends_on lists much easier.

    task:
      name: Test Shard $TESTS_SPLIT
      alias: Tests
      env:
        matrix:
          TESTS_SPLIT: 1/3
          TESTS_SPLIT: 2/2
          TESTS_SPLIT: 3/3
      tests_script: ./.ci/tests.sh
    
    deploy_task:
      depends_on: Tests
      script: ./.ci/deploy.sh
  9. Bring Your Own Infrastructure (Compute Services)

    master

    You can connect your own compute services or persistent workers to Cirrus CI to orchestrate workloads on your own hardware/cloud.

    • Cost: Free for public repositories. For private repositories, it costs $10/seat/month (unless you have a Priority Support Subscription).
    • Benefits: Full control over VM/container types, CPU/Memory allocation, and security (firewalls/access rules). You pay for CI within your existing cloud/GitHub bills.
    • Cons: Requires manual configuration and maintenance of the infrastructure.
  10. Subscribe to Builds and Tasks WebHooks

    master

    Cirrus CI can send POST requests to a configured WebHook URL when builds or tasks are updated.

    • Event Identification: The X-Cirrus-Event header specifies whether the update is for a build or a task.
    • Payload Structure: The JSON payload includes an action (created or updated), an optional old_status (for updated actions), and a data field.
    • Data Retrieval: The data field contains information that can be queried via GraphQL using the repository, build, or task types.
    {
      "action": "created" | "updated",
      "old_status": "FAILED",
      "data": ...
    }
  11. Use Compute Credits for managed infrastructure

    master

    Compute credits allow you to use managed Cirrus Cloud Clusters without maintaining your own infrastructure. 1 credit equals 1 USD. Billing is per-second based on CPU time used.

    Estimated costs per 1000 minutes of 1 virtual CPU:

    • Linux: 3 credits
    • FreeBSD: 3 credits
    • Windows: 4 credits
    • Apple Silicon: 15 credits

    Benefits:

    • No infrastructure maintenance.
    • Per-second billing with no extra fees for storage or traffic.
    • Orchestration costs are included (no additional seats required).

    Limitations:

    • No support for exotic hardware like GPUs, SSDs, or machines with 100+ cores.
    • Less cost-efficient for very large teams.