Skip to content
aztec-labs-engPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

644 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build System

This repository uses a custom build system that is agnostic to CI platforms and leverages a remote cache (S3 or MinIO) for caching build artifacts. Our approach enables efficient incremental builds, distributed parallel testing, and consistent deployment to ephemeral infrastructure (e.g., AWS Spot Instances).

We avoid heavy CI vendor lock-in by using shell scripts with a uniform framework (ci3 folder). Each project defines its own bootstrap or build script but relies on the shared ci3 folder for advanced features like:

  • Generating content hashes to skip unchanged builds
  • Uploading/downloading build artifacts
  • Parallelizing & caching test results
  • Logging ephemeral output
  • Provisioning ephemeral AWS instances for maximum compute at minimal cost

Requirements & Rationale

  1. Monorepo-friendly Multiple projects within one repository can have separate build steps that only rebuild if their subset of files changes.

  2. Remote Caching A stateless approach using S3-compatible storage (AWS S3 or MinIO). This replaces older Docker-image-based caches, streamlines artifact reuse, and easily shares builds across different runners or machines.

  3. Content-based Rebuilds We compare content-hashes of relevant files. If no changes, no rebuild. This encourages fine-grained patterns (e.g., ignoring docs changes, but not ignoring new code).

  4. Ephemeral Infrastructure We frequently run on EC2 spot instances to take advantage of cost savings. On eviction, the system gracefully shuts down and requeues tasks if needed.

  5. Avoiding CI Lock-In We do not rely on special vendor features. Our build is run via shell scripts that can be triggered on any platform.

Important Concepts

Content Hashes

Instead of tagging artifacts by commit or branch, we compute a hash of the actual files that matter (via .rebuild_patterns). If code, dependencies, or scripts in that set change, we produce a new content hash and thus trigger a fresh build.

CI-Agnostic

All logic is in shell scripts, grouped under the ci3 folder. A minimal layer of environment detection handles toggling debug modes, caches, or ephemeral logs. This means the same build system can run on local machines, ephemeral Docker containers, or GitHub Actions.

Rebuild Patterns

Each project folder often contains a .rebuild_patterns file. This file has patterns that, if matched by changed files, triggers a new build. Typical patterns might include: ^yarn-project/foundation/src/.*.ts and other patterns from root.

When cache_content_hash sees new changes in these paths, it regenerates a new hash which prevents a cache download until an S3 artifact with that hash is uploaded.

Tools

Tools are provided for the following themes.

  1. Caching

    • cache_content_hash: Takes file patterns (or .rebuild_patterns) to compute a stable content hash.
    • cache_upload, cache_download: Upload/download .tar.gz artifacts from a remote S3-like cache. The cache follows the instance profile (CI3_INSTANCE_PROFILE_NAME), since each profile can write only its own trust level's cache: the shared, publicly readable aztec-ci-artifacts for ordinary builds and local runs, aztec-ci-release-cache for release instances, aztec-ci-private-cache for private ones. A job with no instance profile that needs another level's cache, such as a release's publish job, names it with source_cache_bucket <bucket> (or CI3_CACHE_BUCKET).
    • cache_upload_flag, cache_download_flag: Mark or detect a particular test's success state. Avoids re-running long tests.
  2. Test Parallelization & Caching

    • parallelize: Reads test commands from STDIN, executes in parallel, aggregates logs.
    • run_test_cmd: Single test runner that can skip tests cached as “already passed.”
    • filter_cached_test_cmd: Filters out test commands known to have succeeded (based on flags in redis).
    • upload_test_artifacts: A test may leave files worth keeping, such as a failed browser test's screenshots, in $TEST_ARTIFACTS_DIR, which every test gets (inside a docker_isolate container too). After the test they are published to https://build-cache.aztec-labs.com/test-artifacts/<log id>/, with a link to each in its log. Hidden files (a tool's own bookkeeping, such as Playwright's .last-run.json) are not published.
  3. Ephemeral Logging

    • denoise: Minimizes output spam; prints dots for each line, reveals full logs only if a command fails.
    • cache_log, dump_fail: Captures output for ephemeral storage and prints or reveals logs when needed.
  4. AWS Provisioning

    • aws_request_instance & aws_terminate_instance: Provision ephemeral spot or on-demand instances.
    • aws_handle_evict: Detects spot-instance eviction signals, handles graceful shutdown or requeue.
  5. Docker Isolation

    • docker_isolate: Executes a script in a new Docker container with ephemeral volumes, isolating host environment from side effects.
  6. General Utilities

    • source_bootstrap, source_refname, source_color: Shared environment, color-coded logging, or version detection.
    • echo_header: Prints a heading for better log readability.
    • ci3/source is the central include-script for Aztec’s build system, automatically configuring Bash strict mode, setting up your $PATH to include all ci3 utilities (e.g. caching, parallel test commands), and providing helper functions and color-coded logging. Simply add source $(git rev-parse --show-toplevel)/ci3/source at the top of any project script to inherit a robust, preconfigured environment.

