Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#
# npm dist-tag add @extenddb/dev@<version> latest (and one per platform pkg)
#
# With the `dry_run` input the run ends after the build jobs: the gates and
# the five native builds, smoke tests and launcher suites run as for a
# release, and nothing is published; dry runs have a concurrency group of
# their own (release-image.yml).
#
# Shape, and why (mirrors .github/workflows/release-image.yml):
#
# gate Runs once. Cheap checks that need no build: the dispatch input is
Expand Down Expand Up @@ -78,6 +83,10 @@ on:
tag:
description: 'Existing release tag to publish npm candidates for, e.g. v0.1.4'
required: true
dry_run:
description: 'Rehearse only: run the gates and the five platform builds with their smoke tests and launcher suites; publish nothing'
type: boolean
default: false

# Nothing is committed, so no write scope on the repo is needed. The publish
# job adds id-token at job level, which is what both authenticates to npm
Expand All @@ -87,7 +96,7 @@ permissions:

# Two launcher releases must never race.
concurrency:
group: npm-publish-extenddb
group: npm-publish-extenddb${{ inputs.dry_run && '-dry' || '' }}
cancel-in-progress: false

jobs:
Expand Down Expand Up @@ -200,9 +209,36 @@ jobs:
uses: ./.github/workflows/npm-build-matrix.yml
with:
ref: ${{ needs.gate.outputs.sha }}
# A release stops at the first failing platform; a rehearsal lets all
# five report.
fail-fast: ${{ !inputs.dry_run }}

# A rehearsal's end: the gates and the builds ran as the release runs them,
# and nothing was published. The publish-side jobs are skipped by their
# `if`, so their environments ask no approval.
dry-run-summary:
needs: [gate, build]
if: ${{ inputs.dry_run }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Summarise the rehearsal
run: |
{
echo "### Dry run: gates and builds passed, nothing published"
echo ""
echo "The five platform binaries built, passed their smoke tests and the launcher suite. Dispatch again without the dry run to publish the candidates."
echo ""
echo "| field | value |"
echo "|---|---|"
echo "| tag | \`v${{ needs.gate.outputs.version }}\` |"
echo "| commit | \`${{ needs.gate.outputs.sha }}\` |"
echo "| version (from tag) | \`${{ needs.gate.outputs.version }}\` |"
} >> "$GITHUB_STEP_SUMMARY"

publish:
needs: [gate, build]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
timeout-minutes: 15
# The protected environment requires reviewer approval, and its name is
Expand Down
62 changes: 40 additions & 22 deletions .github/workflows/release-dev-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
# promote-registry composite action — signature verified at each destination
# before any tag is placed, forward-only latest per destination. The attest
# job runs beside propagate and attests the build provenance and the SBOMs
# (see release-image.yml for the design).
# (see release-image.yml for the design). With the `dry_run` input the run
# ends after the build jobs and publishes nothing, in a concurrency group of
# its own (release-image.yml).
#
# Re-entrant on registry state: if the version tag already exists on Docker
# Hub WITH a verifying signature, the publish job treats the published,
Expand Down Expand Up @@ -59,12 +61,16 @@ on:
tag:
description: 'Existing version tag to release, e.g. v0.1.6'
required: true
dry_run:
description: 'Rehearse only: run the gates and both builds with their smoke tests, scans and SBOMs; publish, sign, mirror and attest nothing'
type: boolean
default: false

permissions:
contents: read

concurrency:
group: release-image-extenddb-dev
group: release-image-extenddb-dev${{ inputs.dry_run && '-dry' || '' }}
cancel-in-progress: false

env:
Expand Down Expand Up @@ -155,7 +161,9 @@ jobs:
build:
needs: gate
strategy:
fail-fast: true
# A release stops at the first failing architecture; a rehearsal lets
# both report.
fail-fast: ${{ !inputs.dry_run }}
matrix:
include:
- arch: amd64
Expand Down Expand Up @@ -268,25 +276,11 @@ jobs:
"$TRIVY_IMAGE" image --input /image.tar.gz \
--format cyclonedx --no-progress --skip-version-check \
> "sbom/sbom-${ARCH}.cdx.json"
REQUIRE_CRATES=0
grep -q 'cargo auditable build' Dockerfile.dev && REQUIRE_CRATES=1
python3 - "sbom/sbom-${ARCH}.cdx.json" "$REQUIRE_CRATES" <<'PY'
import json, re, sys
bom = json.load(open(sys.argv[1]))
crates = [c for c in bom.get("components", []) if c.get("purl", "").startswith("pkg:cargo/")]
ids = [p.get("value", "") for p in bom.get("metadata", {}).get("component", {}).get("properties", [])
if p.get("name") == "aquasecurity:trivy:ImageID"]
if (bom.get("bomFormat") != "CycloneDX" or not bom.get("components") or len(ids) != 1
or not re.fullmatch(r"sha256:[0-9a-f]{64}", ids[0])):
print(f"::error::{sys.argv[1]} is not a CycloneDX SBOM of one image")
sys.exit(1)
if not crates:
if sys.argv[2] == "1":
print(f"::error::{sys.argv[1]} lists no crates, but Dockerfile.dev builds with cargo-auditable")
sys.exit(1)
print(f"::warning::{sys.argv[1]} lists no crates: this tag's Dockerfile.dev predates cargo-auditable")
print(f"{len(bom['components'])} components, {len(crates)} of them crates; image {ids[0]}")
PY
# The check is devtools/check-image-sbom at the tagged commit, shared
# with devtools/release-dry-run; a tag from before it has none.
[[ -x devtools/check-image-sbom ]] \
|| { echo "::error::tagged commit has no devtools/check-image-sbom; use a tag created after it was merged"; exit 1; }
devtools/check-image-sbom "sbom/sbom-${ARCH}.cdx.json" Dockerfile.dev

- name: Upload the SBOM artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
Expand All @@ -303,8 +297,32 @@ jobs:
retention-days: 1
compression-level: 0

# A rehearsal's end: the gates and the builds ran as the release runs them,
# and nothing was published. The publish-side jobs are skipped by their
# `if`, so their environments ask no approval.
dry-run-summary:
needs: [gate, build]
if: ${{ inputs.dry_run }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Summarise the rehearsal
run: |
{
echo "### Dry run: gates and builds passed, nothing published"
echo ""
echo "Both architectures of \`${{ env.IMAGE_REPO }}\` built, passed the smoke test and the vulnerability scan, and produced SBOMs. Dispatch again without the dry run to publish."
echo ""
echo "| field | value |"
echo "|---|---|"
echo "| tag | \`v${{ needs.gate.outputs.version }}\` |"
echo "| commit | \`${{ needs.gate.outputs.sha }}\` |"
echo "| version (from tag) | \`${{ needs.gate.outputs.version }}\` |"
} >> "$GITHUB_STEP_SUMMARY"

publish:
needs: [gate, build]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
timeout-minutes: 30
environment: dockerhub # approval 1: publish + sign (Docker Hub credential lives here)
Expand Down
67 changes: 46 additions & 21 deletions .github/workflows/release-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
# environment approval. Any defect's blast radius stays a tag no user
# consumes.
#
# With the `dry_run` input the run ends after the build jobs: the gates and
# both builds, smoke tests, scans and SBOMs run as for a release, and nothing
# is published, signed or attested. A release rehearsal dispatches the three
# publish workflows (this one per image, release-dev-image, npm-publish) this
# way against the tag first, then again for real. Dry runs have a
# concurrency group of their own, so a dry run never cancels a pending
# release. devtools/release-dry-run runs the same gate and build steps on
# a developer's machine, for the host's architecture.
#
# Shape, and why:
#
# gate Runs once. Cheap checks that do not need a build, so a bad input
Expand Down Expand Up @@ -81,6 +90,10 @@ on:
- extenddb-mongodb
- extenddb-cassandra
default: extenddb-postgres
dry_run:
description: 'Rehearse only: run the gates and both builds with their smoke tests, scans and SBOMs; publish, sign, mirror and attest nothing'
type: boolean
default: false

# Nothing is committed, so no write scope on the repo is needed.
permissions:
Expand All @@ -89,7 +102,7 @@ permissions:
# Two releases must never race. The group names the image, so a future second
# backend does not serialise behind this one for no reason.
concurrency:
group: release-image-${{ inputs.image }}
group: release-image-${{ inputs.image }}${{ inputs.dry_run && '-dry' || '' }}
cancel-in-progress: false

env:
Expand Down Expand Up @@ -252,7 +265,9 @@ jobs:
# If one architecture fails, cancel the other: nothing is published either
# way, so there is no point paying for the rest of the matrix.
strategy:
fail-fast: true
# A release stops at the first failing architecture; a rehearsal lets
# both report.
fail-fast: ${{ !inputs.dry_run }}
matrix:
include:
- arch: amd64
Expand Down Expand Up @@ -402,25 +417,11 @@ jobs:
"$TRIVY_IMAGE" image --input /image.tar.gz \
--format cyclonedx --no-progress --skip-version-check \
> "sbom/sbom-${ARCH}.cdx.json"
REQUIRE_CRATES=0
grep -q 'cargo auditable build' "$DOCKERFILE" && REQUIRE_CRATES=1
python3 - "sbom/sbom-${ARCH}.cdx.json" "$REQUIRE_CRATES" <<'PY'
import json, re, sys
bom = json.load(open(sys.argv[1]))
crates = [c for c in bom.get("components", []) if c.get("purl", "").startswith("pkg:cargo/")]
ids = [p.get("value", "") for p in bom.get("metadata", {}).get("component", {}).get("properties", [])
if p.get("name") == "aquasecurity:trivy:ImageID"]
if (bom.get("bomFormat") != "CycloneDX" or not bom.get("components") or len(ids) != 1
or not re.fullmatch(r"sha256:[0-9a-f]{64}", ids[0])):
print(f"::error::{sys.argv[1]} is not a CycloneDX SBOM of one image")
sys.exit(1)
if not crates:
if sys.argv[2] == "1":
print(f"::error::{sys.argv[1]} lists no crates, but the Dockerfile builds with cargo-auditable")
sys.exit(1)
print(f"::warning::{sys.argv[1]} lists no crates: this tag's Dockerfile predates cargo-auditable")
print(f"{len(bom['components'])} components, {len(crates)} of them crates; image {ids[0]}")
PY
# The check is devtools/check-image-sbom at the tagged commit, shared
# with devtools/release-dry-run; a tag from before it has none.
[[ -x devtools/check-image-sbom ]] \
|| { echo "::error::tagged commit has no devtools/check-image-sbom; use a tag created after it was merged"; exit 1; }
devtools/check-image-sbom "sbom/sbom-${ARCH}.cdx.json" "$DOCKERFILE"

- name: Upload the SBOM artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
Expand All @@ -437,8 +438,32 @@ jobs:
retention-days: 1
compression-level: 0 # already gzipped

# A rehearsal's end: the gates and the builds ran as the release runs them,
# and nothing was published. The publish-side jobs are skipped by their
# `if`, so their environments ask no approval.
dry-run-summary:
needs: [gate, build]
if: ${{ inputs.dry_run }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Summarise the rehearsal
run: |
{
echo "### Dry run: gates and builds passed, nothing published"
echo ""
echo "Both architectures of \`${{ needs.gate.outputs.image_repo }}\` built, passed the smoke test and the vulnerability scan, and produced SBOMs. Dispatch again without the dry run to publish the candidate."
echo ""
echo "| field | value |"
echo "|---|---|"
echo "| tag | \`v${{ needs.gate.outputs.version }}\` |"
echo "| commit | \`${{ needs.gate.outputs.sha }}\` |"
echo "| version (from tag) | \`${{ needs.gate.outputs.version }}\` |"
} >> "$GITHUB_STEP_SUMMARY"

publish-candidate:
needs: [gate, build]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
timeout-minutes: 45
environment: dockerhub # approval 1: publish + sign (the only job with Docker Hub secrets)
Expand Down
69 changes: 69 additions & 0 deletions devtools/check-image-sbom
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
# Copyright 2026 ExtendDB contributors
# SPDX-License-Identifier: Apache-2.0
"""Check the CycloneDX SBOM trivy wrote for one container image.

devtools/check-image-sbom SBOM.cdx.json DOCKERFILE

The SBOM must be CycloneDX with components and carry exactly one
`aquasecurity:trivy:ImageID` of the sha256 form, so it describes one image.
When DOCKERFILE builds with `cargo auditable build`, the SBOM must list the
crates the binary embeds; otherwise a missing crate list is a warning, since
the image's binary carries no dependency record for trivy to read.

The release workflows' build jobs (release-image.yml, release-dev-image.yml)
and devtools/release-dry-run run this on the SBOM they generate. Under GitHub
Actions (GITHUB_ACTIONS set) the messages are workflow annotations.

Exit 0 when the SBOM passes, 1 otherwise, 2 on a usage error.
"""

import json
import os
import pathlib
import re
import sys


def main() -> int:
if len(sys.argv) != 3:
print(__doc__.strip().splitlines()[2].strip(), file=sys.stderr)
return 2
sbom_path, dockerfile = pathlib.Path(sys.argv[1]), pathlib.Path(sys.argv[2])
on_actions = os.environ.get("GITHUB_ACTIONS") == "true"
error = "::error::" if on_actions else "error: "
warning = "::warning::" if on_actions else "warning: "

try:
bom = json.loads(sbom_path.read_text(encoding="utf-8"))
except (OSError, ValueError) as e:
print(f"{error}{sbom_path} is not readable JSON: {e}")
return 1
components = bom.get("components") or []
crates = [c for c in components if str(c.get("purl", "")).startswith("pkg:cargo/")]
ids = [
p.get("value", "")
for p in bom.get("metadata", {}).get("component", {}).get("properties", [])
if p.get("name") == "aquasecurity:trivy:ImageID"
]
if (
bom.get("bomFormat") != "CycloneDX"
or not components
or len(ids) != 1
or not re.fullmatch(r"sha256:[0-9a-f]{64}", ids[0])
):
print(f"{error}{sbom_path} is not a CycloneDX SBOM of one image")
return 1

require_crates = "cargo auditable build" in dockerfile.read_text(encoding="utf-8")
if not crates:
if require_crates:
print(f"{error}{sbom_path} lists no crates, but {dockerfile} builds with cargo-auditable")
return 1
print(f"{warning}{sbom_path} lists no crates: {dockerfile} does not build with cargo-auditable")
print(f"{len(components)} components, {len(crates)} of them crates; image {ids[0]}")
return 0


if __name__ == "__main__":
sys.exit(main())
Loading
Loading