Repository navigation
feat(agent): BuildImage builds with Railpack and Nixpacks (part of #215) - #540
Merged
Merged
Conversation
Signed-off-by: samuel mbabhazi <[email protected]>
…t (part of #215) Signed-off-by: samuel mbabhazi <[email protected]>
|
Warning Review limit reachedYou'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. View limit details
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. |
Collaborator
Author
|
@coderabbitai review |
Action not completed
|
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #215 (M3.3: "Dockerfile, Railpack, Nixpacks, image").
What changed
The agent's
BuildImagenow 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 build /src --out /outfrom that static binary alone: no network, the repository mounted read-only, every argument one argv entry.docker buildcommand Nixpacks writes in.nixpacks/build.sh, in memory, and keeps only--build-arg NAME=VALUEpairs with environment variable names, neverBUILDKIT_…. The application's own arguments override them..nixpacks/Dockerfileover the repository with Nixpacks' files merged on top.railpack prepareruns in Railpack's frontend image v0.43.0, pinned by its index digest, with the repository read-only.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.secrets-hashso that a new value rebuilds.build_typemay berailpackornixpacks, which take nodockerfile(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
secrets-hashthat changes with a value, arguments never in attrs;build.shparsing with malicious content:BUILDKIT_SYNTAX, invalid names, missing values, oversized values and script, invalid UTF-8, otherdocker buildflags, the 200 bound.BuildImageinput checks: unknown type, a Dockerfile path on Railpack or Nixpacks, arguments that look like flags.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.go test ./agent/... ./cli/... ./lib/...,golangci-lint(also with theintegrationtag) and Semgrep are clean.The diff is about 920 lines, half of them tests; prettier also realigned the SPEC action table.
Security considerations
BUILDKIT_…names are dropped so a repository cannot pick another frontend through them.