Skip to content

Have an external builder build a hosted file - #887

Open
simonchrz wants to merge 4 commits into
git-pkgs:mainfrom
simonchrz:feat/builds
Open

simonchrz wants to merge 4 commits into
git-pkgs:mainfrom
simonchrz:feat/builds

Conversation

@simonchrz

@simonchrz simonchrz commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

The proxy can scan what it stores through external scanners. This adds the counterpart for building: the proxy asks an external builder for a file and hosts what the builder uploads. The proxy itself builds nothing.

It is off by default and needs hosted.enabled.

How it works

  1. POST /api/builds (hosted token) names a builder, a package name, a version and a filename.
  2. The proxy POSTs the request to that builder with two URLs signed for this one build: upload_url and failure_url.
  3. The builder answers 2xx at once, builds on its own time, and PUTs the file to upload_url.
  4. The file goes through the same path as a hosted push (PushLocalArtifact), so it is scanned, immutable and never evicted, and is served at /generic/hosted/{name}/{version}/{filename}.

GET /api/builds/{id} returns the status (requested, building, done, failed). The package page lists builds that are open or failed.

What is in here

  • internal/builder: a Builder interface and HTTPBuilder, its one implementation, laid out like internal/scanner.
  • building.builders[].body: an optional body template, so the request can take the shape of another system's API. docs/configuration.md has examples for a GitHub workflow_dispatch and a GitLab pipeline trigger. A template that doesn't parse, or leaves a value unescaped in a JSON body, is refused when the configuration is loaded.
  • A builds table (migration 027_add_builds), so a build's status outlasts a restart and the builder can upload to the instance that replaced the one that asked.
  • Docs: a "Building hosted files" section with the builder contract, the OpenAPI entries and a section in config.example.yaml.

Open questions

  • Is this in scope for the proxy? I opened it as a draft to have something concrete to discuss; I'm happy to move the discussion to an issue or to cut it down.
  • Body templates. Scanning has one fixed format and leaves other systems to adapters. The template goes further than that. It can be dropped without touching the rest.
  • env in templates. A template can read any environment variable of the proxy. It is needed where a token goes in the body (GitLab trigger), and only whoever writes the configuration can use it.
  • Generic files only, one file per build.
  • Several instances on one database. Two requests for the same file at two instances at the same moment can record two builds; within one instance they can't. The second upload is refused as the file is already hosted.

Testing

Unit tests for the builder package, the config validation, the database queries and the API, including restarts on the same database. I ran it end to end against a small build service of my own, with two real builds (ffmpeg and hashcat for linux/arm64). I have not run the GitHub or GitLab examples against the real services, and the new table has only run on SQLite locally.

Refs #888

Summary by CodeRabbit

  • New Features
    • Added support for requesting hosted files from configured external builders and tracking build progress.
    • Package pages now show recent build statuses, including failures and active builds, and refresh automatically while a build is in progress.
    • Added authenticated build requests and build-status lookups, with configurable builder settings and request templates.
  • Documentation
    • Documented builder configuration, build requests and statuses, and setup examples for GitHub Actions and GitLab.

POST /api/builds asks for one hosted generic file. The proxy passes the request to a configured builder with an upload URL signed for that build, and stores what the builder PUTs there as a hosted file. The builder holds no token. The package page lists a package's open and failed builds.

Builds are kept in memory only. Not documented, no swagger.
A build's status now outlasts a restart: the builder can upload to the proxy that replaced the one that asked, and a failed build keeps its reason. A build ends once, through one conditional update. Builds past their time are failed before every read instead of on a timer, so it doesn't matter whether the instance that asked is still running. Finished builds are deleted after 30 days.
internal/builder holds the Builder interface and HTTPBuilder, its one implementation, as internal/scanner does for scanners. A builder can have a body template and a content type, so the request can take the shape of another system's API, such as a GitHub workflow dispatch or a GitLab pipeline trigger. A template that doesn't parse, or leaves a value unescaped in a JSON body, is refused when the configuration is loaded. The builder contract is documented in docs/configuration.md.
…out writing

The /api/builds endpoints are in the OpenAPI document, the four scalar building settings can be set from the environment, and the example config has a building section. A read no longer updates the database: an open build past its time is shown as failed, and the next build request records it.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

CodeRabbit ASCII loading animation

Currently processing new changes in this PR. This may take a few minutes, please wait...

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b7b2f5e9-ce8b-41fd-8ce5-b2da54c4e3d1
Commits

Reviewing files that changed from the base of the PR and between 06815a6 and 19f5210.

Files selected for processing: 19

  • config.example.yaml
  • docs/configuration.md
  • docs/swagger/docs.go
  • docs/swagger/swagger.json
  • internal/builder/builder.go
  • internal/builder/http.go
  • internal/builder/http_test.go
  • internal/config/building.go
  • internal/config/building_test.go
  • internal/config/config.go
  • internal/database/builds.go
  • internal/database/builds_test.go
  • internal/database/schema.go
  • internal/server/builds_api.go
  • internal/server/builds_api_test.go
  • internal/server/dashboard.go
  • internal/server/hosted_api_test.go
  • internal/server/server.go
  • internal/server/templates/pages/package_show.html

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant