Skip to content

feat(agent): BuildImage builds with Railpack and Nixpacks (part of #215) - #540

Merged
samuelmbabhazi merged 2 commits into
mainfrom
feat/215-railpack-nixpacks
Nov 27, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
feat/215-railpack-nixpacks

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Part of #215 (M3.3: "Dockerfile, Railpack, Nixpacks, image").

What changed

The agent's BuildImage now builds the two other build types of ADR 0012 and ADR 0030. The control plane does not send them yet; a follow-up PR lets Git applications choose them.

  • Nixpacks:
    • BuildKit fetches the Nixpacks v1.41.0 release archive for the server's architecture, checked against the SHA-256 GitHub publishes for it.
    • It runs nixpacks build /src --out /out from that static binary alone: no network, the repository mounted read-only, every argument one argv entry.
    • Nixpacks writes no plan file. In the same session, the agent reads the docker build command Nixpacks writes in .nixpacks/build.sh, in memory, and keeps only --build-arg NAME=VALUE pairs with environment variable names, never BUILDKIT_…. The application's own arguments override them.
    • BuildKit's Dockerfile frontend then builds .nixpacks/Dockerfile over the repository with Nixpacks' files merged on top.
  • Railpack:
    • railpack prepare runs in Railpack's frontend image v0.43.0, pinned by its index digest, with the repository read-only.
    • Railpack's frontend reads the repository and the plan only through llb.Local (client directories), never from a source BuildKit fetched. So BuildKit writes the repository and the plan to a 0700 directory under the agent's state directory. The agent serves both to the frontend through the session, without the Git token, and deletes them after the build.
    • The build arguments are served as build secrets, as Railpack reads them, with secrets-hash so that a new value rebuilds.
    • The maintainer chose this approach over linking Railpack's Go module into the agent.
  • Both: cache mounts get a key derived from the application's repository in the registry, so one application's cache is never another's.
  • Validation: build_type may be railpack or nixpacks, which take no dockerfile (refused otherwise). An unknown type is refused.

Docs: ADR 0030 is amended (Railpack's copy, Nixpacks' script, the rejected alternative). The SPEC action table says what each type does with the arguments, and an open question covers the copy's disk use. THREAT_MODEL gets T6 (tampered Railpack or Nixpacks) and a sentence in E4 about the copy.

Why

#215's scope and acceptance ask for the three build types, and the maintainer decided on all three for v0.1. ADR 0030's plan for Railpack ("BuildKit builds it with Railpack's frontend image") cannot work with a Git source, which is why the ADR is amended here.

How it was tested

  • Unit tests:
    • the Nixpacks definition: pinned URL and SHA-256 per architecture, an architecture without a release refused, exact argv, no network, read-only source;
    • the Railpack definition: pinned image, exact argv, read-only source;
    • the frontend options: pinned source, per-application cache key, secrets-hash that changes with a value, arguments never in attrs;
    • build.sh parsing with malicious content: BUILDKIT_SYNTAX, invalid names, missing values, oversized values and script, invalid UTF-8, other docker build flags, the 200 bound.
    • BuildImage input checks: unknown type, a Dockerfile path on Railpack or Nixpacks, arguments that look like flags.
  • Real BuildKit (real_buildkit_test.go, which runs in the "Agent against Docker and Caddy" job): a Node application without a Dockerfile (testdata/node) is built from this repository at its commit with Railpack and with Nixpacks, pushed, and found in the registry at the answered digest. The test also checks that Railpack's copy is gone.
    • Locally against BuildKit v0.35.1: Railpack 2 min 6 s, Nixpacks 1 min 47 s, with an empty cache.
    • Both images, pulled and run, served the application. Railpack's image does not carry the argument; Nixpacks' does.
  • go test ./agent/... ./cli/... ./lib/..., golangci-lint (also with the integration tag) and Semgrep are clean.

The diff is about 920 lines, half of them tests; prettier also realigned the SPEC action table.

Security considerations

  • No process runs on the host. Railpack and Nixpacks run inside rootless BuildKit, behind its network rule, Nixpacks with no network at all, and both see the repository read-only.
  • What runs is pinned in the agent's code: an image index digest and two archive SHA-256s.
  • The plan Railpack writes (shaped by the repository) is read by its frontend inside BuildKit, not by the agent. From Nixpacks' script the agent reads only build argument pairs, under strict name rules and bounds; BUILDKIT_… names are dropped so a repository cannot pick another frontend through them.
  • Railpack's copy is a Git checkout, which has no setuid file. It lives in a 0700 directory of the agent's, and is deleted after the build, or by the next Railpack build after an agent restart.
  • The Git token is not served to Railpack's frontend: the repository is already on disk by then.
  • Cache keys keep one application's cache mounts away from another's.
  • Open question added to the SPEC: the copy has no disk bound, like a build itself.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 258cb8b and bafe70c.

Files selected for processing: 13

  • agent/go.mod
  • agent/internal/actions/build.go
  • agent/internal/actions/build_test.go
  • agent/internal/agent/gateway.go
  • agent/internal/buildkit/builders.go
  • agent/internal/buildkit/builders_test.go
  • agent/internal/buildkit/buildkit.go
  • agent/internal/buildkit/real_buildkit_test.go
  • agent/internal/buildkit/testdata/node/index.js
  • agent/internal/buildkit/testdata/node/package.json
  • docs/SPEC.md
  • docs/THREAT_MODEL.md
  • docs/adr/0030-builds-and-registry-without-a-private-network.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@samuelmbabhazi
samuelmbabhazi merged commit deff5f6 into main Nov 27, 2026
27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/215-railpack-nixpacks branch November 27, 2026 13:51
@samuelmbabhazi

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

samuelmbabhazi added a commit that referenced this pull request Nov 27, 2026
…215) (#541)

Part of #215. Follows #540, which teaches the agent to build with
Railpack and Nixpacks; **merge it after #540**.

## What changed

- A Git application's `shipkeep.yml` may set `build.type: railpack` or
`nixpacks`, not only `dockerfile`. An application created without a
repository still runs an image only (`unsupported_application_source`).
The schema already refuses `build.dockerfile` with Railpack and
Nixpacks.
- The pipeline's build step carries its `builder`. `agent-steps.ts` maps
it to the agent's `BuildType`, with an empty `dockerfile` for Railpack
and Nixpacks. The context is read as for a Dockerfile build (`./web/` is
`web`).
- The release draft accepts any build from the repository; the error
text no longer says "Dockerfile … for now".
- The API no longer answers `unsupported_build_type`. The web form still
maps that code to a message, which is now unreachable. I left it out of
this PR so that the PR does not touch the UI; it goes with the next UI
change.
- SPEC: the `building` stage names the three build types. The `POST
…/applications` description says where built applications are created
(`openapi.json` and the client regenerated).

## Why

#215's scope is "Dockerfile, Railpack, Nixpacks, image", and the
maintainer chose all three for v0.1.

## How it was tested

- Unit tests:
- the configuration: the three types accepted from a repository, refused
without one, a Dockerfile path with Nixpacks refused;
- the pipeline: Railpack and Nixpacks builds succeed with `builder` set
and no Dockerfile;
- the agent action: `BuildType.RAILPACK` and `NIXPACKS`, empty
`dockerfile`, and `DOCKERFILE` for the existing case.
- Integration with PostgreSQL (`git-builds.integration.spec.ts`): a
Nixpacks Git application deployed queues a `BuildImage` with
`BuildType.NIXPACKS`, context `web` and no Dockerfile. In
`git-applications-http.integration.spec.ts`, a Railpack configuration is
no longer refused.
- Locally:
  - API unit tests 966/966, typecheck and lint clean;
- integration 466 passed, with only the known local failures (PostgreSQL
18's 23001 ×3, and the metrics, S3 and Distribution suites, which need a
container runtime).

## Security considerations

- The control plane only chooses the agent's build type from the
validated configuration. Each type's input checks are on the agent
(#540).
- The token, the push grant and the build's isolation are those of
Dockerfile builds (ADR 0030).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Git-based applications can now use Dockerfile, Railpack, or Nixpacks
builds. Build settings are passed through to deployments, including
configured context and arguments.
* **Documentation**
* Updated deployment guidance to describe supported build types and how
build paths are interpreted.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: samuel mbabhazi <[email protected]>
samuelmbabhazi added a commit that referenced this pull request Nov 28, 2026
…ixpacks script (part of #215) (#542)

Part of #215. Fixes what a review of #540 found after it was merged;
CodeRabbit had reached its review limit on #540.

## What changed

**Important**
- **Cache isolation that holds.** #540 named each application's cache
mounts with a plain hash of its registry repository. A build that knew
another application's identifiers could compute that name and write into
its cache. Now:
- The namespace is an HMAC of the repository under a 32-byte key only
the agent holds (`<state>/build-cache.key`, 0600, made once and kept
across restarts; a damaged one is replaced).
- It covers the three build types: `cache-key` for Railpack,
`--cache-key` for Nixpacks, and `BUILDKIT_CACHE_MOUNT_NS` for Dockerfile
builds and Nixpacks' Dockerfile. Dockerfile builds were not isolated at
all before.
  - Without the key, builds fail and say so, and the agent logs it.
- **Failures say why.** A build that failed in the agent before BuildKit
printed anything ended as `build_failed` with an empty output, for
example Nixpacks on an architecture it has no release for. The error now
goes into the build output, each line redacted like the rest. The
action's error text stays the fixed one.
- **A Nixpacks script is bounded, not cut.** The script was read with
exactly 64 KiB, so a longer one was silently truncated, and its last
argument could be parsed with a partial value. It is now read with one
byte more, and a longer script fails the build.

**Smaller**
- **`BUILDKIT_…` build arguments are refused**: by the API
(`reserved_build_arg`, at `/build/args`, before anything is deployed)
and by the agent. BuildKit reads them as its own settings (the cache
namespace above, or `BUILDKIT_SYNTAX`, which swaps the frontend).
- **Every build empties the work directory first**, not only Railpack
builds, so a copy an agent restart left behind does not wait for the
next Railpack build.
- **The repository's own `.nixpacks` is removed** before Nixpacks' files
are merged on top. `llb.Merge` alone overlaid it, so stale files stayed.
- **Docs**:
- ADR 0030 says the build arguments reach Railpack as build secrets, but
are not secret values (as `shipkeep.yml` says), and may show in the
output;
  - ADR 0030 describes the keyed namespace for the three types;
- THREAT_MODEL T6 names the residual risk: the builder, runtime and base
images that the pinned Railpack and Nixpacks versions build from are
referenced by tag upstream;
  - THREAT_MODEL E4 mentions the cache namespaces;
  - SPEC: argument keys are never `BUILDKIT_…`.

## How it was tested

- **Unit tests**:
- namespaces: stable across releases, different between applications,
different under another key, never the repository's plain hash;
  - the key file: created 0600, reused, a damaged one replaced;
  - `BUILDKIT_CACHE_MOUNT_NS` set for Dockerfile builds;
  - the `.nixpacks` removal in the Nixpacks context;
- a build without a key refused, and the leftover work directory removed
before anything reaches BuildKit;
- `BUILDKIT_` arguments refused by the agent and by the API, with
`BUILD_KIT` still accepted;
- a failure's text in the output with the Git token redacted, the
action's error unchanged.
- **Real BuildKit** v0.35.1, locally, at this branch's commit: the
Dockerfile, Railpack (1 min 40 s) and Nixpacks (2 min 43 s) builds all
push and answer their digest. The same test runs in CI.
- `go test ./agent/... ./cli/... ./lib/...`, golangci-lint (also with
the `integration` tag), Semgrep, API typecheck, lint and the `apps`
domain tests are clean.

## Security considerations

- The cache key is a new secret in the agent's state directory (0600,
owned by the agent's account). It never leaves the server. If it is
lost, only the caches are lost: the next builds start cold.
- Refusing `BUILDKIT_` arguments may refuse an existing configuration
that used one. They were never documented, and Shipkeep now sets the one
that matters itself.
- Arguments remain non-secret by contract. They can show in BuildKit's
own error lines, as with any `docker build`.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Build caches are isolated by application, and builds now start with a
clean work directory.
* **Bug Fixes**
* Build failures provide diagnostic messages while keeping the returned
error text fixed and sensitive tokens redacted.
* Nixpacks builds reject scripts larger than 64 KiB and replace existing
generated `.nixpacks` content.
* **Validation**
* Build arguments using reserved `BUILDKIT_` names are rejected. Git
tokens and registry passwords shorter than four bytes are also rejected.
* **Documentation**
* Build argument and cache behavior, including the handling of build
arguments as non-secret values, is clarified.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: samuel mbabhazi <[email protected]>
samuelmbabhazi added a commit that referenced this pull request Nov 28, 2026
…ilpack's (closes #544) (#551)

Closes #544, together with #542. **Builds on #542** (keyed cache
namespaces, `BUILDKIT_` arguments refused): until #542 merges, this diff
also shows its commit, `add2fe2c`. Main will be merged in once #542 is.

## What changed

#544 asks for one reserved-argument policy (done in #542), and for an
explicit decision on user-selected Dockerfile frontends. This PR takes
that decision, choosing the more secure and reversible option:

- **The builder's frontend allowlist.** `deploy/install.sh` now writes
these sections into the builder's `buildkitd.toml`:
  ```toml
  [frontend."dockerfile.v0"]
    enabled = true
  [frontend."gateway.v0"]
    enabled = true
allowedRepositories = ["docker.io/docker/dockerfile",
"ghcr.io/railwayapp/railpack-frontend"]
  ```
- A Dockerfile may still name the official frontend, as in `#
syntax=docker/dockerfile:1` (common, and maintained by Docker).
  - Railpack's frontend, pinned by the agent (#540), keeps working.
- Any other `# syntax=` makes the build fail: BuildKit answers "… is not
an allowed gateway source".
- This does not rely on hiding a secret identifier from a frontend: an
untrusted frontend never runs at all.
- A server installed before this gets the configuration with `install.sh
--migrate yes`, which writes the builder's configuration again and
restarts it.
- **CI's BuildKit runs under the same sections.** They are read from
`deploy/install.sh`, so the real build tests exercise the policy the
servers get.
- **Docs**:
  - ADR 0030 (`dockerfile` build type);
- SPEC: the builder's configuration, plus a new open question on whether
to allow other frontends, and with what session capabilities;
  - THREAT_MODEL E4.

## How it was tested

- **Real BuildKit** v0.35.1, locally, configured as CI now is:
  - a Dockerfile with `# syntax=docker/dockerfile:1` builds and pushes;
- one with `# syntax=ghcr.io/shipkeepdev/not-a-frontend:1` is refused
with "is not an allowed gateway source";
- under the allowlist, Railpack (3 min 30 s), Nixpacks (3 min 15 s) and
the Dockerfile build all build and push. Railpack still goes through
`gateway.v0`.

The two new testdata Dockerfiles run in the "Agent against Docker and
Caddy" job.
- **Unit tests**:
- the installer's allowlist names the repository of the Railpack
frontend the agent pins, and the official Dockerfile frontend;
  - `install_test.sh` checks the configuration line.
- `go test`, golangci-lint (also with the `integration` tag), shellcheck
and actionlint are clean.

## Security considerations

- A repository can no longer have its build interpreted by a frontend
image of its choosing. Such a frontend would have run with the build's
session: its secrets provider and the registry credentials for the push.
- The two allowed frontends are BuildKit's own and Railpack's, which the
agent pins by digest. The official Dockerfile frontend is named by tag
in a Dockerfile, as Docker documents it.
- The policy is reversible: one configuration line, rewritten by
`--migrate`.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Security**
* Builds now accept only the official Dockerfile frontend and Railpack’s
frontend. Builds that specify other frontends are refused.
* **Documentation**
* Updated build specifications and threat model to reflect frontend
restrictions and related security considerations.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: samuel mbabhazi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant