From cf736a850f1d2993e5f04cfc50996f4b34240fa5 Mon Sep 17 00:00:00 2001 From: x1unix <9203548+x1unix@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:48:37 -0500 Subject: [PATCH 1/6] feat: Add RPM packages build using a shared spec Update SRPM spec generator to generate a spec shared among rpmbuild and debbuild Signed-off-by: x1unix <9203548+x1unix@users.noreply.github.com> --- .github/workflows/build.yml | 30 +++ AGENTS.md | 7 +- CONTRIBUTING.md | 38 +++- Makefile | 27 +++ packaging/builder/debsources.go | 2 +- packaging/builder/debspec.go | 95 ++++++---- packaging/builder/debspec_test.go | 177 +++++++++++++++--- packaging/builder/opentelemetry-deb.spec.tmpl | 103 ---------- packaging/builder/opentelemetry.spec.tmpl | 147 +++++++++++++++ packaging/builder/stage.go | 118 ++++++++---- packaging/repo/debbuild-rebuild.sh | 2 +- packaging/repo/rpm-obs-rebuild.sh | 76 ++++++++ 12 files changed, 598 insertions(+), 224 deletions(-) delete mode 100644 packaging/builder/opentelemetry-deb.spec.tmpl create mode 100644 packaging/builder/opentelemetry.spec.tmpl create mode 100755 packaging/repo/rpm-obs-rebuild.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2205bf19..0d24832c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -163,6 +163,36 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: make check-reproducible-deb-sources-python + # The same generated specs, built with rpmbuild the way OBS builds the Fedora and EL repositories, then checked by the RPM metadata tests. + rpm-source-rebuild: + strategy: + fail-fast: false + matrix: + include: + - image: registry.fedoraproject.org/fedora:44 + skip: "" + # The oldest rpm the specs have to parse under. + # The Python package is not built for EL, whose interpreter does not match the bundled wheels. + - image: docker.io/almalinux/9-base + skip: python + arch: [ "amd64", "arm64" ] + runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }} + steps: + - name: Check out the codebase. + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Write the sources + env: + GITHUB_TOKEN: ${{ github.token }} + SOURCE_DATE_EPOCH: "1700000000" + run: make deb-sources VERSION=0.0.0-dev + + - name: Build the specs with rpmbuild and check the metadata + run: make integration-test-obs-rpm-rebuild ARCH=${{ matrix.arch }} RPM_REBUILD_IMAGE=${{ matrix.image }} RPM_REBUILD_SKIP=${{ matrix.skip }} + integration-tests: needs: build-packages strategy: diff --git a/AGENTS.md b/AGENTS.md index f979a717..62a94909 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,7 +19,7 @@ make srpm-container # Same, running rpmbuild in a container instead make srpm-sources # Generated spec + vendored source tarball only make rpm-rebuild-container # Rebuild the SRPM into binary RPMs the way COPR does # REBUILD_IMAGE=almalinux:9 to exercise the EL rpm -make deb-sources # debbuild specs + staged source archives for OBS (build/deb-sources//), each at its upstream version +make deb-sources # Unified spec (debbuild and rpmbuild) + staged source archives for OBS (build/deb-sources//), each at its upstream version make deb-sources- # Same, for one component make check-reproducible-deb-sources- # Write one component's DEB sources twice and fail unless byte-identical make deb-rebuild-container # Build those specs with debbuild the way OBS does @@ -30,6 +30,9 @@ make python-unit-tests # sitecustomize.py unit tests (throwaway venv, no make pyproto-unit-tests # Vendored pyproto exporter test suites (throwaway venvs, no containers) make integration-test-metadata # Fast metadata tests (no containers) make integration-test-deb-rebuild # Same metadata tests over the debbuild output +make obs-rpm-rebuild-container # Build the same specs with rpmbuild the way OBS does + # RPM_REBUILD_IMAGE=docker.io/almalinux/9-base RPM_REBUILD_SKIP=python for EL +make integration-test-obs-rpm-rebuild # RPM metadata tests over the rpmbuild output make integration-tests # Full E2E tests (requires Podman/Docker) make integration-test-deb-java # Single E2E test make integration-test-deb-lifecycle # Package lifecycle tests (preload, config, install/remove) @@ -45,7 +48,7 @@ make clean # Remove build/ - `.copr/Makefile` — COPR "make srpm" entry point; installs the tooling and delegates to `make srpm` - `cmd/build-packages/` — CLI entry point; calls `packaging/builder/` - `cmd/build-spec/rpm/` — source RPM spec generation and rpmbuild payload staging -- `cmd/build-spec/deb/` — debbuild spec and pre-staged source archive per component, for the OBS DEB build +- `cmd/build-spec/deb/` — unified spec and pre-staged source archive per component, built by debbuild and rpmbuild on OBS - `cmd/package-metadata/` — CI build plans: package images (`-target images`) and OBS uploads (`-target obs`) - `cmd/obs-publish/` + `packaging/obs/` — OBS API client that commits one package's sources, waits for every build of that revision, and releases it (used by `.github/workflows/obs.yml`) - `packaging/changes/` — maps changed paths to the components they affect, shared by the image and OBS workflows diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1c3d0178..49e38fdd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,7 +28,7 @@ Every `make` invocation in this document is then `gmake` instead. .copr/Makefile COPR "make srpm" entry point (installs the tooling, then calls make srpm) cmd/build-packages/ CLI entry point for building .deb and .rpm packages cmd/build-spec/rpm/ CLI entry point for generating and staging the source RPM spec -cmd/build-spec/deb/ CLI entry point for writing the debbuild specs and source archives built on OBS +cmd/build-spec/deb/ CLI entry point for writing the specs and source archives built on OBS cmd/package-metadata/ Per-component package metadata and build plans for CI (package images, OBS) cmd/obs-publish/ CLI entry point for uploading, building, and releasing one package on OBS cmd/otel-config-check/ Declarative-config validator shipped inside the Python package @@ -38,7 +38,7 @@ packaging/ components.go Per-component definitions (injector, java, nodejs, dotnet, python, meta) download.go Upstream artifact download helpers spec.go RPM spec generation for the COPR build (projection of components.go) - debspec.go debbuild spec generation for the OBS build, one spec per component + debspec.go Unified debbuild and rpmbuild spec generation for the OBS build, one spec per component debsources.go OBS source archives: the payload staged for every architecture stage.go Payload staging into a buildroot, with generated %files lists common/ Shared assets referenced by the builder @@ -203,9 +203,10 @@ copr-cli buildscm opentelemetry/opentelemetry-packaging \ To try a change before it is merged, point `--clone-url` and `--commit` at a fork and a branch, or submit the same command to a COPR project of your own with the same chroots. -### Building DEBs with debbuild on the Open Build Service +### Building DEBs and RPMs on the Open Build Service -DEBs have a second producer too, used by the [Open Build Service](https://build.opensuse.org/) (OBS), which builds, signs, and publishes the Debian and Ubuntu repositories. +DEBs and RPMs have a second producer too, used by the [Open Build Service](https://build.opensuse.org/) (OBS), which builds, signs, and publishes the repositories. +One spec per component serves both: OBS builds it with debbuild for the Debian and Ubuntu repositories, and with rpmbuild for the Fedora and EL ones. OBS builds have no network access, and the Debian releases do not ship the Go version `go.mod` asks for, so nothing is compiled or downloaded there. The payload is staged beforehand, by the same builder as every other path, and committed to OBS in the source archive. @@ -232,9 +233,11 @@ go run ./cmd/build-spec/deb -output build/deb-sources `-version` overrides every component's version, for testing. Each directory holds two files. -`.spec` is a [debbuild](https://github.com/debbuild/debbuild) spec rendered from `components.go`, with nothing to build. -`-.tar.gz` holds the payload staged for each DEB architecture under `/root`, or once under `all/root` for an architecture-independent component, with the `%files` list for it alongside. -The spec picks the tree debbuild's `%{_arch}` names and copies it into the buildroot. +`.spec` is a spec rendered from `components.go`, with nothing to build. +`-.tar.gz` holds the payload staged for each architecture, named by its DEB architecture, under `/root`, or once under `all/root` for an architecture-independent component. +Beside each tree are two file lists, `.deb.files` and `.rpm.files`: the RPM one carries `%attr` and the `%config(noreplace)` qualifiers rpmbuild needs, the DEB one does neither. +The spec picks the tree and the list for the architecture and the builder it runs under, and copies the tree into the buildroot. +The few differences between the two builders sit under `%if "%{_vendor}" == "debbuild"`; everything else, including the lifecycle scriptlets, is shared. The archive entries, and the date in the man pages, carry the time in [`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/specs/source-date-epoch/), so identical payloads give identical archives and an unchanged component is no change to commit. Without it the archive records the current time, and the command warns. The Python payload is the one pip writes, and pip records in every `*.dist-info/direct_url.json` the URL it installed the package from, a temporary directory that changes at every run. @@ -249,7 +252,7 @@ To check that a component's sources are reproducible, write them twice with the make check-reproducible-deb-sources-python ``` -Some properties of the result differ from the nfpm packages, and are worth knowing: +Some properties of the DEBs differ from the nfpm packages, and are worth knowing: - The DEB version is the upstream version written the way nfpm would (`1.0.0~rc.1` for `1.0.0-rc.1`), followed by a revision that OBS sets from its own commit and build counters (`-2.1`). A packaging-only change keeps the version and gets a higher revision, so it still upgrades. - The spec sets `AutoReq: no`, so the dependencies are exactly those in `components.go`, as with nfpm. @@ -258,7 +261,15 @@ Some properties of the result differ from the nfpm packages, and are worth knowi - The compression follows the build distribution's `dpkg` default: xz on Debian, zstd on Ubuntu. - The packages are not byte-reproducible: debbuild stamps the directories it creates, and the man page it recompresses, with the time of the build. The source archives are, which is what matters for OBS, where a changed archive is a rebuild. -### Building the DEB sources locally +The RPMs built from the same spec differ from the source RPM the COPR path produced in two ways: + +- Nothing is compiled or downloaded at build time. The spec has no `BuildRequires`, because the payload is staged beforehand. +- The Python package is not built for EL, whose interpreter does not match the bundled wheels. On OBS that package is disabled in the EL repository; locally, `RPM_REBUILD_SKIP=python` leaves it out. + +The spec sets the same globals the source RPM did: no debuginfo, no stripping of the prebuilt binaries, and no private libraries published as `Provides`. +`AutoReq` stays on for rpm, so the glibc symbol versions the binaries need remain install constraints. + +### Building the sources locally `make deb-rebuild-container` builds every generated spec with debbuild in a container, the way OBS does, and `make integration-test-deb-rebuild` runs the metadata tests over the result: @@ -273,6 +284,15 @@ Keep it pinned: the specs set `%global __mkdir_p` and `%global __gzip`, macros i That is also why the rebuild is worth running at all. Every other assertion about this path reads the text of the generated spec, and a spec that is wrong in a way debbuild agrees with passes all of them. +`make obs-rpm-rebuild-container` builds the same specs with rpmbuild, and `make integration-test-obs-rpm-rebuild` runs the RPM metadata tests over the result: + +```sh +make integration-test-obs-rpm-rebuild RPM_REBUILD_IMAGE=docker.io/almalinux/9-base RPM_REBUILD_SKIP=python +``` + +`RPM_REBUILD_IMAGE` defaults to Fedora 44. +The EL 9 image exercises the oldest rpm, 4.16, which has to parse the spec too. + To run debbuild by hand instead, create the `_topdir` skeleton first: ```sh diff --git a/Makefile b/Makefile index 9ddd7047..3bd10e49 100644 --- a/Makefile +++ b/Makefile @@ -339,6 +339,33 @@ deb-rebuild-container: integration-test-deb-rebuild: deb-rebuild-container PACKAGES_DIR=$(DEB_REBUILD_OUTPUT_DIR) go test -v -timeout 5m -run TestDeb ./packaging/tests/metadata/ +# Builds the same generated specs with rpmbuild in a container, the way OBS does for the RPM repositories, and runs the RPM metadata tests over the result. +# +# RPM_REBUILD_IMAGE selects the build distribution; almalinux:9 exercises the oldest rpm (4.16) the specs have to parse under. +# RPM_REBUILD_SKIP lists the components to leave out: python is not built for EL, whose interpreter does not match the bundled wheels. +RPM_REBUILD_IMAGE ?= registry.fedoraproject.org/fedora:44 +RPM_REBUILD_SKIP ?= +RPM_REBUILD_OUTPUT_DIR ?= $(CURDIR)/build/rpm-rebuild + +.PHONY: obs-rpm-rebuild-container +obs-rpm-rebuild-container: + @if [ -z "$$(ls $(DEB_SOURCES_DIR)/*/*.spec 2>/dev/null)" ]; then \ + echo "error: no spec found in $(DEB_SOURCES_DIR). Run \`make deb-sources\` first."; \ + exit 1; \ + fi + @rm -rf $(RPM_REBUILD_OUTPUT_DIR) + @mkdir -p $(RPM_REBUILD_OUTPUT_DIR) + $(CONTAINER_ENGINE) run --rm --platform linux/$(ARCH) \ + -v $(abspath $(DEB_SOURCES_DIR)):/sources:ro \ + -v $(RPM_REBUILD_OUTPUT_DIR):/out \ + -v $(CURDIR)/packaging/repo:/scripts:ro \ + $(RPM_REBUILD_IMAGE) \ + /scripts/rpm-obs-rebuild.sh /sources /out $(RPM_REBUILD_SKIP) + +.PHONY: integration-test-obs-rpm-rebuild +integration-test-obs-rpm-rebuild: obs-rpm-rebuild-container + PACKAGES_DIR=$(RPM_REBUILD_OUTPUT_DIR) go test -v -timeout 5m -run TestRpm $(if $(findstring python,$(RPM_REBUILD_SKIP)),-skip Python) ./packaging/tests/metadata/ + # ============================================================================ # Local Package Repositories for Testing # ============================================================================ diff --git a/packaging/builder/debsources.go b/packaging/builder/debsources.go index fb1ca074..65576772 100644 --- a/packaging/builder/debsources.go +++ b/packaging/builder/debsources.go @@ -47,7 +47,7 @@ func WriteDebSources(cfg Config, comp Component, configCheckBinary func(arch str archCfg.ConfigCheckBinary = configCheckBinary(arch) dir := filepath.Join(workDir, prefix, debPayloadDir(comp, arch)) - if err := StageDeb(archCfg, comp, filepath.Join(dir, "root"), dir); err != nil { + if err := StageOBS(archCfg, comp, filepath.Join(dir, "root"), dir); err != nil { return nil, err } } diff --git a/packaging/builder/debspec.go b/packaging/builder/debspec.go index 901b26e4..e6466b45 100644 --- a/packaging/builder/debspec.go +++ b/packaging/builder/debspec.go @@ -14,12 +14,24 @@ import ( ) var ( - //go:embed opentelemetry-deb.spec.tmpl + //go:embed opentelemetry.spec.tmpl debSpecTemplateSource string - debSpecTemplate = template.Must(template.New("opentelemetry-deb.spec.tmpl").Parse(debSpecTemplateSource)) + debSpecTemplate = template.Must(template.New("opentelemetry.spec.tmpl").Parse(debSpecTemplateSource)) ) +// rpmArch returns the RPM spelling of a payload architecture, which is named after its DEB architecture in the source archive. +func rpmArch(debArch string) string { + switch debArch { + case "amd64": + return "x86_64" + case "arm64": + return "aarch64" + default: + return debArch + } +} + // DebNoarchDir is the payload directory of an architecture-independent // component in the DEB source archive. It is the DEB architecture name such a // package carries. @@ -37,21 +49,23 @@ type debSpecData struct { Packager string Section string Noarch bool - // PayloadDir is the source archive directory that holds this build's - // payload: a literal for noarch packages, the arch macro otherwise. + // Noarch packages keep their one payload in a literal directory, and every other package in the one named after its architecture, which the spec resolves into the payload_arch macro. PayloadDir string - // PayloadArchs lists the architectures the source archive was staged for, - // space separated for the ifnarch guard. Empty for a noarch package, whose - // single payload serves every architecture. - PayloadArchs string - Component string - Provides []string - Requires []string - Recommends []string - Suggests []string - Conflicts []string - Replaces []string - Scriptlets []specScriptlet + // DebArchs and RPMArchs list the architectures the source archive was staged for, space separated for the ifnarch guard, spelled as debbuild and rpm spell them. + // Empty for a noarch package, whose single payload serves every architecture. + DebArchs string + RPMArchs string + Component string + // DebFileList and RPMFileList are the names of the file lists beside the payload. + DebFileList string + RPMFileList string + Provides []string + Requires []string + Recommends []string + Suggests []string + Conflicts []string + Replaces []string + Scriptlets []specScriptlet } // DebVersionRelease returns the Version and Release fields of a debbuild spec. @@ -109,11 +123,15 @@ func WriteDebSpec(cfg Config, comp Component, w io.Writer) error { return err } - payloadDir := "%{_arch}" - payloadArchs := strings.Join(debPayloadArchs(comp), " ") - if comp.Noarch { - payloadDir = DebNoarchDir - payloadArchs = "" + var debArchs, rpmArchs string + if !comp.Noarch { + archs := debPayloadArchs(comp) + debArchs = strings.Join(archs, " ") + rpmNames := make([]string, 0, len(archs)) + for _, arch := range archs { + rpmNames = append(rpmNames, rpmArch(arch)) + } + rpmArchs = strings.Join(rpmNames, " ") } scriptlets, err := componentScriptlets(cfg, comp) @@ -128,22 +146,25 @@ func WriteDebSpec(cfg Config, comp Component, w io.Writer) error { Summary: comp.Description, // debbuild has a Summary tag of its own, as rpm does, so the // description section holds the prose alone. - Description: comp.formatDescription("rpm"), - License: cfg.license(), - URL: cfg.homepage(), - Packager: cfg.maintainer(), - Section: cfg.section(), - Noarch: comp.Noarch, - PayloadDir: payloadDir, - PayloadArchs: payloadArchs, - Component: comp.Name, - Provides: comp.Relations.Provides, - Requires: comp.Relations.Depends, - Recommends: comp.Relations.Recommends, - Suggests: comp.Relations.Suggests, - Conflicts: comp.Relations.Conflicts, - Replaces: comp.Relations.Replaces, - Scriptlets: scriptlets, + Description: comp.formatDescription("rpm"), + License: cfg.license(), + URL: cfg.homepage(), + Packager: cfg.maintainer(), + Section: cfg.section(), + Noarch: comp.Noarch, + PayloadDir: DebNoarchDir, + DebArchs: debArchs, + RPMArchs: rpmArchs, + Component: comp.Name, + DebFileList: comp.Name + DEBFileListSuffix, + RPMFileList: comp.Name + RPMFileListSuffix, + Provides: comp.Relations.Provides, + Requires: comp.Relations.Depends, + Recommends: comp.Relations.Recommends, + Suggests: comp.Relations.Suggests, + Conflicts: comp.Relations.Conflicts, + Replaces: comp.Relations.Replaces, + Scriptlets: scriptlets, } return debSpecTemplate.Execute(w, data) diff --git a/packaging/builder/debspec_test.go b/packaging/builder/debspec_test.go index 918af248..82da0732 100644 --- a/packaging/builder/debspec_test.go +++ b/packaging/builder/debspec_test.go @@ -9,6 +9,7 @@ import ( "io" "os" "path/filepath" + "sort" "strings" "testing" @@ -87,22 +88,85 @@ func TestWriteDebSpecPreamble(t *testing.T) { assert.Contains(t, spec, "Version: 1.2.3\n") assert.Contains(t, spec, "Release: 1\n") assert.Contains(t, spec, "License: Apache-2.0\n") - assert.Contains(t, spec, "Packager: The OpenTelemetry Authors\n") - // debbuild writes Group out as the DEB Section field, and omits the field - // altogether when the tag is absent. - assert.Contains(t, spec, "Group: utils\n") assert.Contains(t, spec, "Source0: %{name}-%{version}.tar.gz\n") + + // debbuild writes Group out as the DEB Section field, and omits the field altogether when the tag is absent. + // Packager becomes the Maintainer. + // rpm gets neither, so both sit under the debbuild branch. + debbuild, rpm := vendorBranches(t, spec) + assert.Contains(t, debbuild, "Group: utils\n") + assert.NotContains(t, rpm, "Group:") + assert.Contains(t, spec, "Packager: The OpenTelemetry Authors\n") // The dependencies are the declared ones only, as in the nfpm packages. - assert.Contains(t, spec, "AutoReq: no\n") + // For rpm they are whatever it generates from the binaries, which is how the glibc symbol versions reach its Requires. + assert.Contains(t, debbuild, "AutoReq: no\n") + assert.NotContains(t, rpm, "AutoReq") assert.NotContains(t, spec, "BuildRequires:", "the payload is prebuilt, the build needs nothing") } // Under the build's umask of 002 debbuild would ship group-writable directories // and man pages; these are the two commands it creates them with. func TestWriteDebSpecPackagesUnderUmask022(t *testing.T) { - spec := renderDebSpec(t, "1.2.3", Injector) - assert.Contains(t, spec, "%global __mkdir_p umask 022 && /bin/mkdir -p\n") - assert.Contains(t, spec, "%global __gzip umask 022 && /bin/gzip\n") + debbuild, rpm := vendorBranches(t, renderDebSpec(t, "1.2.3", Injector)) + assert.Contains(t, debbuild, "%global __mkdir_p umask 022 && /bin/mkdir -p\n") + assert.Contains(t, debbuild, "%global __gzip umask 022 && /bin/gzip\n") + assert.NotContains(t, rpm, "__mkdir_p", "rpm builds with its own macros") +} + +// The prebuilt payload must reach rpm untouched, and its glibc symbol versions must remain install constraints; the same globals the source RPM sets. +func TestWriteDebSpecKeepsPrebuiltBinariesIntactUnderRpm(t *testing.T) { + debbuild, rpm := vendorBranches(t, renderDebSpec(t, "1.2.3", Injector)) + for _, want := range []string{ + "%global debug_package %{nil}\n", + "%global __strip /bin/true\n", + "%global _build_id_links none\n", + "%global source_date_epoch_from_changelog 0\n", + "%global __provides_exclude_from ^%{_prefix}/lib/opentelemetry/.*$\n", + "%global __requires_exclude ^%{_bindir}/(node|python3)$\n", + } { + assert.Contains(t, rpm, want) + assert.NotContains(t, debbuild, want) + } +} + +// vendorBranches splits the part of a spec that is conditional on the vendor into what debbuild sees and what rpm sees. +// It handles the top level conditionals only, which is all the template has. +func vendorBranches(t *testing.T, spec string) (debbuild, rpm string) { + t.Helper() + var d, r strings.Builder + // state: 0 outside, 1 debbuild branch, 2 rpm branch + state := 0 + nested := 0 + for line := range strings.SplitSeq(spec, "\n") { + trimmed := strings.TrimSpace(line) + switch { + case state == 0 && trimmed == `%if "%{_vendor}" == "debbuild"`: + state = 1 + continue + case state != 0 && strings.HasPrefix(trimmed, "%if"): + nested++ + case state != 0 && strings.HasPrefix(trimmed, "%ifarch"): + nested++ + case state != 0 && nested == 0 && trimmed == "%else": + state = 2 + continue + case state != 0 && trimmed == "%endif": + if nested > 0 { + nested-- + break + } + state = 0 + continue + } + switch state { + case 1: + d.WriteString(line + "\n") + case 2: + r.WriteString(line + "\n") + } + } + require.Equal(t, 0, state, "unbalanced vendor conditional") + return d.String(), r.String() } func TestWriteDebSpecMirrorsTheDependencyModel(t *testing.T) { @@ -125,8 +189,7 @@ func TestWriteDebSpecMirrorsTheDependencyModel(t *testing.T) { } } -// debbuild reads Replaces directly; the RPM spec's Obsoletes spelling would -// work too, but the DEB field is what the relationship is called here. +// The relationship is Replaces to debbuild and Obsoletes to rpm. func TestWriteDebSpecDisplacementRelations(t *testing.T) { comp := Component{ Name: "fixture", @@ -140,21 +203,34 @@ func TestWriteDebSpecDisplacementRelations(t *testing.T) { spec := renderDebSpec(t, "1.2.3", comp) assert.Contains(t, spec, "Conflicts: opentelemetry-java-autoinstrumentation\n") - assert.Contains(t, spec, "Replaces: opentelemetry-java-autoinstrumentation\n") - assert.NotContains(t, spec, "Obsoletes:") + debbuild, rpm := vendorBranches(t, spec) + assert.Contains(t, debbuild, "Replaces: opentelemetry-java-autoinstrumentation\n") + assert.NotContains(t, debbuild, "Obsoletes:") + assert.Contains(t, rpm, "Obsoletes: opentelemetry-java-autoinstrumentation\n") + assert.NotContains(t, rpm, "Replaces:") } func TestWriteDebSpecSelectsThePayloadByArchitecture(t *testing.T) { spec := renderDebSpec(t, "1.2.3", Injector) - assert.Contains(t, spec, "%{name}-%{version}/%{_arch}/root") - assert.Contains(t, spec, "%files -f %{_arch}/injector.files\n") + assert.Contains(t, spec, "%{name}-%{version}/%{payload_arch}/root") + assert.Contains(t, spec, "%files -f %{payload_arch}/%{filelist}\n") assert.NotContains(t, spec, "BuildArch:") + // The archive names payloads after the DEB architectures, so rpm maps its own. + debbuild, rpm := vendorBranches(t, spec) + assert.Contains(t, debbuild, "%global payload_arch %{_arch}\n") + assert.Contains(t, rpm, "%ifarch x86_64\n%global payload_arch amd64\n%endif\n") + assert.Contains(t, rpm, "%ifarch aarch64\n%global payload_arch arm64\n%endif\n") + + // Each format reads the file list written for it. + assert.Contains(t, debbuild, "%global filelist injector.deb.files\n") + assert.Contains(t, rpm, "%global filelist injector.rpm.files\n") + noarch := renderDebSpec(t, "1.2.3", Java) assert.Contains(t, noarch, "BuildArch: noarch\n") - assert.Contains(t, noarch, "%{name}-%{version}/all/root") - assert.Contains(t, noarch, "%files -f all/java.files\n") + assert.Contains(t, noarch, "%global payload_arch all\n") assert.NotContains(t, noarch, "%{_arch}") + assert.NotContains(t, noarch, "%ifarch") } // An architecture the archive carries no payload for would otherwise fail in @@ -162,12 +238,14 @@ func TestWriteDebSpecSelectsThePayloadByArchitecture(t *testing.T) { // on but the exit status. The guard reports it while the spec is read. func TestWriteDebSpecGuardsUnstagedArchitectures(t *testing.T) { spec := renderDebSpec(t, "1.2.3", Injector) - archs := strings.Join(Architectures, " ") - assert.Contains(t, spec, "%ifnarch "+archs+"\n") - assert.Contains(t, spec, "%{error:this package is built for "+archs+", not %{_arch}}\n") + debbuild, rpm := vendorBranches(t, spec) + assert.Contains(t, debbuild, "%global payload_archs "+strings.Join(Architectures, " ")+"\n") + assert.Contains(t, rpm, "%global payload_archs x86_64 aarch64\n") + assert.Contains(t, spec, "%ifnarch %{payload_archs}\n") + assert.Contains(t, spec, "%{error:this package is built for %{payload_archs}, not %{_arch}}\n") // A noarch payload serves every architecture, so there is nothing to guard. - assert.NotContains(t, renderDebSpec(t, "1.2.3", Java), "%ifnarch") + assert.NotContains(t, renderDebSpec(t, "1.2.3", Java), "%ifnarch %{payload_archs}") } func TestWriteDebSpecInlinesLifecycleScripts(t *testing.T) { @@ -198,7 +276,7 @@ func TestWriteDebSpecSectionsAppearOnce(t *testing.T) { } } -func TestStageDebFileListCarriesNoAttributes(t *testing.T) { +func TestStageOBSWritesAFileListPerFormat(t *testing.T) { src := writeSource(t, "libotelinject.so", "payload") conf := writeSource(t, "injector.conf", "conf\n") @@ -215,25 +293,47 @@ func TestStageDebFileListCarriesNoAttributes(t *testing.T) { }, func() {}, nil }, } - require.NoError(t, StageDeb(testConfig(t, "1.2.3"), comp, root, filelistDir)) + require.NoError(t, StageOBS(testConfig(t, "1.2.3"), comp, root, filelistDir)) - data, err := os.ReadFile(filepath.Join(filelistDir, "fixture.files")) + data, err := os.ReadFile(filepath.Join(filelistDir, "fixture"+DEBFileListSuffix)) require.NoError(t, err) - list := string(data) + deb := string(data) // debbuild would turn every attr into a chown and chmod in the postinst. - assert.NotContains(t, list, "%attr") - assert.Contains(t, list, injectorInstallDir+"/libotelinject.so\n") + assert.NotContains(t, deb, "%attr") + assert.Contains(t, deb, injectorInstallDir+"/libotelinject.so\n") // dpkg treats conffiles as noreplace anyway; debbuild knows no qualifier. - assert.Contains(t, list, "%config "+injectorConfigDir+"/injector.conf\n") - assert.Contains(t, list, "%dir "+injectorInstallDir+"\n") + assert.Contains(t, deb, "%config "+injectorConfigDir+"/injector.conf\n") + assert.Contains(t, deb, "%dir "+injectorInstallDir+"\n") + + // rpmbuild runs as an unprivileged user and needs the ownership spelled out. + data, err = os.ReadFile(filepath.Join(filelistDir, "fixture"+RPMFileListSuffix)) + require.NoError(t, err) + rpm := string(data) + assert.Contains(t, rpm, "%attr(0755,root,root) "+injectorInstallDir+"/libotelinject.so\n") + assert.Contains(t, rpm, "%config(noreplace) %attr(0644,root,root) "+injectorConfigDir+"/injector.conf\n") + assert.Contains(t, rpm, "%dir %attr(") + + // The same files, whichever format lists them. + assert.Equal(t, listedPaths(deb), listedPaths(rpm)) - // The mode the file list leaves out is in the staged tree. + // The mode the DEB file list leaves out is in the staged tree. info, err := os.Stat(filepath.Join(root, injectorInstallDir, "libotelinject.so")) require.NoError(t, err) assert.Equal(t, os.FileMode(0o755), info.Mode().Perm()) } +// listedPaths returns the paths a file list names, without its directives. +func listedPaths(list string) []string { + var paths []string + for line := range strings.SplitSeq(strings.TrimSpace(list), "\n") { + fields := strings.Fields(line) + paths = append(paths, fields[len(fields)-1]) + } + sort.Strings(paths) + return paths +} + // readArchive returns the entries of a gzipped tar by name. func readArchive(t *testing.T, path string) map[string]*tar.Header { t.Helper() @@ -294,7 +394,8 @@ func TestWriteDebSourcesStagesEveryArchitecture(t *testing.T) { assert.Equal(t, int64(0o755), bin.Mode&0o777) assert.Equal(t, 0, bin.Uid) assert.Equal(t, "root", bin.Uname) - assert.NotNil(t, entries[prefix+"fixture.files"], "file list for %s", arch) + assert.NotNil(t, entries[prefix+"fixture"+DEBFileListSuffix], "DEB file list for %s", arch) + assert.NotNil(t, entries[prefix+"fixture"+RPMFileListSuffix], "RPM file list for %s", arch) } spec, err := os.ReadFile(sources.Spec) @@ -333,3 +434,19 @@ func TestWriteDebSourcesIsReproducible(t *testing.T) { require.NoError(t, err) assert.Equal(t, a, b, "identical payloads must give identical archives") } + +// rpm expands macros in comments, and an unescaped section macro in one makes rpm 4.16 (EL 9) start that section there: "second install" is how it fails. +// Fedora's newer rpm tolerates it, so nothing but this test and an EL build catches a comment that names a section with its percent sign. +func TestWriteDebSpecCommentsNameNoMacros(t *testing.T) { + for _, comp := range AllComponents { + t.Run(comp.Name, func(t *testing.T) { + for line := range strings.SplitSeq(renderDebSpec(t, "1.2.3", comp), "\n") { + // A doubled percent sign is escaped, as in the lifecycle scripts. + if strings.HasPrefix(line, "#") { + assert.NotContains(t, strings.ReplaceAll(line, "%%", ""), "%", + "comment expands as a macro: %q", line) + } + } + }) + } +} diff --git a/packaging/builder/opentelemetry-deb.spec.tmpl b/packaging/builder/opentelemetry-deb.spec.tmpl deleted file mode 100644 index 50465568..00000000 --- a/packaging/builder/opentelemetry-deb.spec.tmpl +++ /dev/null @@ -1,103 +0,0 @@ -{{/* -Copyright The OpenTelemetry Authors -SPDX-License-Identifier: Apache-2.0 - -Template for the debbuild spec of one component, rendered by WriteDebSpec in -debspec.go. Text outside the {{...}} actions is emitted verbatim, so this file -reads as the spec it produces. - -debbuild expands macros in comments as rpm does, so the comments below name -spec sections and macros without a leading percent sign. -*/ -}} -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 -# -# Generated by "build-spec/deb" from packaging/builder. DO NOT EDIT. -# -# Built by debbuild on the Open Build Service, whose builds have no network -# access. The payload is therefore staged ahead of time, by the same builder -# that produces the nfpm packages, into the source archive: one tree per DEB -# architecture, next to the file list written for it. This spec builds nothing -# and only copies the tree for the architecture being built. -# -# There is no changelog section on purpose: the repository history is the -# changelog, and a generated spec has no stable date to put there. - -# The dependencies are declared below, as in the nfpm packages. Without this, -# debbuild would add every shared library the bundled agents link against. -AutoReq: no - -# debbuild creates the package's directories itself, and recompresses man pages -# after the install section, under the umask of the build, which is 002 on the -# Open Build Service: the package would ship group-writable directories. These -# two commands are what it runs for both, so they set the umask nfpm packages -# with instead. -%global __mkdir_p umask 022 && /bin/mkdir -p -%global __gzip umask 022 && /bin/gzip - -Name: {{ .Name }} -Version: {{ .Version }} -Release: {{ .Release }} -Summary: {{ .Summary }} -# debbuild writes the Group tag out as the DEB Section field, and omits the -# field entirely when the tag is absent. -Group: {{ .Section }} -License: {{ .License }} -URL: {{ .URL }} -Packager: {{ .Packager }} -Source0: %{name}-%{version}.tar.gz -{{ if .Noarch }}BuildArch: noarch -{{ end -}} -{{ range .Provides }}Provides: {{ . }} -{{ end -}} -{{ range .Requires }}Requires: {{ . }} -{{ end -}} -{{ range .Recommends }}Recommends: {{ . }} -{{ end -}} -{{ range .Suggests }}Suggests: {{ . }} -{{ end -}} -{{ range .Conflicts }}Conflicts: {{ . }} -{{ end -}} -{{ range .Replaces }}Replaces: {{ . }} -{{ end }} -{{ if .PayloadArchs -}} -# The source archive carries a payload for the architectures below, and the -# install and files sections below pick the one the arch macro names. A build -# for any other architecture fails in the install section, where debbuild -# discards the output of every section it runs, leaving only "Exec of -# /var/tmp/deb-tmp.install.NNN failed (%install): 512" to go on. Catching it -# here instead fails while the spec is read, where the message is printed. -%ifnarch {{ .PayloadArchs }} -%{error:this package is built for {{ .PayloadArchs }}, not %{_arch}} -%endif - -{{ end -}} -%description -{{ .Description }} - -%prep -# Creates the build directory without unpacking into it, and takes only the -# file list from the archive. The payload does not belong here: the install -# section extracts it straight from the archive, and the build directory is -# only where the files section reads its list from. Unpacking the archive whole -# would write out every architecture's payload to use one. -%setup -q -c -T -tar -xzf %{SOURCE0} --strip-components=1 \ - %{name}-%{version}/{{ .PayloadDir }}/{{ .Component }}.files - -%build -# Nothing to build: the payload in the source archive is already staged. - -%install -# Extracted from the archive again rather than copied from the setup tree, -# whose modes the build user's umask has already narrowed. The file list -# declares no modes, so the archive is where they come from. -mkdir -p %{buildroot} -tar -xzpf %{SOURCE0} -C %{buildroot} --strip-components=3 \ - %{name}-%{version}/{{ .PayloadDir }}/root - -{{ range .Scriptlets }}%{{ .Section }} -{{ .Body }} - -{{ end -}} -%files -f {{ .PayloadDir }}/{{ .Component }}.files diff --git a/packaging/builder/opentelemetry.spec.tmpl b/packaging/builder/opentelemetry.spec.tmpl new file mode 100644 index 00000000..386bf177 --- /dev/null +++ b/packaging/builder/opentelemetry.spec.tmpl @@ -0,0 +1,147 @@ +{{/* +Copyright The OpenTelemetry Authors +SPDX-License-Identifier: Apache-2.0 + +Template for the spec of one component, rendered by WriteDebSpec in debspec.go. +One spec serves both package formats: OBS builds it with debbuild for the DEB repositories and with rpmbuild for the RPM ones, and the vendor macro tells them apart. +Text outside the {{...}} actions is emitted verbatim, so this file reads as the spec it produces. + +Both builders expand macros in comments, so the comments below name spec sections and macros without a leading percent sign. +This matters most to rpm: a section macro in a comment above the preamble makes rpm 4.16 (EL9) start that section mid-comment and swallow the preamble. +*/ -}} +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 +# +# Generated by "build-spec/deb" from packaging/builder. DO NOT EDIT. +# +# Built on the Open Build Service, whose builds have no network access, by debbuild for the DEB repositories and by rpmbuild for the RPM ones. +# The payload is therefore staged ahead of time, by the same builder that produces the nfpm packages, into the source archive: one tree per architecture, next to a file list for each package format. +# This spec builds nothing and only copies the tree for the architecture being built. +# +# The few differences between the two builders sit under a test of the vendor macro: it is "debbuild" for debbuild, and anything else is rpm. +# +# There is no changelog section on purpose: the repository history is the changelog, and a generated spec has no stable date to put there. + +%if "%{_vendor}" == "debbuild" +# The dependencies are declared below, as in the nfpm packages. +# Without this, debbuild would add every shared library the bundled agents link against. +AutoReq: no + +# debbuild creates the package's directories itself, and recompresses man pages after the install section, under the umask of the build, which is 002 on the Open Build Service: the package would ship group-writable directories. +# These two commands are what it runs for both, so they set the umask nfpm packages with instead. +%global __mkdir_p umask 022 && /bin/mkdir -p +%global __gzip umask 022 && /bin/gzip + +%global filelist {{ .DebFileList }} +{{ if .Noarch -}} +%global payload_arch {{ .PayloadDir }} +{{ else -}} +%global payload_arch %{_arch} +{{ end -}} +{{ if .DebArchs }}%global payload_archs {{ .DebArchs }} +{{ end -}} +%else +# The bundled agents are prebuilt binaries: no stripping, no debuginfo, and no build-id links. +%global debug_package %{nil} +%global __strip /bin/true +%global _build_id_links none + +# This spec carries no changelog, so there is no date in it to derive SOURCE_DATE_EPOCH from. +# Saying so is better than fabricating an entry to satisfy the macro, which would otherwise warn on every build. +%global source_date_epoch_from_changelog 0 + +# Keep the bundled libraries private: rpm would otherwise publish the injector's SONAME as "Provides: libinjector.so()(64bit)", which could satisfy an unrelated package. +# Safe to filter, as the injector is preloaded by absolute path and never resolved by SONAME. +# Requires generation stays on: the glibc symbol versions are real install constraints. +# The pattern matches /usr/lib, where these packages install on every architecture, not /usr/lib64. +%global __provides_exclude_from ^%{_prefix}/lib/opentelemetry/.*$ + +# The agents instrument the runtime the application already has, so a dependency on one is wrong: on EL 9 it resolves to a nodejs older than the bundled agent supports. +# The DEB packages declare none either. +# Filtered by dependency rather than by path, which would drop the glibc symbol versions too. +%global __requires_exclude ^%{_bindir}/(node|python3)$ + +%global filelist {{ .RPMFileList }} +{{ if .Noarch -}} +%global payload_arch {{ .PayloadDir }} +{{ else -}} +# The source archive names each payload after its DEB architecture. +%ifarch x86_64 +%global payload_arch amd64 +%endif +%ifarch aarch64 +%global payload_arch arm64 +%endif +{{ if .RPMArchs }}%global payload_archs {{ .RPMArchs }} +{{ end -}} +{{ end -}} +%endif + +Name: {{ .Name }} +Version: {{ .Version }} +Release: {{ .Release }} +Summary: {{ .Summary }} +%if "%{_vendor}" == "debbuild" +# debbuild writes the Group tag out as the DEB Section field, and omits the field entirely when the tag is absent; the Packager tag becomes the Maintainer field. rpm needs neither. +Group: {{ .Section }} +Packager: {{ .Packager }} +%endif +License: {{ .License }} +URL: {{ .URL }} +Source0: %{name}-%{version}.tar.gz +{{ if .Noarch }}BuildArch: noarch +{{ end -}} +{{ range .Provides }}Provides: {{ . }} +{{ end -}} +{{ range .Requires }}Requires: {{ . }} +{{ end -}} +{{ range .Recommends }}Recommends: {{ . }} +{{ end -}} +{{ range .Suggests }}Suggests: {{ . }} +{{ end -}} +{{ range .Conflicts }}Conflicts: {{ . }} +{{ end -}} +{{ if .Replaces -}} +%if "%{_vendor}" == "debbuild" +{{ range .Replaces }}Replaces: {{ . }} +{{ end -}} +%else +{{ range .Replaces }}Obsoletes: {{ . }} +{{ end -}} +%endif +{{ end }} +{{ if .DebArchs -}} +# The source archive carries a payload for the architectures below, and the install and files sections below pick the one the architecture names. +# A build for any other architecture would otherwise fail in the install section, where debbuild discards the output of every section it runs, leaving only an "Exec of /var/tmp/deb-tmp.install.NNN failed" line and the status 512 to go on. +# Catching it here instead fails while the spec is read, where the message is printed. +%ifnarch %{payload_archs} +%{error:this package is built for %{payload_archs}, not %{_arch}} +%endif + +{{ end -}} +%description +{{ .Description }} + +%prep +# Creates the build directory without unpacking into it, and takes only the file list from the archive. +# The payload does not belong here: the install section extracts it straight from the archive, and the build directory is only where the files section reads its list from. +# Unpacking the archive whole would write out every architecture's payload to use one. +%setup -q -c -T +tar -xzf %{SOURCE0} --strip-components=1 \ + %{name}-%{version}/%{payload_arch}/%{filelist} + +%build +# Nothing to build: the payload in the source archive is already staged. + +%install +# Extracted from the archive again rather than copied from the setup tree, whose modes the build user's umask has already narrowed. +# The file list declares no modes for a DEB, so the archive is where they come from. +mkdir -p %{buildroot} +tar -xzpf %{SOURCE0} -C %{buildroot} --strip-components=3 \ + %{name}-%{version}/%{payload_arch}/root + +{{ range .Scriptlets }}%{{ .Section }} +{{ .Body }} + +{{ end -}} +%files -f %{payload_arch}/%{filelist} diff --git a/packaging/builder/stage.go b/packaging/builder/stage.go index 779ae0dc..098f47b5 100644 --- a/packaging/builder/stage.go +++ b/packaging/builder/stage.go @@ -56,16 +56,35 @@ var ( // Like Build, it derives both outputs from ContentsFunc, keeping the staged // payload and file list consistent. It calls the returned cleanup after staging. func Stage(cfg Config, comp Component, root, filelistDir string) error { - return stage(cfg, comp, root, filelistDir, rpmFileList) + return stageFormats(cfg, comp, root, filelistDir, []stagedList{ + {format: rpmFileList, name: comp.Name + ".files"}, + }) } -// StageDeb is Stage for the debbuild spec (see debspec.go). The file list -// declares no ownership or modes, which dpkg takes from the staged tree. -func StageDeb(cfg Config, comp Component, root, filelistDir string) error { - return stage(cfg, comp, root, filelistDir, debFileList) +// Names of the file lists StageOBS writes beside the payload, one per package format. +// The unified spec (see debspec.go) picks the one for the build it is running under. +const ( + RPMFileListSuffix = ".rpm.files" + DEBFileListSuffix = ".deb.files" +) + +// StageOBS stages a component's payload once under root and writes both of its file lists to filelistDir: .rpm.files for rpmbuild, with the ownership and %config qualifiers it needs, and .deb.files for debbuild, which declares no modes (dpkg takes them from the staged tree). +// +// The payload is the same for both formats, so one source archive serves the DEB and RPM repositories of an OBS package. +func StageOBS(cfg Config, comp Component, root, filelistDir string) error { + return stageFormats(cfg, comp, root, filelistDir, []stagedList{ + {format: rpmFileList, name: comp.Name + RPMFileListSuffix}, + {format: debFileList, name: comp.Name + DEBFileListSuffix}, + }) +} + +// stagedList is one file list to write while staging. +type stagedList struct { + format fileListFormat + name string } -func stage(cfg Config, comp Component, root, filelistDir string, format fileListFormat) error { +func stageFormats(cfg Config, comp Component, root, filelistDir string, lists []stagedList) error { contents, cleanup, err := comp.ContentsFunc(cfg) if cleanup != nil { defer cleanup() @@ -74,48 +93,57 @@ func stage(cfg Config, comp Component, root, filelistDir string, format fileList return fmt.Errorf("staging contents for %s: %w", comp.Name, err) } - // Match nfpm's expansion of trees, globs, and implicit parent directories. - prepared, err := files.PrepareForPackager(contents, stageUmask, format.packager, false, time.Now()) - if err != nil { - return fmt.Errorf("preparing contents for %s: %w", comp.Name, err) + if err := os.MkdirAll(filelistDir, 0o755); err != nil { + return err } - var lines []string - for _, content := range prepared { - line, err := stageContent(content, root, format) + for i, list := range lists { + // Match nfpm's expansion of trees, globs, and implicit parent directories. + prepared, err := files.PrepareForPackager(contents, stageUmask, list.format.packager, false, time.Now()) if err != nil { - return fmt.Errorf("staging %s for %s: %w", content.Destination, comp.Name, err) + return fmt.Errorf("preparing contents for %s: %w", comp.Name, err) } - if line != "" { - lines = append(lines, line) + + // The payload is the same whichever packager prepared it, so only the first list writes the tree. + write := i == 0 + + var lines []string + for _, content := range prepared { + line, err := stageContent(content, root, list.format, write) + if err != nil { + return fmt.Errorf("staging %s for %s: %w", content.Destination, comp.Name, err) + } + if line != "" { + lines = append(lines, line) + } } - } - sort.Strings(lines) + sort.Strings(lines) - if err := os.MkdirAll(filelistDir, 0o755); err != nil { - return err - } - listPath := filepath.Join(filelistDir, comp.Name+".files") - body := strings.Join(lines, "\n") + "\n" - if err := os.WriteFile(listPath, []byte(body), 0o644); err != nil { - return fmt.Errorf("writing file list %s: %w", listPath, err) - } + listPath := filepath.Join(filelistDir, list.name) + body := strings.Join(lines, "\n") + "\n" + if err := os.WriteFile(listPath, []byte(body), 0o644); err != nil { + return fmt.Errorf("writing file list %s: %w", listPath, err) + } - fmt.Printf("Staged %s: %d entries -> %s\n", comp.Name, len(lines), listPath) + fmt.Printf("Staged %s: %d entries -> %s\n", comp.Name, len(lines), listPath) + } return nil } // stageContent writes a single content entry under root and returns the %files // line describing it, or an empty string when the entry needs no line. -func stageContent(content *files.Content, root string, format fileListFormat) (string, error) { +// With write false it only returns the line, for a list over a tree already written. +func stageContent(content *files.Content, root string, format fileListFormat, write bool) (string, error) { dst := content.Destination target := filepath.Join(root, filepath.FromSlash(dst)) switch content.Type { case files.TypeImplicitDir: - if err := os.MkdirAll(target, content.Mode()); err != nil { - return "", err + if write { + if err := os.MkdirAll(target, content.Mode()); err != nil { + return "", err + } } // Distribution-owned parents must exist in the buildroot but remain // unclaimed; RPM permits unowned directories, though not unpackaged files. @@ -124,27 +152,35 @@ func stageContent(content *files.Content, root string, format fileListFormat) (s } return dirLine(content, format), nil case files.TypeDir: - if err := os.MkdirAll(target, content.Mode()); err != nil { - return "", err + if write { + if err := os.MkdirAll(target, content.Mode()); err != nil { + return "", err + } } return dirLine(content, format), nil case files.TypeSymlink: - if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil { - return "", err - } - if err := os.Symlink(content.Source, target); err != nil && !os.IsExist(err) { - return "", err + if write { + if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil { + return "", err + } + if err := os.Symlink(content.Source, target); err != nil && !os.IsExist(err) { + return "", err + } } // A symlink has no meaningful mode of its own in RPM. return filelistPath(dst), nil case files.TypeConfig, files.TypeConfigNoReplace, files.TypeConfigMissingOK: - if err := copyStagedFile(content, target); err != nil { - return "", err + if write { + if err := copyStagedFile(content, target); err != nil { + return "", err + } } return fileLine(content, format, configDirective(content.Type, format)), nil case files.TypeFile, "": - if err := copyStagedFile(content, target); err != nil { - return "", err + if write { + if err := copyStagedFile(content, target); err != nil { + return "", err + } } return fileLine(content, format, ""), nil default: diff --git a/packaging/repo/debbuild-rebuild.sh b/packaging/repo/debbuild-rebuild.sh index f0ec07dc..f3bc3dfb 100755 --- a/packaging/repo/debbuild-rebuild.sh +++ b/packaging/repo/debbuild-rebuild.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 diff --git a/packaging/repo/rpm-obs-rebuild.sh b/packaging/repo/rpm-obs-rebuild.sh new file mode 100755 index 00000000..768a3915 --- /dev/null +++ b/packaging/repo/rpm-obs-rebuild.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Build the generated OBS specs with rpmbuild the way the Open Build Service does. +# This script is meant to run inside a Fedora or EL container. +# +# Usage: rpm-obs-rebuild.sh [skipped_component ...] +# +# Expected structure: +# //.spec +# //-.tar.gz +# +# Every package found is built, and the .rpm files are copied to . +# A package named as a skipped component is left out. +# The Python package is not built for EL, whose interpreter does not match the bundled wheels. + +set -euo pipefail + +sources_dir="${1:?usage: rpm-obs-rebuild.sh [skipped_component ...]}" +output_dir="${2:?usage: rpm-obs-rebuild.sh [skipped_component ...]}" +shift 2 +skipped=("$@") + +echo "Installing the build dependencies" +# The payload is prebuilt, so rpmbuild is all a build needs. +dnf install -q -y --setopt=install_weak_deps=False rpm-build tar gzip >/dev/null + +mkdir -p "$output_dir" + +# The Open Build Service builds under umask 002, and the container defaults to 022. +# Without this the build is not the one being reproduced. +umask 002 + +built=0 +for spec in "$sources_dir"/*/*.spec; do + [ -e "$spec" ] || continue + package="$(basename "$(dirname "$spec")")" + + skip=false + for component in "${skipped[@]}"; do + if [ "$package" = "opentelemetry-${component}-autoinstrumentation" ]; then + skip=true + fi + done + if [ "$skip" = true ]; then + echo "Skipping $package" + continue + fi + + work="/tmp/rpmbuild/$package" + + echo "" + echo "=== Building $package ===" + rm -rf "$work" + mkdir -p "$work" + cp -r "$(dirname "$spec")"/. "$work/" + + # No --define of anything the spec reads. + # The point is to build it as OBS does, from the spec alone, and catch anything that only works because the generator happened to be the one driving it. + rpmbuild --define "_sourcedir $work" --define "_topdir $work/top" \ + -bb "$work/$(basename "$spec")" + + find "$work/top/RPMS" -name '*.rpm' -exec cp -v {} "$output_dir/" \; + built=$((built + 1)) +done + +if [ "$built" -eq 0 ]; then + echo "error: no spec found under $sources_dir" >&2 + exit 1 +fi + +echo "" +echo "Built $built package(s) into $output_dir:" +ls -1 "$output_dir" From 4aa0491b8b4d0bfa34d003c196cf14a91d89f4ed Mon Sep 17 00:00:00 2001 From: x1unix <9203548+x1unix@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:55:47 -0500 Subject: [PATCH 2/6] fix: Rename OBS source generation to be format-neutral The unified spec is built by debbuild and rpmbuild, so names that said "deb" for the shared parts were misleading. - cmd/build-spec/deb -> cmd/build-spec/obs - make deb-sources[-] -> make obs-sources[-], DEB_SOURCES_DIR -> OBS_SOURCES_DIR, build/deb-sources -> build/obs-sources - packaging/builder: debspec.go, debsources.go and their test -> obsspec.go, obssources.go, obsspec_test.go; WriteDebSpec, WriteDebSources, DebVersionRelease and related identifiers -> OBS* DEB-specific names stay: deb-rebuild-container, debbuild-rebuild.sh, DEBFileListSuffix, TestDeb*. Also fix the rpm-source-rebuild matrix: its include entries had no arch, so GitHub would have merged them into the arch axis and run only the AlmaLinux image. Use a plain image x arch matrix and derive the Python skip from the image. Signed-off-by: x1unix <9203548+x1unix@users.noreply.github.com> --- .github/workflows/build.yml | 18 ++--- .github/workflows/obs.yml | 4 +- AGENTS.md | 8 +- CONTRIBUTING.md | 16 ++-- Makefile | 54 ++++++------- cmd/build-spec/{deb => obs}/main.go | 15 ++-- cmd/obs-publish/main.go | 2 +- cmd/package-metadata/obs.go | 2 +- cmd/package-metadata/obs_test.go | 4 +- docs/design/package-publishing.md | 2 +- .../builder/{debsources.go => obssources.go} | 32 ++++---- packaging/builder/{debspec.go => obsspec.go} | 42 +++++----- .../{debspec_test.go => obsspec_test.go} | 80 +++++++++---------- packaging/builder/opentelemetry.spec.tmpl | 4 +- packaging/builder/stage.go | 2 +- 15 files changed, 139 insertions(+), 146 deletions(-) rename cmd/build-spec/{deb => obs}/main.go (83%) rename packaging/builder/{debsources.go => obssources.go} (86%) rename packaging/builder/{debspec.go => obsspec.go} (79%) rename packaging/builder/{debspec_test.go => obsspec_test.go} (86%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d24832c..25b9d2bc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -136,7 +136,7 @@ jobs: # an unchanged archive. The value is arbitrary here: debbuild does not # care, and the reproducible-deb-sources job checks the reproducibility. SOURCE_DATE_EPOCH: "1700000000" - run: make deb-sources VERSION=0.0.0-dev + run: make obs-sources VERSION=0.0.0-dev - name: Build the specs with debbuild and check the metadata run: make integration-test-deb-rebuild ARCH=${{ matrix.arch }} DEB_REBUILD_IMAGE=${{ matrix.image }} @@ -161,20 +161,15 @@ jobs: # Raises the GitHub API rate limit for the release-asset digest # lookups the payload staging makes, as build-packages does. GITHUB_TOKEN: ${{ github.token }} - run: make check-reproducible-deb-sources-python + run: make check-reproducible-obs-sources-python # The same generated specs, built with rpmbuild the way OBS builds the Fedora and EL repositories, then checked by the RPM metadata tests. rpm-source-rebuild: strategy: fail-fast: false matrix: - include: - - image: registry.fedoraproject.org/fedora:44 - skip: "" - # The oldest rpm the specs have to parse under. - # The Python package is not built for EL, whose interpreter does not match the bundled wheels. - - image: docker.io/almalinux/9-base - skip: python + # Fedora, and the oldest rpm the specs have to parse under. + image: [ "registry.fedoraproject.org/fedora:44", "docker.io/almalinux/9-base" ] arch: [ "amd64", "arm64" ] runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }} steps: @@ -188,10 +183,11 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} SOURCE_DATE_EPOCH: "1700000000" - run: make deb-sources VERSION=0.0.0-dev + run: make obs-sources VERSION=0.0.0-dev + # The Python package is not built for EL, whose interpreter does not match the bundled wheels. - name: Build the specs with rpmbuild and check the metadata - run: make integration-test-obs-rpm-rebuild ARCH=${{ matrix.arch }} RPM_REBUILD_IMAGE=${{ matrix.image }} RPM_REBUILD_SKIP=${{ matrix.skip }} + run: make integration-test-obs-rpm-rebuild ARCH=${{ matrix.arch }} RPM_REBUILD_IMAGE=${{ matrix.image }} RPM_REBUILD_SKIP=${{ contains(matrix.image, 'almalinux') && 'python' || '' }} integration-tests: needs: build-packages diff --git a/.github/workflows/obs.yml b/.github/workflows/obs.yml index 195876bb..3443c98c 100644 --- a/.github/workflows/obs.yml +++ b/.github/workflows/obs.yml @@ -157,7 +157,7 @@ jobs: SOURCE_DATE_EPOCH: ${{ matrix.package.source_date_epoch }} run: | make otel-config-check-all - go run ./cmd/build-spec/deb -component "$COMPONENT" -output build/deb-sources + go run ./cmd/build-spec/obs -component "$COMPONENT" -output build/obs-sources - name: Upload, build, and release env: @@ -183,5 +183,5 @@ jobs: fi fi go run ./cmd/obs-publish -project "$obs_project" -package "$PACKAGE" \ - -dir "build/deb-sources/$PACKAGE" -timeout 200m \ + -dir "build/obs-sources/$PACKAGE" -timeout 200m \ -message "$PACKAGE $VERSION from $GITHUB_REPOSITORY@$SHA" "${args[@]}" diff --git a/AGENTS.md b/AGENTS.md index 62a94909..578bf1ce 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,9 +19,9 @@ make srpm-container # Same, running rpmbuild in a container instead make srpm-sources # Generated spec + vendored source tarball only make rpm-rebuild-container # Rebuild the SRPM into binary RPMs the way COPR does # REBUILD_IMAGE=almalinux:9 to exercise the EL rpm -make deb-sources # Unified spec (debbuild and rpmbuild) + staged source archives for OBS (build/deb-sources//), each at its upstream version -make deb-sources- # Same, for one component -make check-reproducible-deb-sources- # Write one component's DEB sources twice and fail unless byte-identical +make obs-sources # Unified spec (debbuild and rpmbuild) + staged source archives for OBS (build/obs-sources//), each at its upstream version +make obs-sources- # Same, for one component +make check-reproducible-obs-sources- # Write one component's OBS sources twice and fail unless byte-identical make deb-rebuild-container # Build those specs with debbuild the way OBS does # DEB_REBUILD_IMAGE=ubuntu:24.04 to exercise the Ubuntu dpkg @@ -48,7 +48,7 @@ make clean # Remove build/ - `.copr/Makefile` — COPR "make srpm" entry point; installs the tooling and delegates to `make srpm` - `cmd/build-packages/` — CLI entry point; calls `packaging/builder/` - `cmd/build-spec/rpm/` — source RPM spec generation and rpmbuild payload staging -- `cmd/build-spec/deb/` — unified spec and pre-staged source archive per component, built by debbuild and rpmbuild on OBS +- `cmd/build-spec/obs/` — unified spec and pre-staged source archive per component, built by debbuild and rpmbuild on OBS - `cmd/package-metadata/` — CI build plans: package images (`-target images`) and OBS uploads (`-target obs`) - `cmd/obs-publish/` + `packaging/obs/` — OBS API client that commits one package's sources, waits for every build of that revision, and releases it (used by `.github/workflows/obs.yml`) - `packaging/changes/` — maps changed paths to the components they affect, shared by the image and OBS workflows diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 49e38fdd..69d842e3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,7 +28,7 @@ Every `make` invocation in this document is then `gmake` instead. .copr/Makefile COPR "make srpm" entry point (installs the tooling, then calls make srpm) cmd/build-packages/ CLI entry point for building .deb and .rpm packages cmd/build-spec/rpm/ CLI entry point for generating and staging the source RPM spec -cmd/build-spec/deb/ CLI entry point for writing the specs and source archives built on OBS +cmd/build-spec/obs/ CLI entry point for writing the specs and source archives built on OBS cmd/package-metadata/ Per-component package metadata and build plans for CI (package images, OBS) cmd/obs-publish/ CLI entry point for uploading, building, and releasing one package on OBS cmd/otel-config-check/ Declarative-config validator shipped inside the Python package @@ -38,8 +38,8 @@ packaging/ components.go Per-component definitions (injector, java, nodejs, dotnet, python, meta) download.go Upstream artifact download helpers spec.go RPM spec generation for the COPR build (projection of components.go) - debspec.go Unified debbuild and rpmbuild spec generation for the OBS build, one spec per component - debsources.go OBS source archives: the payload staged for every architecture + obsspec.go Unified debbuild and rpmbuild spec generation for the OBS build, one spec per component + obssources.go OBS source archives: the payload staged for every architecture stage.go Payload staging into a buildroot, with generated %files lists common/ Shared assets referenced by the builder /otel-config.yaml Language-specific declarative configuration file, shipped by that language package (valid as shipped) @@ -215,19 +215,19 @@ Each is versioned by the upstream agent it ships, the version in its pin (see "U Write the sources of every component: ```sh -make deb-sources +make obs-sources ``` Or of a single one: ```sh -make deb-sources-injector +make obs-sources-injector ``` -Both write `build/deb-sources//`, the content of the OBS package of the same name, by running: +Both write `build/obs-sources//`, the content of the OBS package of the same name, by running: ```sh -go run ./cmd/build-spec/deb -output build/deb-sources +go run ./cmd/build-spec/obs -output build/obs-sources ``` `-version` overrides every component's version, for testing. @@ -249,7 +249,7 @@ Renovate bumps that pin on its own, in a PR of its own: the next upload then reb To check that a component's sources are reproducible, write them twice with the same `SOURCE_DATE_EPOCH` and compare the two, which CI does for Python: ```sh -make check-reproducible-deb-sources-python +make check-reproducible-obs-sources-python ``` Some properties of the DEBs differ from the nfpm packages, and are worth knowing: diff --git a/Makefile b/Makefile index 3bd10e49..50a35d67 100644 --- a/Makefile +++ b/Makefile @@ -247,14 +247,12 @@ rpm-rebuild-container: @ls -1 $(REBUILD_OUTPUT_DIR)/*.rpm # ============================================================================ -# DEB sources for the Open Build Service (debbuild path) +# Sources for the Open Build Service (DEB and RPM) # ============================================================================ -# The Open Build Service builds the DEB packages with debbuild, one OBS package -# per component, and its builds have no network access. So the payload is -# staged here, for every architecture, into each component's source archive, -# and the generated spec only copies it into place. -DEB_SOURCES_DIR ?= build/deb-sources +# The Open Build Service builds the DEB packages with debbuild and the RPM ones with rpmbuild, one OBS package per component, and its builds have no network access. +# So the payload is staged here, for every architecture, into each component's source archive, and the generated spec only copies it into place. +OBS_SOURCES_DIR ?= build/obs-sources # Cross-compiles otel-config-check for every supported architecture. Source # packages carry the payload of all of them, and the Python payload bundles the @@ -263,42 +261,42 @@ DEB_SOURCES_DIR ?= build/deb-sources # architecture to builder.Architectures is the only edit it takes. .PHONY: otel-config-check-all otel-config-check-all: - @set -e; for arch in $$(go run ./cmd/build-spec/deb -print-architectures); do \ + @set -e; for arch in $$(go run ./cmd/build-spec/obs -print-architectures); do \ $(MAKE) --no-print-directory otel-config-check ARCH=$$arch; \ done -# Writes $(DEB_SOURCES_DIR)// with the debbuild spec and source archive -# of every component; deb-sources- writes one. Each package takes the +# Writes $(OBS_SOURCES_DIR)// with the spec and source archive +# of every component; obs-sources- writes one. Each package takes the # version of the upstream agent it ships, not $(VERSION): on OBS every package # is versioned and released on its own. -.PHONY: deb-sources -deb-sources: otel-config-check-all - go run ./cmd/build-spec/deb -output $(DEB_SOURCES_DIR) +.PHONY: obs-sources +obs-sources: otel-config-check-all + go run ./cmd/build-spec/obs -output $(OBS_SOURCES_DIR) -.PHONY: deb-sources-% -deb-sources-%: otel-config-check-all - go run ./cmd/build-spec/deb -component $* -output $(DEB_SOURCES_DIR) +.PHONY: obs-sources-% +obs-sources-%: otel-config-check-all + go run ./cmd/build-spec/obs -component $* -output $(OBS_SOURCES_DIR) -# Writes the DEB sources of one component twice, with the same +# Writes the OBS sources of one component twice, with the same # SOURCE_DATE_EPOCH, and fails unless the two outputs are byte-identical. OBS # rebuilds and releases a package whenever its committed archive changes, so an # archive that differs between two generations of an unchanged payload means a # new release of identical content on every run that selects the component. -REPRODUCIBLE_SOURCES_DIR ?= build/deb-sources-reproducible +REPRODUCIBLE_SOURCES_DIR ?= build/obs-sources-reproducible REPRODUCIBLE_SOURCE_DATE_EPOCH ?= 1700000000 -.PHONY: check-reproducible-deb-sources-% -check-reproducible-deb-sources-%: otel-config-check-all +.PHONY: check-reproducible-obs-sources-% +check-reproducible-obs-sources-%: otel-config-check-all @rm -rf $(REPRODUCIBLE_SOURCES_DIR)/$* @set -e; for run in first second; do \ SOURCE_DATE_EPOCH=$(REPRODUCIBLE_SOURCE_DATE_EPOCH) \ - go run ./cmd/build-spec/deb -component $* -output $(REPRODUCIBLE_SOURCES_DIR)/$*/$$run; \ + go run ./cmd/build-spec/obs -component $* -output $(REPRODUCIBLE_SOURCES_DIR)/$*/$$run; \ done @if ! diff -r $(REPRODUCIBLE_SOURCES_DIR)/$*/first $(REPRODUCIBLE_SOURCES_DIR)/$*/second; then \ - echo "error: two generations of the $* DEB sources differ"; \ + echo "error: two generations of the $* OBS sources differ"; \ exit 1; \ fi - @echo "The $* DEB sources are reproducible." + @echo "The $* OBS sources are reproducible." # Builds the generated specs with debbuild in a container, the way OBS does. # @@ -320,14 +318,14 @@ DEBBUILD_VERSION ?= 24.12.0 .PHONY: deb-rebuild-container deb-rebuild-container: - @if [ -z "$$(ls $(DEB_SOURCES_DIR)/*/*.spec 2>/dev/null)" ]; then \ - echo "error: no spec found in $(DEB_SOURCES_DIR). Run \`make deb-sources\` first."; \ + @if [ -z "$$(ls $(OBS_SOURCES_DIR)/*/*.spec 2>/dev/null)" ]; then \ + echo "error: no spec found in $(OBS_SOURCES_DIR). Run \`make obs-sources\` first."; \ exit 1; \ fi @rm -rf $(DEB_REBUILD_OUTPUT_DIR) @mkdir -p $(DEB_REBUILD_OUTPUT_DIR) $(CONTAINER_ENGINE) run --rm --platform linux/$(ARCH) \ - -v $(abspath $(DEB_SOURCES_DIR)):/sources:ro \ + -v $(abspath $(OBS_SOURCES_DIR)):/sources:ro \ -v $(DEB_REBUILD_OUTPUT_DIR):/out \ -v $(CURDIR)/packaging/repo:/scripts:ro \ $(DEB_REBUILD_IMAGE) \ @@ -349,14 +347,14 @@ RPM_REBUILD_OUTPUT_DIR ?= $(CURDIR)/build/rpm-rebuild .PHONY: obs-rpm-rebuild-container obs-rpm-rebuild-container: - @if [ -z "$$(ls $(DEB_SOURCES_DIR)/*/*.spec 2>/dev/null)" ]; then \ - echo "error: no spec found in $(DEB_SOURCES_DIR). Run \`make deb-sources\` first."; \ + @if [ -z "$$(ls $(OBS_SOURCES_DIR)/*/*.spec 2>/dev/null)" ]; then \ + echo "error: no spec found in $(OBS_SOURCES_DIR). Run \`make obs-sources\` first."; \ exit 1; \ fi @rm -rf $(RPM_REBUILD_OUTPUT_DIR) @mkdir -p $(RPM_REBUILD_OUTPUT_DIR) $(CONTAINER_ENGINE) run --rm --platform linux/$(ARCH) \ - -v $(abspath $(DEB_SOURCES_DIR)):/sources:ro \ + -v $(abspath $(OBS_SOURCES_DIR)):/sources:ro \ -v $(RPM_REBUILD_OUTPUT_DIR):/out \ -v $(CURDIR)/packaging/repo:/scripts:ro \ $(RPM_REBUILD_IMAGE) \ diff --git a/cmd/build-spec/deb/main.go b/cmd/build-spec/obs/main.go similarity index 83% rename from cmd/build-spec/deb/main.go rename to cmd/build-spec/obs/main.go index 756dc65b..912fdc76 100644 --- a/cmd/build-spec/deb/main.go +++ b/cmd/build-spec/obs/main.go @@ -1,9 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -// Command build-spec/deb writes the sources of the DEB packages built by debbuild -// on the Open Build Service: for each component, a spec and a source archive -// holding the payload already staged for every architecture. +// Command build-spec/obs writes the sources of the DEB and RPM packages built on the Open Build Service. +// For each component it writes one spec, built by debbuild for the DEB repositories and by rpmbuild for the RPM ones, and a source archive holding the payload already staged for every architecture. // // Each component lands in its own directory, named after its package, which is // the content of the OBS package of the same name. @@ -13,9 +12,9 @@ // // Usage: // -// go run ./cmd/build-spec/deb -output build/deb-sources -// go run ./cmd/build-spec/deb -component injector -output build/deb-sources -// go run ./cmd/build-spec/deb -version 1.0.0 -output build/deb-sources +// go run ./cmd/build-spec/obs -output build/obs-sources +// go run ./cmd/build-spec/obs -component injector -output build/obs-sources +// go run ./cmd/build-spec/obs -version 1.0.0 -output build/obs-sources package main import ( @@ -36,7 +35,7 @@ func main() { "Print the architectures the source archives are staged for, one per line, and exit") version := flag.String("version", "", "Package version for every component (defaults to each component's upstream version pin)") release := flag.String("release", "", "Packaging revision (defaults to 1)") - outputDir := flag.String("output", "build/deb-sources", "Output directory; each component gets a subdirectory named after its package") + outputDir := flag.String("output", "build/obs-sources", "Output directory; each component gets a subdirectory named after its package") component := flag.String("component", "all", "Component to write: injector, java, nodejs, dotnet, python, meta, or all") packagingDir := flag.String("packaging-dir", "", "Path to packaging/ directory (auto-detected if empty)") configCheckDir := flag.String("config-check-dir", filepath.Join("build", "bin"), @@ -106,7 +105,7 @@ func main() { if err := os.RemoveAll(dir); err != nil { log.Fatalf("error: %v", err) } - sources, err := builder.WriteDebSources(cfg, comp, configCheckBinary, dir) + sources, err := builder.WriteOBSSources(cfg, comp, configCheckBinary, dir) if err != nil { log.Fatalf("error: %v", err) } diff --git a/cmd/obs-publish/main.go b/cmd/obs-publish/main.go index 67d4c2f6..4fbd538b 100644 --- a/cmd/obs-publish/main.go +++ b/cmd/obs-publish/main.go @@ -11,7 +11,7 @@ // Usage: // // go run ./cmd/obs-publish -project home:opentelemetry:stable:build \ -// -package opentelemetry-injector -dir build/deb-sources/opentelemetry-injector \ +// -package opentelemetry-injector -dir build/obs-sources/opentelemetry-injector \ // -message "opentelemetry-injector 0.11.0" -release package main diff --git a/cmd/package-metadata/obs.go b/cmd/package-metadata/obs.go index f65bf688..67b6877b 100644 --- a/cmd/package-metadata/obs.go +++ b/cmd/package-metadata/obs.go @@ -19,7 +19,7 @@ import ( // The planner, the publisher and the workflow are deliberately not among them: // they decide what is uploaded, not what it contains, so a change to them // republishes nothing. The first upload after they change is a manual dispatch. -var obsInputs = []string{"cmd/build-spec/deb"} +var obsInputs = []string{"cmd/build-spec/obs"} func obsShared() []string { return append(append([]string(nil), changes.PackageInputs...), obsInputs...) diff --git a/cmd/package-metadata/obs_test.go b/cmd/package-metadata/obs_test.go index 13cf3362..441feaf7 100644 --- a/cmd/package-metadata/obs_test.go +++ b/cmd/package-metadata/obs_test.go @@ -122,8 +122,8 @@ func TestOBSPlanSelectsChangesSinceBase(t *testing.T) { {"python requirements", "packaging/common/python/requirements.txt", []string{"python"}}, {"metapackage", "packaging/common/meta/release.txt", []string{"meta"}}, {"component config", "packaging/common/injector/otel-injector.conf", []string{"injector"}}, - {"builder", "packaging/builder/debspec.go", []string{"injector", "java", "nodejs", "dotnet", "python", "meta"}}, - {"DEB source generator", "cmd/build-spec/deb/main.go", []string{"injector", "java", "nodejs", "dotnet", "python", "meta"}}, + {"builder", "packaging/builder/obsspec.go", []string{"injector", "java", "nodejs", "dotnet", "python", "meta"}}, + {"DEB source generator", "cmd/build-spec/obs/main.go", []string{"injector", "java", "nodejs", "dotnet", "python", "meta"}}, // The workflow and the tools around it decide what is uploaded, not // what it contains. {"workflow", ".github/workflows/obs.yml", []string{}}, diff --git a/docs/design/package-publishing.md b/docs/design/package-publishing.md index dfb97af3..aa070e74 100644 --- a/docs/design/package-publishing.md +++ b/docs/design/package-publishing.md @@ -193,7 +193,7 @@ Nothing is compiled on OBS: its build roots have no network access. Debian 12 also cannot supply the Go version this repository needs, so a build cannot compile the tools either. Instead, CI prepares everything a build needs, as Kubernetes does (see [Prior art](#prior-art)). -For each package, `make deb-sources` (or `make deb-sources-`) writes the 2 files that make up its OBS sources. +For each package, `make obs-sources` (or `make obs-sources-`) writes the 2 files that make up its OBS sources. - `-.tar.gz` holds the prepared package contents for every architecture, a directory per architecture, plus the file lists. It is prepared with the same code as the nfpm packages, so the contents cannot drift between the two. diff --git a/packaging/builder/debsources.go b/packaging/builder/obssources.go similarity index 86% rename from packaging/builder/debsources.go rename to packaging/builder/obssources.go index 65576772..5861e688 100644 --- a/packaging/builder/debsources.go +++ b/packaging/builder/obssources.go @@ -14,13 +14,13 @@ import ( "time" ) -// DebSources are the files of one component's OBS package. -type DebSources struct { +// OBSSources are the files of one component's OBS package. +type OBSSources struct { Spec string // Path to the generated spec Archive string // Path to the source archive it names as Source0 } -// WriteDebSources writes a component's debbuild spec and source archive into +// WriteOBSSources writes a component's spec and source archive into // outputDir, ready to be committed to an OBS package. // // The archive holds one staged payload per architecture in Architectures, each @@ -28,25 +28,25 @@ type DebSources struct { // under /all for an architecture-independent component. cfg.Arch is // ignored. configCheckBinary returns the otel-config-check binary built for an // architecture, which the Python payload bundles. -func WriteDebSources(cfg Config, comp Component, configCheckBinary func(arch string) string, outputDir string) (*DebSources, error) { - version, _, err := DebVersionRelease(cfg) +func WriteOBSSources(cfg Config, comp Component, configCheckBinary func(arch string) string, outputDir string) (*OBSSources, error) { + version, _, err := OBSVersionRelease(cfg) if err != nil { return nil, err } - workDir, err := os.MkdirTemp("", "otel-deb-sources-*") + workDir, err := os.MkdirTemp("", "otel-obs-sources-*") if err != nil { return nil, err } defer os.RemoveAll(workDir) - prefix := DebSourcePrefix(comp, version) - for _, arch := range debPayloadArchs(comp) { + prefix := OBSSourcePrefix(comp, version) + for _, arch := range obsPayloadArchs(comp) { archCfg := cfg archCfg.Arch = arch archCfg.ConfigCheckBinary = configCheckBinary(arch) - dir := filepath.Join(workDir, prefix, debPayloadDir(comp, arch)) + dir := filepath.Join(workDir, prefix, obsPayloadDir(comp, arch)) if err := StageOBS(archCfg, comp, filepath.Join(dir, "root"), dir); err != nil { return nil, err } @@ -56,12 +56,12 @@ func WriteDebSources(cfg Config, comp Component, configCheckBinary func(arch str return nil, err } - sources := &DebSources{ + sources := &OBSSources{ Spec: filepath.Join(outputDir, comp.PackageName+".spec"), - Archive: filepath.Join(outputDir, DebSourceArchiveName(comp, version)), + Archive: filepath.Join(outputDir, OBSSourceArchiveName(comp, version)), } if err := writeFileWith(sources.Spec, func(w io.Writer) error { - return WriteDebSpec(cfg, comp, w) + return WriteOBSSpec(cfg, comp, w) }); err != nil { return nil, fmt.Errorf("writing spec for %s: %w", comp.Name, err) } @@ -73,20 +73,20 @@ func WriteDebSources(cfg Config, comp Component, configCheckBinary func(arch str return sources, nil } -// debPayloadArchs returns the architectures a component is staged for. They +// obsPayloadArchs returns the architectures a component is staged for. They // are DEB architecture names, which is what debbuild expands %{_arch} to. An // architecture-independent payload is the same for every one, so it is staged // once. -func debPayloadArchs(comp Component) []string { +func obsPayloadArchs(comp Component) []string { if comp.Noarch { return Architectures[:1] } return Architectures } -func debPayloadDir(comp Component, arch string) string { +func obsPayloadDir(comp Component, arch string) string { if comp.Noarch { - return DebNoarchDir + return OBSNoarchDir } return arch } diff --git a/packaging/builder/debspec.go b/packaging/builder/obsspec.go similarity index 79% rename from packaging/builder/debspec.go rename to packaging/builder/obsspec.go index e6466b45..9c830fb3 100644 --- a/packaging/builder/debspec.go +++ b/packaging/builder/obsspec.go @@ -15,9 +15,9 @@ import ( var ( //go:embed opentelemetry.spec.tmpl - debSpecTemplateSource string + obsSpecTemplateSource string - debSpecTemplate = template.Must(template.New("opentelemetry.spec.tmpl").Parse(debSpecTemplateSource)) + obsSpecTemplate = template.Must(template.New("opentelemetry.spec.tmpl").Parse(obsSpecTemplateSource)) ) // rpmArch returns the RPM spelling of a payload architecture, which is named after its DEB architecture in the source archive. @@ -32,13 +32,13 @@ func rpmArch(debArch string) string { } } -// DebNoarchDir is the payload directory of an architecture-independent +// OBSNoarchDir is the payload directory of an architecture-independent // component in the DEB source archive. It is the DEB architecture name such a // package carries. -const DebNoarchDir = "all" +const OBSNoarchDir = "all" -// debSpecData is the template input describing one component's spec. -type debSpecData struct { +// obsSpecData is the template input describing one component's spec. +type obsSpecData struct { Name string Version string Release string @@ -68,7 +68,7 @@ type debSpecData struct { Scriptlets []specScriptlet } -// DebVersionRelease returns the Version and Release fields of a debbuild spec. +// OBSVersionRelease returns the Version and Release fields of the spec. // // The version is the one nfpm writes into its DEB packages, a pre-release // suffix after a tilde, so packages from both producers compare the same way. @@ -77,7 +77,7 @@ type debSpecData struct { // default of 1. The Open Build Service replaces the Release field with its own // commit and build counters, so there the revision grows with every commit and // stays above the unrevised version nfpm writes. -func DebVersionRelease(cfg Config) (version, release string, err error) { +func OBSVersionRelease(cfg Config) (version, release string, err error) { v := strings.TrimPrefix(strings.TrimSpace(cfg.Version), "v") if v == "" { return "", "", fmt.Errorf("empty version") @@ -99,33 +99,33 @@ func DebVersionRelease(cfg Config) (version, release string, err error) { return version, release, nil } -// DebSourceArchiveName returns the file name of a component's source archive, +// OBSSourceArchiveName returns the file name of a component's source archive, // which is also the spec's Source0. -func DebSourceArchiveName(comp Component, version string) string { - return DebSourcePrefix(comp, version) + ".tar.gz" +func OBSSourceArchiveName(comp Component, version string) string { + return OBSSourcePrefix(comp, version) + ".tar.gz" } -// DebSourcePrefix returns the top directory of a component's source archive, +// OBSSourcePrefix returns the top directory of a component's source archive, // where debbuild's setup macro expects it. -func DebSourcePrefix(comp Component, version string) string { +func OBSSourcePrefix(comp Component, version string) string { return comp.PackageName + "-" + version } -// WriteDebSpec renders the debbuild spec for one component. +// WriteOBSSpec renders the spec for one component. // // Every component gets its own spec, and therefore its own OBS package, so a // component can be built and released on its own. Unlike WriteSpec, the spec -// builds nothing: the payload is staged ahead of time, by WriteDebSources, into +// builds nothing: the payload is staged ahead of time, by WriteOBSSources, into // the source archive, and the spec only copies it into place. -func WriteDebSpec(cfg Config, comp Component, w io.Writer) error { - version, release, err := DebVersionRelease(cfg) +func WriteOBSSpec(cfg Config, comp Component, w io.Writer) error { + version, release, err := OBSVersionRelease(cfg) if err != nil { return err } var debArchs, rpmArchs string if !comp.Noarch { - archs := debPayloadArchs(comp) + archs := obsPayloadArchs(comp) debArchs = strings.Join(archs, " ") rpmNames := make([]string, 0, len(archs)) for _, arch := range archs { @@ -139,7 +139,7 @@ func WriteDebSpec(cfg Config, comp Component, w io.Writer) error { return err } - data := &debSpecData{ + data := &obsSpecData{ Name: comp.PackageName, Version: version, Release: release, @@ -152,7 +152,7 @@ func WriteDebSpec(cfg Config, comp Component, w io.Writer) error { Packager: cfg.maintainer(), Section: cfg.section(), Noarch: comp.Noarch, - PayloadDir: DebNoarchDir, + PayloadDir: OBSNoarchDir, DebArchs: debArchs, RPMArchs: rpmArchs, Component: comp.Name, @@ -167,5 +167,5 @@ func WriteDebSpec(cfg Config, comp Component, w io.Writer) error { Scriptlets: scriptlets, } - return debSpecTemplate.Execute(w, data) + return obsSpecTemplate.Execute(w, data) } diff --git a/packaging/builder/debspec_test.go b/packaging/builder/obsspec_test.go similarity index 86% rename from packaging/builder/debspec_test.go rename to packaging/builder/obsspec_test.go index 82da0732..f9744b02 100644 --- a/packaging/builder/debspec_test.go +++ b/packaging/builder/obsspec_test.go @@ -19,14 +19,14 @@ import ( "github.com/stretchr/testify/require" ) -func renderDebSpec(t *testing.T, version string, comp Component) string { +func renderOBSSpec(t *testing.T, version string, comp Component) string { t.Helper() var b strings.Builder - require.NoError(t, WriteDebSpec(testConfig(t, version), comp, &b)) + require.NoError(t, WriteOBSSpec(testConfig(t, version), comp, &b)) return b.String() } -func TestDebVersionRelease(t *testing.T) { +func TestOBSVersionRelease(t *testing.T) { tests := []struct { name string version string @@ -46,7 +46,7 @@ func TestDebVersionRelease(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - version, release, err := DebVersionRelease(Config{Version: tt.version, Release: tt.release}) + version, release, err := OBSVersionRelease(Config{Version: tt.version, Release: tt.release}) if tt.wantErr { assert.Error(t, err) return @@ -60,7 +60,7 @@ func TestDebVersionRelease(t *testing.T) { // The version must be the one nfpm writes, so a DEB built by debbuild and one // built by nfpm from the same tag compare as the same upstream version. -func TestDebVersionReleaseMatchesNfpm(t *testing.T) { +func TestOBSVersionReleaseMatchesNfpm(t *testing.T) { packager, err := nfpm.Get("deb") require.NoError(t, err) @@ -75,14 +75,14 @@ func TestDebVersionReleaseMatchesNfpm(t *testing.T) { // writes, after the defaults it applies while packaging. name := packager.ConventionalFileName(nfpm.WithDefaults(info)) - version, _, err := DebVersionRelease(testConfig(t, v)) + version, _, err := OBSVersionRelease(testConfig(t, v)) require.NoError(t, err) assert.Equal(t, Meta.PackageName+"_"+version+"_all.deb", name, "version %s", v) } } -func TestWriteDebSpecPreamble(t *testing.T) { - spec := renderDebSpec(t, "1.2.3", Injector) +func TestWriteOBSSpecPreamble(t *testing.T) { + spec := renderOBSSpec(t, "1.2.3", Injector) assert.Contains(t, spec, "Name: opentelemetry-injector\n") assert.Contains(t, spec, "Version: 1.2.3\n") @@ -106,16 +106,16 @@ func TestWriteDebSpecPreamble(t *testing.T) { // Under the build's umask of 002 debbuild would ship group-writable directories // and man pages; these are the two commands it creates them with. -func TestWriteDebSpecPackagesUnderUmask022(t *testing.T) { - debbuild, rpm := vendorBranches(t, renderDebSpec(t, "1.2.3", Injector)) +func TestWriteOBSSpecPackagesUnderUmask022(t *testing.T) { + debbuild, rpm := vendorBranches(t, renderOBSSpec(t, "1.2.3", Injector)) assert.Contains(t, debbuild, "%global __mkdir_p umask 022 && /bin/mkdir -p\n") assert.Contains(t, debbuild, "%global __gzip umask 022 && /bin/gzip\n") assert.NotContains(t, rpm, "__mkdir_p", "rpm builds with its own macros") } // The prebuilt payload must reach rpm untouched, and its glibc symbol versions must remain install constraints; the same globals the source RPM sets. -func TestWriteDebSpecKeepsPrebuiltBinariesIntactUnderRpm(t *testing.T) { - debbuild, rpm := vendorBranches(t, renderDebSpec(t, "1.2.3", Injector)) +func TestWriteOBSSpecKeepsPrebuiltBinariesIntactUnderRpm(t *testing.T) { + debbuild, rpm := vendorBranches(t, renderOBSSpec(t, "1.2.3", Injector)) for _, want := range []string{ "%global debug_package %{nil}\n", "%global __strip /bin/true\n", @@ -169,10 +169,10 @@ func vendorBranches(t *testing.T, spec string) (debbuild, rpm string) { return d.String(), r.String() } -func TestWriteDebSpecMirrorsTheDependencyModel(t *testing.T) { +func TestWriteOBSSpecMirrorsTheDependencyModel(t *testing.T) { for _, comp := range AllComponents { t.Run(comp.Name, func(t *testing.T) { - spec := renderDebSpec(t, "1.2.3", comp) + spec := renderOBSSpec(t, "1.2.3", comp) for _, p := range comp.Relations.Provides { assert.Contains(t, spec, "Provides: "+p+"\n") } @@ -190,7 +190,7 @@ func TestWriteDebSpecMirrorsTheDependencyModel(t *testing.T) { } // The relationship is Replaces to debbuild and Obsoletes to rpm. -func TestWriteDebSpecDisplacementRelations(t *testing.T) { +func TestWriteOBSSpecDisplacementRelations(t *testing.T) { comp := Component{ Name: "fixture", PackageName: "acme-java-autoinstrumentation", @@ -200,7 +200,7 @@ func TestWriteDebSpecDisplacementRelations(t *testing.T) { Replaces: []string{"opentelemetry-java-autoinstrumentation"}, }, } - spec := renderDebSpec(t, "1.2.3", comp) + spec := renderOBSSpec(t, "1.2.3", comp) assert.Contains(t, spec, "Conflicts: opentelemetry-java-autoinstrumentation\n") debbuild, rpm := vendorBranches(t, spec) @@ -210,8 +210,8 @@ func TestWriteDebSpecDisplacementRelations(t *testing.T) { assert.NotContains(t, rpm, "Replaces:") } -func TestWriteDebSpecSelectsThePayloadByArchitecture(t *testing.T) { - spec := renderDebSpec(t, "1.2.3", Injector) +func TestWriteOBSSpecSelectsThePayloadByArchitecture(t *testing.T) { + spec := renderOBSSpec(t, "1.2.3", Injector) assert.Contains(t, spec, "%{name}-%{version}/%{payload_arch}/root") assert.Contains(t, spec, "%files -f %{payload_arch}/%{filelist}\n") assert.NotContains(t, spec, "BuildArch:") @@ -226,7 +226,7 @@ func TestWriteDebSpecSelectsThePayloadByArchitecture(t *testing.T) { assert.Contains(t, debbuild, "%global filelist injector.deb.files\n") assert.Contains(t, rpm, "%global filelist injector.rpm.files\n") - noarch := renderDebSpec(t, "1.2.3", Java) + noarch := renderOBSSpec(t, "1.2.3", Java) assert.Contains(t, noarch, "BuildArch: noarch\n") assert.Contains(t, noarch, "%global payload_arch all\n") assert.NotContains(t, noarch, "%{_arch}") @@ -236,8 +236,8 @@ func TestWriteDebSpecSelectsThePayloadByArchitecture(t *testing.T) { // An architecture the archive carries no payload for would otherwise fail in // the install section, whose output debbuild discards, leaving nothing to go // on but the exit status. The guard reports it while the spec is read. -func TestWriteDebSpecGuardsUnstagedArchitectures(t *testing.T) { - spec := renderDebSpec(t, "1.2.3", Injector) +func TestWriteOBSSpecGuardsUnstagedArchitectures(t *testing.T) { + spec := renderOBSSpec(t, "1.2.3", Injector) debbuild, rpm := vendorBranches(t, spec) assert.Contains(t, debbuild, "%global payload_archs "+strings.Join(Architectures, " ")+"\n") assert.Contains(t, rpm, "%global payload_archs x86_64 aarch64\n") @@ -245,11 +245,11 @@ func TestWriteDebSpecGuardsUnstagedArchitectures(t *testing.T) { assert.Contains(t, spec, "%{error:this package is built for %{payload_archs}, not %{_arch}}\n") // A noarch payload serves every architecture, so there is nothing to guard. - assert.NotContains(t, renderDebSpec(t, "1.2.3", Java), "%ifnarch %{payload_archs}") + assert.NotContains(t, renderOBSSpec(t, "1.2.3", Java), "%ifnarch %{payload_archs}") } -func TestWriteDebSpecInlinesLifecycleScripts(t *testing.T) { - spec := renderDebSpec(t, "1.2.3", Injector) +func TestWriteOBSSpecInlinesLifecycleScripts(t *testing.T) { + spec := renderOBSSpec(t, "1.2.3", Injector) // One spec per package, so the scriptlets belong to the main package. assert.Contains(t, spec, "%post\n") @@ -258,13 +258,13 @@ func TestWriteDebSpecInlinesLifecycleScripts(t *testing.T) { // Percent signs in the scripts are escaped from macro expansion. assert.Contains(t, spec, "%%") - assert.NotContains(t, renderDebSpec(t, "1.2.3", Java), "%post") + assert.NotContains(t, renderOBSSpec(t, "1.2.3", Java), "%post") } // Comments are macro-expanded too, so the template must not name a section // with its percent sign anywhere but where the section starts. -func TestWriteDebSpecSectionsAppearOnce(t *testing.T) { - spec := renderDebSpec(t, "1.2.3", Injector) +func TestWriteOBSSpecSectionsAppearOnce(t *testing.T) { + spec := renderOBSSpec(t, "1.2.3", Injector) for _, section := range []string{"%description", "%prep", "%build", "%install", "%files", "%post", "%preun"} { count := 0 for line := range strings.SplitSeq(spec, "\n") { @@ -355,7 +355,7 @@ func readArchive(t *testing.T, path string) map[string]*tar.Header { } } -func debFixtureComponent(t *testing.T, noarch bool) Component { +func obsFixtureComponent(t *testing.T, noarch bool) Component { t.Helper() src := writeSource(t, "payload.bin", "payload") return Component{ @@ -371,16 +371,16 @@ func debFixtureComponent(t *testing.T, noarch bool) Component { } } -func TestWriteDebSourcesStagesEveryArchitecture(t *testing.T) { +func TestWriteOBSSourcesStagesEveryArchitecture(t *testing.T) { out := t.TempDir() - comp := debFixtureComponent(t, false) + comp := obsFixtureComponent(t, false) var checkBinaries []string checkBinary := func(arch string) string { checkBinaries = append(checkBinaries, arch) return "/nonexistent/otel-config-check-" + arch } - sources, err := WriteDebSources(testConfig(t, "1.2.3"), comp, checkBinary, out) + sources, err := WriteOBSSources(testConfig(t, "1.2.3"), comp, checkBinary, out) require.NoError(t, err) assert.Equal(t, filepath.Join(out, "opentelemetry-fixture.spec"), sources.Spec) assert.Equal(t, filepath.Join(out, "opentelemetry-fixture-1.2.3.tar.gz"), sources.Archive) @@ -403,8 +403,8 @@ func TestWriteDebSourcesStagesEveryArchitecture(t *testing.T) { assert.Contains(t, string(spec), "Name: opentelemetry-fixture\n") } -func TestWriteDebSourcesStagesNoarchOnce(t *testing.T) { - sources, err := WriteDebSources(testConfig(t, "1.2.3"), debFixtureComponent(t, true), +func TestWriteOBSSourcesStagesNoarchOnce(t *testing.T) { + sources, err := WriteOBSSources(testConfig(t, "1.2.3"), obsFixtureComponent(t, true), func(string) string { return "" }, t.TempDir()) require.NoError(t, err) @@ -415,17 +415,17 @@ func TestWriteDebSourcesStagesNoarchOnce(t *testing.T) { dirs = append(dirs, parts[1]) } } - assert.Equal(t, []string{DebNoarchDir}, dirs) + assert.Equal(t, []string{OBSNoarchDir}, dirs) } -func TestWriteDebSourcesIsReproducible(t *testing.T) { +func TestWriteOBSSourcesIsReproducible(t *testing.T) { t.Setenv("SOURCE_DATE_EPOCH", "1700000000") - comp := debFixtureComponent(t, false) + comp := obsFixtureComponent(t, false) noCheck := func(string) string { return "" } - first, err := WriteDebSources(testConfig(t, "1.2.3"), comp, noCheck, t.TempDir()) + first, err := WriteOBSSources(testConfig(t, "1.2.3"), comp, noCheck, t.TempDir()) require.NoError(t, err) - second, err := WriteDebSources(testConfig(t, "1.2.3"), comp, noCheck, t.TempDir()) + second, err := WriteOBSSources(testConfig(t, "1.2.3"), comp, noCheck, t.TempDir()) require.NoError(t, err) a, err := os.ReadFile(first.Archive) @@ -437,10 +437,10 @@ func TestWriteDebSourcesIsReproducible(t *testing.T) { // rpm expands macros in comments, and an unescaped section macro in one makes rpm 4.16 (EL 9) start that section there: "second install" is how it fails. // Fedora's newer rpm tolerates it, so nothing but this test and an EL build catches a comment that names a section with its percent sign. -func TestWriteDebSpecCommentsNameNoMacros(t *testing.T) { +func TestWriteOBSSpecCommentsNameNoMacros(t *testing.T) { for _, comp := range AllComponents { t.Run(comp.Name, func(t *testing.T) { - for line := range strings.SplitSeq(renderDebSpec(t, "1.2.3", comp), "\n") { + for line := range strings.SplitSeq(renderOBSSpec(t, "1.2.3", comp), "\n") { // A doubled percent sign is escaped, as in the lifecycle scripts. if strings.HasPrefix(line, "#") { assert.NotContains(t, strings.ReplaceAll(line, "%%", ""), "%", diff --git a/packaging/builder/opentelemetry.spec.tmpl b/packaging/builder/opentelemetry.spec.tmpl index 386bf177..251332bd 100644 --- a/packaging/builder/opentelemetry.spec.tmpl +++ b/packaging/builder/opentelemetry.spec.tmpl @@ -2,7 +2,7 @@ Copyright The OpenTelemetry Authors SPDX-License-Identifier: Apache-2.0 -Template for the spec of one component, rendered by WriteDebSpec in debspec.go. +Template for the spec of one component, rendered by WriteOBSSpec in obsspec.go. One spec serves both package formats: OBS builds it with debbuild for the DEB repositories and with rpmbuild for the RPM ones, and the vendor macro tells them apart. Text outside the {{...}} actions is emitted verbatim, so this file reads as the spec it produces. @@ -12,7 +12,7 @@ This matters most to rpm: a section macro in a comment above the preamble makes # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 # -# Generated by "build-spec/deb" from packaging/builder. DO NOT EDIT. +# Generated by "build-spec/obs" from packaging/builder. DO NOT EDIT. # # Built on the Open Build Service, whose builds have no network access, by debbuild for the DEB repositories and by rpmbuild for the RPM ones. # The payload is therefore staged ahead of time, by the same builder that produces the nfpm packages, into the source archive: one tree per architecture, next to a file list for each package format. diff --git a/packaging/builder/stage.go b/packaging/builder/stage.go index 098f47b5..114562ea 100644 --- a/packaging/builder/stage.go +++ b/packaging/builder/stage.go @@ -62,7 +62,7 @@ func Stage(cfg Config, comp Component, root, filelistDir string) error { } // Names of the file lists StageOBS writes beside the payload, one per package format. -// The unified spec (see debspec.go) picks the one for the build it is running under. +// The unified spec (see obsspec.go) picks the one for the build it is running under. const ( RPMFileListSuffix = ".rpm.files" DEBFileListSuffix = ".deb.files" From 6fc2be00901c1b740e60575fe31faee1a4ed7185 Mon Sep 17 00:00:00 2001 From: x1unix <9203548+x1unix@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:51:39 -0500 Subject: [PATCH 3/6] feat: enable python instrumentation package Signed-off-by: x1unix <9203548+x1unix@users.noreply.github.com> --- .github/workflows/build.yml | 3 +-- AGENTS.md | 2 +- CONTRIBUTING.md | 9 +++------ Makefile | 6 ++---- packaging/repo/rpm-obs-rebuild.sh | 21 +++------------------ 5 files changed, 10 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 25b9d2bc..40fc99ed 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -185,9 +185,8 @@ jobs: SOURCE_DATE_EPOCH: "1700000000" run: make obs-sources VERSION=0.0.0-dev - # The Python package is not built for EL, whose interpreter does not match the bundled wheels. - name: Build the specs with rpmbuild and check the metadata - run: make integration-test-obs-rpm-rebuild ARCH=${{ matrix.arch }} RPM_REBUILD_IMAGE=${{ matrix.image }} RPM_REBUILD_SKIP=${{ contains(matrix.image, 'almalinux') && 'python' || '' }} + run: make integration-test-obs-rpm-rebuild ARCH=${{ matrix.arch }} RPM_REBUILD_IMAGE=${{ matrix.image }} integration-tests: needs: build-packages diff --git a/AGENTS.md b/AGENTS.md index 578bf1ce..917477ad 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,7 +31,7 @@ make pyproto-unit-tests # Vendored pyproto exporter test suites (throwawa make integration-test-metadata # Fast metadata tests (no containers) make integration-test-deb-rebuild # Same metadata tests over the debbuild output make obs-rpm-rebuild-container # Build the same specs with rpmbuild the way OBS does - # RPM_REBUILD_IMAGE=docker.io/almalinux/9-base RPM_REBUILD_SKIP=python for EL + # RPM_REBUILD_IMAGE=docker.io/almalinux/9-base to exercise the EL rpm make integration-test-obs-rpm-rebuild # RPM metadata tests over the rpmbuild output make integration-tests # Full E2E tests (requires Podman/Docker) make integration-test-deb-java # Single E2E test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69d842e3..90408db4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -261,11 +261,8 @@ Some properties of the DEBs differ from the nfpm packages, and are worth knowing - The compression follows the build distribution's `dpkg` default: xz on Debian, zstd on Ubuntu. - The packages are not byte-reproducible: debbuild stamps the directories it creates, and the man page it recompresses, with the time of the build. The source archives are, which is what matters for OBS, where a changed archive is a rebuild. -The RPMs built from the same spec differ from the source RPM the COPR path produced in two ways: - -- Nothing is compiled or downloaded at build time. The spec has no `BuildRequires`, because the payload is staged beforehand. -- The Python package is not built for EL, whose interpreter does not match the bundled wheels. On OBS that package is disabled in the EL repository; locally, `RPM_REBUILD_SKIP=python` leaves it out. - +Unlike the source RPM the COPR path produced, nothing is compiled or downloaded at build time. +The spec has no `BuildRequires`, because the payload is staged beforehand. The spec sets the same globals the source RPM did: no debuginfo, no stripping of the prebuilt binaries, and no private libraries published as `Provides`. `AutoReq` stays on for rpm, so the glibc symbol versions the binaries need remain install constraints. @@ -287,7 +284,7 @@ Every other assertion about this path reads the text of the generated spec, and `make obs-rpm-rebuild-container` builds the same specs with rpmbuild, and `make integration-test-obs-rpm-rebuild` runs the RPM metadata tests over the result: ```sh -make integration-test-obs-rpm-rebuild RPM_REBUILD_IMAGE=docker.io/almalinux/9-base RPM_REBUILD_SKIP=python +make integration-test-obs-rpm-rebuild RPM_REBUILD_IMAGE=docker.io/almalinux/9-base ``` `RPM_REBUILD_IMAGE` defaults to Fedora 44. diff --git a/Makefile b/Makefile index 50a35d67..e1d5fce7 100644 --- a/Makefile +++ b/Makefile @@ -340,9 +340,7 @@ integration-test-deb-rebuild: deb-rebuild-container # Builds the same generated specs with rpmbuild in a container, the way OBS does for the RPM repositories, and runs the RPM metadata tests over the result. # # RPM_REBUILD_IMAGE selects the build distribution; almalinux:9 exercises the oldest rpm (4.16) the specs have to parse under. -# RPM_REBUILD_SKIP lists the components to leave out: python is not built for EL, whose interpreter does not match the bundled wheels. RPM_REBUILD_IMAGE ?= registry.fedoraproject.org/fedora:44 -RPM_REBUILD_SKIP ?= RPM_REBUILD_OUTPUT_DIR ?= $(CURDIR)/build/rpm-rebuild .PHONY: obs-rpm-rebuild-container @@ -358,11 +356,11 @@ obs-rpm-rebuild-container: -v $(RPM_REBUILD_OUTPUT_DIR):/out \ -v $(CURDIR)/packaging/repo:/scripts:ro \ $(RPM_REBUILD_IMAGE) \ - /scripts/rpm-obs-rebuild.sh /sources /out $(RPM_REBUILD_SKIP) + /scripts/rpm-obs-rebuild.sh /sources /out .PHONY: integration-test-obs-rpm-rebuild integration-test-obs-rpm-rebuild: obs-rpm-rebuild-container - PACKAGES_DIR=$(RPM_REBUILD_OUTPUT_DIR) go test -v -timeout 5m -run TestRpm $(if $(findstring python,$(RPM_REBUILD_SKIP)),-skip Python) ./packaging/tests/metadata/ + PACKAGES_DIR=$(RPM_REBUILD_OUTPUT_DIR) go test -v -timeout 5m -run TestRpm ./packaging/tests/metadata/ # ============================================================================ # Local Package Repositories for Testing diff --git a/packaging/repo/rpm-obs-rebuild.sh b/packaging/repo/rpm-obs-rebuild.sh index 768a3915..33ed94e3 100755 --- a/packaging/repo/rpm-obs-rebuild.sh +++ b/packaging/repo/rpm-obs-rebuild.sh @@ -6,22 +6,18 @@ # Build the generated OBS specs with rpmbuild the way the Open Build Service does. # This script is meant to run inside a Fedora or EL container. # -# Usage: rpm-obs-rebuild.sh [skipped_component ...] +# Usage: rpm-obs-rebuild.sh # # Expected structure: # //.spec # //-.tar.gz # # Every package found is built, and the .rpm files are copied to . -# A package named as a skipped component is left out. -# The Python package is not built for EL, whose interpreter does not match the bundled wheels. set -euo pipefail -sources_dir="${1:?usage: rpm-obs-rebuild.sh [skipped_component ...]}" -output_dir="${2:?usage: rpm-obs-rebuild.sh [skipped_component ...]}" -shift 2 -skipped=("$@") +sources_dir="${1:?usage: rpm-obs-rebuild.sh }" +output_dir="${2:?usage: rpm-obs-rebuild.sh }" echo "Installing the build dependencies" # The payload is prebuilt, so rpmbuild is all a build needs. @@ -38,17 +34,6 @@ for spec in "$sources_dir"/*/*.spec; do [ -e "$spec" ] || continue package="$(basename "$(dirname "$spec")")" - skip=false - for component in "${skipped[@]}"; do - if [ "$package" = "opentelemetry-${component}-autoinstrumentation" ]; then - skip=true - fi - done - if [ "$skip" = true ]; then - echo "Skipping $package" - continue - fi - work="/tmp/rpmbuild/$package" echo "" From ace36915b9efd5f2f949237f931de897bdd2f5ec Mon Sep 17 00:00:00 2001 From: x1unix <9203548+x1unix@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:08:20 -0500 Subject: [PATCH 4/6] fix: Pin test container images Signed-off-by: x1unix <9203548+x1unix@users.noreply.github.com> --- .github/workflows/build.yml | 8 ++++++-- Makefile | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40fc99ed..805fa579 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -116,7 +116,9 @@ jobs: strategy: fail-fast: false matrix: - image: [ "debian:12", "ubuntu:24.04" ] + image: + - debian@sha256:268fb24c39bca92d326dd83ea3abebe4a3f7751c804ffef23bb6d857dd343ff8 # debian:12 + - ubuntu@sha256:73b999393d07f2bf65a40373778a44dc9a6d54ad7718d29247d8ff9413c4d6a8 # ubuntu:24.04 arch: [ "amd64", "arm64" ] runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }} steps: @@ -169,7 +171,9 @@ jobs: fail-fast: false matrix: # Fedora, and the oldest rpm the specs have to parse under. - image: [ "registry.fedoraproject.org/fedora:44", "docker.io/almalinux/9-base" ] + image: + - registry.fedoraproject.org/fedora@sha256:98b558564d3510363f0f706a44b1ee9de461b030373d741c5729ae3f24d8cb26 # fedora:44 + - docker.io/almalinux/9-base@sha256:2edb3541b7909af131c4ca8ae2c8cb985b20c80364e1f1230de88fb1131a0228 # almalinux/9-base arch: [ "amd64", "arm64" ] runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }} steps: diff --git a/Makefile b/Makefile index e1d5fce7..e5fceade 100644 --- a/Makefile +++ b/Makefile @@ -309,7 +309,7 @@ check-reproducible-obs-sources-%: otel-config-check-all # # DEB_REBUILD_IMAGE selects the build distribution. Debian and Ubuntu differ in # the compression dpkg-deb defaults to, and in little else here. -DEB_REBUILD_IMAGE ?= debian:12 +DEB_REBUILD_IMAGE ?= debian@sha256:268fb24c39bca92d326dd83ea3abebe4a3f7751c804ffef23bb6d857dd343ff8 # debian:12 DEB_REBUILD_OUTPUT_DIR ?= $(CURDIR)/build/deb-rebuild # Pinned, so that an upstream change to the macros the specs rely on fails on a @@ -340,7 +340,7 @@ integration-test-deb-rebuild: deb-rebuild-container # Builds the same generated specs with rpmbuild in a container, the way OBS does for the RPM repositories, and runs the RPM metadata tests over the result. # # RPM_REBUILD_IMAGE selects the build distribution; almalinux:9 exercises the oldest rpm (4.16) the specs have to parse under. -RPM_REBUILD_IMAGE ?= registry.fedoraproject.org/fedora:44 +RPM_REBUILD_IMAGE ?= registry.fedoraproject.org/fedora@sha256:98b558564d3510363f0f706a44b1ee9de461b030373d741c5729ae3f24d8cb26 # fedora:44 RPM_REBUILD_OUTPUT_DIR ?= $(CURDIR)/build/rpm-rebuild .PHONY: obs-rpm-rebuild-container From 327f095c3bf0bb746494f20aebe40ae1045fc77d Mon Sep 17 00:00:00 2001 From: x1unix <9203548+x1unix@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:08:36 -0500 Subject: [PATCH 5/6] fix: Sync spec with home:opentelemetry:sandbox state Signed-off-by: x1unix <9203548+x1unix@users.noreply.github.com> --- docs/design/package-publishing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design/package-publishing.md b/docs/design/package-publishing.md index aa070e74..12974396 100644 --- a/docs/design/package-publishing.md +++ b/docs/design/package-publishing.md @@ -185,7 +185,7 @@ In phase 1, the stable build project has 2 repositories, both built for the `x86 The package contents do not depend on the distribution release they are built against, so the packages are expected to install on newer releases of the same distribution. Debian and Ubuntu get separate repositories in case the content of the packages needs to diverge. -The sandbox instead has a repository per release (Debian 12 and 13, Ubuntu 22.04, 24.04, and 26.04), each for both architectures so that it is possible to compare the same package across releases before it reaches users. +The sandbox has the same repositories as the stable build project, so that a change is tried the way it will be built for users. ### Sources From 2fccf9866544176abe9cea8bc195197e73988218 Mon Sep 17 00:00:00 2001 From: x1unix <9203548+x1unix@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:40:07 -0500 Subject: [PATCH 6/6] fix: Stop rpmbuild from rewriting the prebuilt payload brp-mangle-shebangs rewrote "#!/usr/bin/env node" to "#!/usr/bin/node" in the Node.js scripts, so the RPMs shipped different bytes from the DEBs built from the same source archive and the scripts failed on hosts whose node is not /usr/bin/node. Turn it off, and brp-python-bytecompile too, which would write unpackaged __pycache__ files if its inputs changed. Signed-off-by: x1unix <9203548+x1unix@users.noreply.github.com> --- packaging/builder/obsspec_test.go | 2 ++ packaging/builder/opentelemetry.spec.tmpl | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/packaging/builder/obsspec_test.go b/packaging/builder/obsspec_test.go index f9744b02..196b5bd5 100644 --- a/packaging/builder/obsspec_test.go +++ b/packaging/builder/obsspec_test.go @@ -120,6 +120,8 @@ func TestWriteOBSSpecKeepsPrebuiltBinariesIntactUnderRpm(t *testing.T) { "%global debug_package %{nil}\n", "%global __strip /bin/true\n", "%global _build_id_links none\n", + "%global __brp_mangle_shebangs %{nil}\n", + "%global __brp_python_bytecompile %{nil}\n", "%global source_date_epoch_from_changelog 0\n", "%global __provides_exclude_from ^%{_prefix}/lib/opentelemetry/.*$\n", "%global __requires_exclude ^%{_bindir}/(node|python3)$\n", diff --git a/packaging/builder/opentelemetry.spec.tmpl b/packaging/builder/opentelemetry.spec.tmpl index 251332bd..1b918f0c 100644 --- a/packaging/builder/opentelemetry.spec.tmpl +++ b/packaging/builder/opentelemetry.spec.tmpl @@ -42,9 +42,13 @@ AutoReq: no {{ end -}} %else # The bundled agents are prebuilt binaries: no stripping, no debuginfo, and no build-id links. +# The payload must also reach the package byte for byte as it is in the source archive, which is what the DEB packages ship. +# Two post-install scripts rewrite files in the buildroot unless switched off: brp-mangle-shebangs, which turns "#!/usr/bin/env node" into "#!/usr/bin/node" and so breaks the scripts on a host whose node is elsewhere, and brp-python-bytecompile, which would write unpackaged __pycache__ files. %global debug_package %{nil} %global __strip /bin/true %global _build_id_links none +%global __brp_mangle_shebangs %{nil} +%global __brp_python_bytecompile %{nil} # This spec carries no changelog, so there is no date in it to derive SOURCE_DATE_EPOCH from. # Saying so is better than fabricating an entry to satisfy the macro, which would otherwise warn on every build.