From 7fc85139a0766b1b448760bfb66659f09fae27b9 Mon Sep 17 00:00:00 2001 From: Vasili Pascal Date: Wed, 23 Sep 2026 15:53:54 +0300 Subject: [PATCH 1/3] ci: build the release binaries once, not twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A run takes 47 minutes, and the release binaries are compiled twice in it: once by the test job, then again from scratch inside the Docker build. The first set was already being packed into `app.tar.gz` and uploaded — nothing ever downloaded it. The reason it could not simply be reused is the one that has to be got right: the binaries are dynamically linked against glibc, and glibc is forward- but not backward-compatible. Built on the runner (Ubuntu 24.04, glibc 2.39) they would not start on debian:bookworm-slim (glibc 2.36). So the test job now runs inside `rust:bookworm` — the same image the Dockerfile builds in, and the one the runtime stage is derived from. The environments match exactly, and the Docker job copies the artifact instead of recompiling. The Dockerfile keeps both paths. `BINARIES=prebuilt` takes them from a build context; the default still compiles from source, so a local `docker build` works unchanged. Both were verified to parse, and the prebuilt path was built end to end: the four binaries, the config files and the sqlx CLI all land in the image with no compilation. Two things fell out along the way. The job now builds all four binaries the image needs — `console` and `backfill_field_policy` were missing from the artifact, which is part of why it could not be used. And `cargo install sqlx-cli` moved to its own small stage with only the postgres and rustls features, so the prebuilt path no longer pays 110 seconds of it to fetch two YAML files. Inside a job container, service containers resolve by name rather than 127.0.0.1, so PGHOST changes accordingly. Co-Authored-By: Claude Opus 5 --- .github/workflows/docker.yml | 57 ++++++++++++++++++++++++++++-------- Dockerfile | 54 ++++++++++++++++++++++++++++------ 2 files changed, 90 insertions(+), 21 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8ddc86d1..28446ec6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -19,6 +19,14 @@ jobs: name: Cargo and npm build runs-on: ubuntu-latest #runs-on: [self-hosted, linux] + # Build inside the same image the Dockerfile builds in, so the binaries + # produced here can be copied into the runtime image instead of being + # compiled a second time. They are dynamically linked against glibc, and + # glibc is forward- but not backward-compatible: a binary built on the + # runner (Ubuntu 24.04, glibc 2.39) would not start on debian:bookworm-slim + # (glibc 2.36). Building in rust:bookworm makes the two match exactly. + container: + image: rust:bookworm services: postgres: image: postgres:16 @@ -42,7 +50,9 @@ jobs: ref: ${{ github.ref }} - name: Export PostgreSQL connection env run: | - echo "PGHOST=127.0.0.1" >> "$GITHUB_ENV" + # Inside a job container, services resolve by name on the shared + # network — 127.0.0.1 is the container itself. + echo "PGHOST=postgres" >> "$GITHUB_ENV" echo "PGPORT=5432" >> "$GITHUB_ENV" echo "PGUSER=postgres" >> "$GITHUB_ENV" echo "PGPASSWORD=postgres" >> "$GITHUB_ENV" @@ -136,17 +146,16 @@ jobs: command: clippy args: -- -D warnings - - name: Build server (release) - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --bin server - - - name: Build cleanup-notify (release) - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --bin cleanup-notify + # One invocation, so the four binaries share a single compilation of the + # workspace instead of four sequential ones. These are the binaries the + # runtime image needs; the Docker job copies them rather than rebuilding. + - name: Build release binaries + run: | + cargo build --release \ + --bin server \ + --bin console --features explain \ + --bin cleanup-notify \ + --bin backfill_field_policy - name: Set up Node.js if: ${{ hashFiles('web/package.json') != '' }} @@ -181,7 +190,9 @@ jobs: run: | mkdir -p app/stacker/dist cp target/release/server app/stacker/server + cp target/release/console app/stacker/console cp target/release/cleanup-notify app/stacker/cleanup-notify + cp target/release/backfill_field_policy app/stacker/backfill_field_policy if [ -d web/dist ]; then cp -a web/dist/. app/stacker; fi cp Dockerfile app/Dockerfile cp access_control.conf.dist app/access_control.conf.dist @@ -210,6 +221,25 @@ jobs: run: | test -d "${GITHUB_WORKSPACE}/tests/fixtures/pipe-contract" + # The test job already compiled these, in the same rust:bookworm image the + # runtime stage is based on. Without this the Dockerfile compiles the whole + # workspace a second time — around fourteen minutes of the run. + - name: Download binaries built by the test job + uses: actions/download-artifact@v4 + with: + name: artifact-linux-docker + + - name: Unpack binaries + run: | + mkdir -p prebuilt + tar -xzf app.tar.gz -C prebuilt + # The build context expects them at its root. + mv prebuilt/stacker/server prebuilt/stacker/console \ + prebuilt/stacker/cleanup-notify prebuilt/stacker/backfill_field_policy \ + prebuilt/ + chmod +x prebuilt/server prebuilt/console \ + prebuilt/cleanup-notify prebuilt/backfill_field_policy + - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -235,8 +265,11 @@ jobs: uses: docker/build-push-action@v6 with: context: . + build-args: | + BINARIES=prebuilt build-contexts: | shared_fixtures=${{ github.workspace }}/tests/fixtures + prebuilt_binaries=${{ github.workspace }}/prebuilt push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.docker_tags.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index a04089a7..8ca9f0c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,22 @@ # syntax=docker/dockerfile:1.4 +# +# Two ways in, selected by the `binaries` build context: +# +# prebuilt — the CI job already compiled the release binaries and passes them +# in. It builds inside this same `rust:bookworm` image, so the +# glibc the binaries link against matches the runtime stage. That +# skips a second full compile of the workspace. +# +# builder — nothing was passed in (a local `docker build`, or CI without the +# artifact). Compiles from source, as before. +# +# Select with `--build-arg BINARIES=prebuilt`. Default is a self-contained build. +ARG BINARIES=builder + FROM rust:bookworm AS builder RUN apt-get update && apt-get install --no-install-recommends -y protobuf-compiler libprotobuf-dev && rm -rf /var/lib/apt/lists/* -RUN cargo install sqlx-cli - WORKDIR /app COPY --from=shared_fixtures / /shared-fixtures # copy manifests @@ -45,6 +57,30 @@ RUN apt-get update && apt-get install --no-install-recommends -y libssl-dev; \ #RUN ls -la /app/target/release/ >&2 +# Config files and the sqlx CLI, needed by both paths. Separate from `builder` +# so the prebuilt path does not drag in a compile of the workspace just to get +# two YAML files. +FROM rust:bookworm AS config +RUN cargo install sqlx-cli --no-default-features --features rustls,postgres +WORKDIR /app +COPY ./docker/local/.env . +COPY ./docker/local/configuration.yaml . + +# The two sources of binaries, each putting them at the image root so the +# production stage copies from one place regardless of which was used. + +# Handed in by CI, already compiled in this same rust:bookworm image. +FROM scratch AS prebuilt-source +COPY --from=prebuilt_binaries / / + +FROM scratch AS builder-source +COPY --from=builder /app/target/release/server /server +COPY --from=builder /app/target/release/console /console +COPY --from=builder /app/target/release/cleanup-notify /cleanup-notify +COPY --from=builder /app/target/release/backfill_field_policy /backfill_field_policy + +FROM ${BINARIES}-source AS binaries + # deploy production FROM debian:bookworm-slim AS production @@ -54,13 +90,13 @@ WORKDIR /app RUN mkdir ./files && chmod 0777 ./files # copy binary and configuration files -COPY --from=builder /app/target/release/server . -COPY --from=builder /app/target/release/console . -COPY --from=builder /app/target/release/cleanup-notify . -COPY --from=builder /app/target/release/backfill_field_policy . -COPY --from=builder /app/.env . -COPY --from=builder /app/configuration.yaml . -COPY --from=builder /usr/local/cargo/bin/sqlx /usr/local/bin/sqlx +COPY --from=binaries /server . +COPY --from=binaries /console . +COPY --from=binaries /cleanup-notify . +COPY --from=binaries /backfill_field_policy . +COPY --from=config /app/.env . +COPY --from=config /app/configuration.yaml . +COPY --from=config /usr/local/cargo/bin/sqlx /usr/local/bin/sqlx COPY ./access_control.conf.dist ./access_control.conf EXPOSE 8000 From a865c3f00e66c0d15032152b5f2c13316f2d6c03 Mon Sep 17 00:00:00 2001 From: Vasili Pascal Date: Wed, 23 Sep 2026 16:08:21 +0300 Subject: [PATCH 2/3] docs: restore the config_contract reference, with names that parse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reference documented `required_env:` under `config_contract`. No such field exists — the parser knows `required`, and since every contract type denies unknown fields, anyone following the example would have had their submission rejected. Removing it was right. It took the whole section with it, though, leaving the reference with no description of field policy at all: only the volume subsection added last week remained. An author reading this file would not learn that `mutability` exists. The design document in config/docs covers it, but that is not where someone writing a stacker.yml looks. Restored with the four mutabilities, the keys that apply to each, the legacy three-list shorthand, and a note that publishing is refused until secret-shaped fields carry a policy. Every example here was run through the parser, including the removed `required_env`, which is confirmed to be rejected. Co-Authored-By: Claude Opus 5 --- docs/STACKER_YML_REFERENCE.md | 76 ++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/docs/STACKER_YML_REFERENCE.md b/docs/STACKER_YML_REFERENCE.md index ac7212b1..da7658fe 100644 --- a/docs/STACKER_YML_REFERENCE.md +++ b/docs/STACKER_YML_REFERENCE.md @@ -23,7 +23,6 @@ - [install — Marketplace Install Inputs](#install) - [environments — Named Environments](#environments) - [volumes — Named Volumes](#volumes) -- [config_contract — Service Config Contracts](#config_contract) - [ai — AI Assistant](#ai) - [monitoring — Health & Metrics](#monitoring) - [status_panel](#monitoringstatus_panel) · [healthcheck](#monitoringhealthcheck) · [metrics](#monitoringmetrics) · [alerts](#monitoringalerts) @@ -847,6 +846,62 @@ environments: --- +## `config_contract` + +Declares who controls each of a service's inputs when somebody else installs the +stack. Read at publish time and on the marketplace install path; ignored by a +plain local deploy. + +Without it, the literal values that are correct for *your* deployment — a +`JWT_SECRET`, a database password — are copied verbatim into every buyer's +install, so every buyer and you share one set of credentials. + +```yaml +config_contract: + services: + my-service: # must match a service name, or `app` + fields: + DATABASE_URL: + mutability: fixed # your value ships as-is + LOG_LEVEL: + mutability: editable # your value is a default the buyer may override + LICENSE_KEY: + mutability: provided # the buyer must supply it; yours is never shipped + SECRET_KEY: + mutability: generated # a fresh value per install; the buyer never types it + type: alphanumeric + length: 32 + display: password +``` + +| Key | Applies to | Meaning | +|---|---|---| +| `mutability` | every field | `fixed`, `editable`, `provided` or `generated` — see above | +| `required` | every field | whether a value must resolve at all. Default `true` | +| `type` | `generated` | `hex`, `base64`, `alphanumeric`, `uuid`, `enum`, `derived_jwt` | +| `length` / `min_length` | `generated` | exact or minimum length | +| `values` | `enum` | the allowed set | +| `signing_key`, `claims`, `alg` | `derived_jwt` | `"service.FIELD"` to sign with, the claims, and one of `HS256`/`HS384`/`HS512` | +| `display` | any field | UI hint — `boolean`, `string`, `number`, `password`. Independent of `type` | + +Publishing to the marketplace is refused until every secret-shaped field carries +a `generated` or `provided` policy. + +**Shorthand.** Three plain lists are still accepted and mean +`fixed`+required, `fixed`+optional, and `generated` respectively: + +```yaml +config_contract: + services: + my-service: + required: [DATABASE_URL] + optional: [LOG_LEVEL] + secret: [SECRET_KEY] +``` + +Mixing is fine; an explicit `fields:` entry wins over a list mentioning the same +name. + ### Volume policy in `config_contract` A baked marketplace image is cloned for every buyer, and a volume that travels @@ -905,25 +960,6 @@ Named volumes referenced in `app.volumes` or `services[].volumes` but not listed --- -## `config_contract` - -*Optional* · `object` · Default: none - -Declares service-level configuration contracts — metadata consumed by the TryDirect Install Service and marketplace pipeline to validate and pre-populate service inputs. Not used during local deploys. - -```yaml -config_contract: - services: - my-service: - required_env: - - DATABASE_URL - - SECRET_KEY -``` - -> This section is primarily written by `stacker install` and the marketplace generator. You rarely need to set it by hand. - ---- - ## `ai` *Optional* · `object` · Default: `enabled: false` From 492a29bc6483febeca3cbcf978af3b636326feea Mon Sep 17 00:00:00 2001 From: Vasili Pascal Date: Wed, 23 Sep 2026 17:10:42 +0300 Subject: [PATCH 3/3] ci: fix what moving the job into a container broke MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The run failed on `sudo: not found`. The container runs as root and does not ship sudo, and it does not need to: `rust:bookworm` already has pkg-config, libssl-dev and a C toolchain, and protoc never comes from the system — `build.rs` points PROTOC at a vendored binary unless one is set. Verified against the image. The step is gone. The error that was actually reported was `no such command: nextest`, which is not what went wrong. Both test steps carried `if: always()`, so they ran after the setup step failed and the nextest install had been skipped. Dropped on the first, narrowed to `success() || failure()` on the second, which is what was wanted: run both suites even if one fails, without reporting on an environment that was never built. Two more, found while looking rather than by the next 47-minute run: `--features explain` applies to the whole `cargo build`, not to the `--bin` it follows, so folding four binaries into one invocation was quietly shipping `server` with explain-logging on — a different binary from the one the image has always carried. Split in two; only `console` and the re-featured casbin dependency recompile. `.dockerignore` is empty, so the unpacked binaries and `app.tar.gz` were being sent to buildkit as part of `context: .` — hundreds of megabytes, twice, eating back the time this change exists to save. They now unpack to `runner.temp`. Co-Authored-By: Claude Opus 5 --- .github/workflows/docker.yml | 46 +++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 28446ec6..8b97853b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -57,11 +57,11 @@ jobs: echo "PGUSER=postgres" >> "$GITHUB_ENV" echo "PGPASSWORD=postgres" >> "$GITHUB_ENV" - - name: Install OpenSSL and protoc build deps - if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y pkg-config libssl-dev protobuf-compiler + # No apt step here: `rust:bookworm` already carries pkg-config, libssl-dev + # and a C toolchain, and protoc never comes from the system — `build.rs` + # points PROTOC at a vendored binary unless one is already set. The step + # that used to be here called `sudo`, which the image does not have, and + # does not need: the job runs as root. - name: Verify .sqlx cache exists run: | @@ -118,12 +118,16 @@ jobs: # env vars no longer race and the suite runs in parallel (no more # RUST_TEST_THREADS=1 serialization, no 25-minute timeout). The `bdd` # target uses a custom harness nextest cannot run, so it runs separately. + # Both suites run even if one of them fails, so a single broken test does + # not hide the state of the other. Not `always()`: that also runs them + # after an earlier *setup* step fails, and then reports something + # unrelated — a missing apt package once surfaced as "no such command: + # nextest", because the install step had been skipped. - name: Cargo test - if: ${{ always() }} run: cargo nextest run --tests -E 'not binary(bdd)' - name: Cargo test (bdd suite) - if: ${{ always() }} + if: success() || failure() run: cargo test --test bdd - name: Rustfmt @@ -149,13 +153,18 @@ jobs: # One invocation, so the four binaries share a single compilation of the # workspace instead of four sequential ones. These are the binaries the # runtime image needs; the Docker job copies them rather than rebuilding. + # Two invocations, not one: `--features` applies to the whole command, not + # to the `--bin` it follows. Listing them together builds `server` with + # `explain` too — a differently configured binary from the one the image + # has always shipped. The second call is nearly free; only `console` and + # the re-featured casbin dependency recompile. - name: Build release binaries run: | cargo build --release \ --bin server \ - --bin console --features explain \ --bin cleanup-notify \ --bin backfill_field_policy + cargo build --release --bin console --features explain - name: Set up Node.js if: ${{ hashFiles('web/package.json') != '' }} @@ -229,16 +238,19 @@ jobs: with: name: artifact-linux-docker + # Unpacked outside the workspace: `.dockerignore` is empty, so anything + # left here is sent to buildkit as part of `context: .` — hundreds of + # megabytes of release binaries, twice, eating back the time this change + # exists to save. - name: Unpack binaries run: | - mkdir -p prebuilt - tar -xzf app.tar.gz -C prebuilt - # The build context expects them at its root. - mv prebuilt/stacker/server prebuilt/stacker/console \ - prebuilt/stacker/cleanup-notify prebuilt/stacker/backfill_field_policy \ - prebuilt/ - chmod +x prebuilt/server prebuilt/console \ - prebuilt/cleanup-notify prebuilt/backfill_field_policy + mkdir -p "${{ runner.temp }}/prebuilt" + tar -xzf app.tar.gz -C "${{ runner.temp }}/prebuilt" + cd "${{ runner.temp }}/prebuilt" + mv stacker/server stacker/console stacker/cleanup-notify \ + stacker/backfill_field_policy . + chmod +x server console cleanup-notify backfill_field_policy + rm -f "${GITHUB_WORKSPACE}/app.tar.gz" - name: Set up QEMU @@ -269,7 +281,7 @@ jobs: BINARIES=prebuilt build-contexts: | shared_fixtures=${{ github.workspace }}/tests/fixtures - prebuilt_binaries=${{ github.workspace }}/prebuilt + prebuilt_binaries=${{ runner.temp }}/prebuilt push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.docker_tags.outputs.tags }}