Usage Flow

  1. In each project: A bootstrap.sh might:

    • Call cache_content_hash to detect changes.
    • If changed, do the relevant compile step, then cache_upload.
    • If not changed, do cache_download to restore a previously built artifact.
  2. In test scripts:

    • We gather test commands (test_cmds) in a form easily read by parallelize.
    • parallelize calls run_test_cmd on each line, skipping or running tests as needed.
  3. In local or ephemeral servers:

    • Either manually run ./bootstrap.sh fast or let the CI invoke it on a fresh machine.
    • The system pulls dependencies, attempts to restore from remote caches, rebuilds only if necessary, then parallelizes tests.
  4. On success:

    • Artifacts can be re-uploaded or flagged as “passed,” letting future runs skip unchanged steps.

Interface

ci3 is consumed as a git submodule at <repo>/ci3. What a consuming repository may rely on is deliberately narrower than "every file here".

Public

Everything at the top level of this repository, plus aws/, bin/, dashboard/ and lua/. A script is public because a consuming repository sources or executes it, or because a person runs it by hand (cache_ls, cache_delete, clean_remote_tags, start_interactive). The scripted set was established by auditing every reference in the consuming repositories. Changing the name, arguments, output format or exit codes of anything public is a breaking change for them.

Entry points are sourced by path — source $(git rev-parse --show-toplevel)/ci3/source, source_bootstrap from a bootstrap.sh, or the minimal source_base — which puts ci3 on PATH, so the rest is called by name: denoise, cache_download, parallelize, and so on. source already brings in redis, the ref name and the cache settings; those fragments are internal and never need sourcing separately. Only source_npm_auth and source_cache_bucket are opt-in.

Internal

internal/ holds scripts only ci3 itself uses. It is on PATH so ci3's scripts can call each other by name, but nothing outside ci3 should: these can change or disappear without notice. A script moves out of internal/ when a consuming repository needs it, not before.

What ci3 expects from the consuming repository

The dependency runs both ways. ci3 reads these from the repository it is building:

  • .test_patterns.yml — test skips, retries, owners and Slack notifications (filter_test_cmds, run_test_cmd).
  • scripts/process_flake_log.py — optional; run by parallelize after a test run when present.
  • build-images/src/home/.gitconfig — mounted into containers by docker_isolate.
  • CI3_EVENT_ENDPOINT, CI3_EVENT_TOKEN and CI3_EVENT_PROJECT — optional; when all are set, bootstrap_ec2 sends a ci.instance event per build instance through send_event to that OTLP endpoint, for example https://otel.aztec-labs.com.
  • Permission to renew a build instance's lease. Each build instance shuts itself down, and so terminates, once its LeaseUntil tag has passed, and whoever launched it renews that tag every minute while it runs (internal/source_instance_lease). The AWS role that launches instances, in CI and on a build instance launching another (such as the benchmark box), needs ec2:CreateTags for the LeaseUntil key on instances tagged with its Group. Without it, every instance shuts down 10 minutes after boot.
  • One Group per instance profile. An instance's Group tag is its instance profile's name without the ci3- prefix and -profile suffix (CI3_INSTANCE_PROFILE_NAME, default ci3-build-instance-profile, so build-instance). Scope each launching role's EC2 and SSM permissions to the groups of the profiles it may pass, so a build of one trust level cannot drive instances of another.
  • What reaches the build container. bootstrap_ec2 passes ci3's own settings. Anything else the repository's build needs it names, usually in its ci.sh: CI3_PASS_ENV, variables passed as they are; CI3_PASS_FILES, variables holding the path of a file on the runner, which is copied to the instance under /tmp/ci3-files and passed pointing at the copy.
  • .github/ci3_post_checkout.sh — optional; executable. Run on the instance right after checkout and before ci3/source derives COMMIT_HASH, with the build's environment and AWS role, so it can change the tree (apply and commit a patch, say). Its stdout is printed at the start of the run; its stderr shows only if it fails, which fails the run.
  • exec into bootstrap_ec2 or bootstrap_ec2_multi, all the way from the CI step: run: exec ./ci.sh fast in the workflow, exec bootstrap_ec2 … in ci.sh. CI cancels a job by signalling only the process it started (GitHub Actions sends that one process SIGINT, then SIGTERM, then SIGKILL 10 seconds later), so that process must be the ci3 script that terminates the instances. A script in between that runs it without exec, including as part of a pipeline, keeps the signal to itself, and the instances run on until their leases run out. tests/cancel_test covers this.

State shared between versions

A repository pins its own ci3, and a build can involve more than one pin: a repository and a submodule of it each use their own. What has to stay compatible across versions is therefore not the scripts but the state they share: redis key shapes (ci-run-<org>/<repo>/<section>, history_*, hb-*, the test cache), S3 log keys (logs/<prefix>/<key>.log.gz), build-cache artifact names, and the <hash>[:VAR=val] <cmd> test command format.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages