From 0251d4e7d5897252605fa88c248a3aadaac8179b Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Thu, 19 Sep 2024 09:10:15 +0200 Subject: [PATCH 1/8] previous commits --- .github/workflows/base-ci-goreleaser.yaml | 73 +++++++++- ...age-tests.yaml => base-package-tests.yaml} | 0 .github/workflows/ci-goreleaser-contrib.yaml | 2 +- .github/workflows/ci-goreleaser-core.yaml | 2 +- .github/workflows/package-test.yaml | 24 ++++ cmd/goreleaser/internal/configure.go | 136 +++++++++++------- cmd/goreleaser/main.go | 10 +- .../otelcol-contrib/.goreleaser-build.yaml | 43 ++++++ .../otelcol-contrib/.goreleaser.yaml | 10 +- scripts/build.sh | 2 +- scripts/generate-goreleaser.sh | 4 + 11 files changed, 239 insertions(+), 67 deletions(-) rename .github/workflows/{package-tests.yaml => base-package-tests.yaml} (100%) create mode 100644 .github/workflows/package-test.yaml create mode 100644 distributions/otelcol-contrib/.goreleaser-build.yaml diff --git a/.github/workflows/base-ci-goreleaser.yaml b/.github/workflows/base-ci-goreleaser.yaml index 7a036bef..4e9799f0 100644 --- a/.github/workflows/base-ci-goreleaser.yaml +++ b/.github/workflows/base-ci-goreleaser.yaml @@ -12,6 +12,11 @@ on: goarch: required: true type: string + nightly: + required: false + type: boolean + default: false + description: "Set to true to fetch latest otelcol-contrib main branch version instead of building the version in this repo" env: # renovate: datasource=github-tags depName=goreleaser-pro packageName=goreleaser/goreleaser-pro @@ -64,9 +69,75 @@ jobs: go-version: '1.23' check-latest: true - - name: Generate the sources + - name: Create artifacts directory to store build artifacts + if: inputs.distribution == 'otelcol-contrib' + run: mkdir -p distributions/otelcol-contrib/artifacts + + - name: "[Nightly] Get latest finished run ID from contrib repo build-and-test" + id: get-run-id + if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux' + env: + GH_TOKEN: ${{ github.token }} + run: | + run_id=$(gh run list \ + --branch main \ + --workflow build-and-test \ + --repo open-telemetry/opentelemetry-collector-contrib \ + --limit 1 \ + --status success \ + --json databaseId \ + --jq '.[0].databaseId' \ + ) + echo "Found run ID: $run_id" + echo "run_id=$run_id" >> "$GITHUB_OUTPUT" + + - name: "[Nightly] Create sub-directory for otelcol-contrib nightly build" + if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux' + run: mkdir -p distributions/otelcol-contrib/artifacts/otelcol-contrib_linux_amd64_v1 + + - name: "[Nightly] Download built otelcol-contrib artifact from contrib repo" + if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux' + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: collector-binaries-linux-amd64 + repository: open-telemetry/opentelemetry-collector-contrib + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ steps.get-run-id.outputs.run_id }} + + - name: "[Nightly] Move downloaded artifact" + if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux' + run: mv otelcontribcol_linux_amd64 distributions/otelcol-contrib/artifacts/otelcol-contrib_linux_amd64_v1/otelcol-contrib + + - name: Generate the sources for ${{ inputs.distribution }} + if: inputs.nightly != true + env: + DISTRIBUTIONS: ${{ inputs.distribution }} run: make generate-sources + # otelcol-contrib is built in a separate stage + - name: Build ${{ inputs.distribution }} + if: inputs.distribution == 'otelcol-contrib' && inputs.nightly != true + uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0 + with: + distribution: goreleaser-pro + version: ${{ env.GORELEASER_PRO_VERSION }} + workdir: distributions/otelcol-contrib + args: --snapshot --clean --timeout 2h --split --config .goreleaser-build.yaml + env: + GOOS: ${{ matrix.GOOS }} + GOARCH: ${{ matrix.GOARCH }} + GOARM: 7 # Default is 6 + GOAMD64: v1 + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + + - name: Move built artifacts + if: inputs.distribution == 'otelcol-contrib' && inputs.nightly != true + run: mv distributions/otelcol-contrib/dist/**/* distributions/otelcol-contrib/artifacts/ + + - name: Show built or downloaded content + if: inputs.distribution == 'otelcol-contrib' + run: ls -laR distributions/otelcol-contrib/artifacts + - name: Run GoReleaser for ${{ inputs.distribution }} uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0 with: diff --git a/.github/workflows/package-tests.yaml b/.github/workflows/base-package-tests.yaml similarity index 100% rename from .github/workflows/package-tests.yaml rename to .github/workflows/base-package-tests.yaml diff --git a/.github/workflows/ci-goreleaser-contrib.yaml b/.github/workflows/ci-goreleaser-contrib.yaml index fed5f85d..a85e0f22 100644 --- a/.github/workflows/ci-goreleaser-contrib.yaml +++ b/.github/workflows/ci-goreleaser-contrib.yaml @@ -36,7 +36,7 @@ jobs: package-tests: name: Package tests needs: check-goreleaser - uses: ./.github/workflows/package-tests.yaml + uses: ./.github/workflows/base-package-tests.yaml with: distribution: otelcol-contrib type: '[ "deb", "rpm" ]' diff --git a/.github/workflows/ci-goreleaser-core.yaml b/.github/workflows/ci-goreleaser-core.yaml index 80a116a8..ae191138 100644 --- a/.github/workflows/ci-goreleaser-core.yaml +++ b/.github/workflows/ci-goreleaser-core.yaml @@ -37,7 +37,7 @@ jobs: package-tests: name: Package tests needs: check-goreleaser - uses: ./.github/workflows/package-tests.yaml + uses: ./.github/workflows/base-package-tests.yaml with: distribution: otelcol type: '[ "deb", "rpm" ]' diff --git a/.github/workflows/package-test.yaml b/.github/workflows/package-test.yaml new file mode 100644 index 00000000..b0ab6cfc --- /dev/null +++ b/.github/workflows/package-test.yaml @@ -0,0 +1,24 @@ +name: Package Tests - Contrib + +on: + schedule: + - cron: "0 2 * * *" # every day at 2am UTC + +jobs: + check-goreleaser: + name: Build - Contrib - GoReleaser + uses: ./.github/workflows/base-ci-goreleaser.yaml + with: + distribution: otelcol-contrib + goos: '[ "linux" ]' + goarch: '[ "amd64" ]' + nightly: true + secrets: inherit + + package-tests: + name: Linux Package tests + needs: check-goreleaser + uses: ./.github/workflows/base-package-tests.yaml + with: + distribution: otelcol-contrib + type: '[ "deb", "rpm" ]' diff --git a/cmd/goreleaser/internal/configure.go b/cmd/goreleaser/internal/configure.go index 21100479..d93a05e4 100644 --- a/cmd/goreleaser/internal/configure.go +++ b/cmd/goreleaser/internal/configure.go @@ -42,7 +42,6 @@ const ( var ( ImagePrefixes = []string{DockerHub, GHCR} Architectures = []string{"386", "amd64", "arm", "arm64", "ppc64le", "s390x"} - ArmVersions = []string{"7"} DefaultConfigDists = map[string]bool{CoreDistro: true, ContribDistro: true} MSIWindowsDists = map[string]bool{CoreDistro: true, ContribDistro: true, OTLPDistro: true} K8sDockerSkipArchs = map[string]bool{"arm": true, "386": true} @@ -71,14 +70,25 @@ func InternalLinkPIESupported(goos, goarch string) bool { return false } -func Generate(dist string) config.Project { +func GenerateContribBuildOnly(dist string, buildOrRest bool) config.Project { + return config.Project{ + ProjectName: "opentelemetry-collector-releases", + Builds: Builds(dist, buildOrRest), + Version: 2, + Monorepo: config.Monorepo{ + TagPrefix: "v", + }, + } +} + +func Generate(dist string, buildOrRest bool) config.Project { return config.Project{ ProjectName: "opentelemetry-collector-releases", Checksum: config.Checksum{ NameTemplate: fmt.Sprintf("{{ .ProjectName }}_%v_checksums.txt", dist), }, Env: []string{"COSIGN_YES=true"}, - Builds: Builds(dist), + Builds: Builds(dist, buildOrRest), Archives: Archives(dist), MSI: WinPackages(dist), NFPMs: Packages(dist), @@ -94,53 +104,48 @@ func Generate(dist string) config.Project { } } -func Builds(dist string) []config.Build { +func Builds(dist string, buildOrRest bool) []config.Build { return []config.Build{ - Build(dist, true), - Build(dist, false), + Build(dist, buildOrRest, true), + Build(dist, buildOrRest, false), } } -func generateIgnored(goos, archs []string, pie bool) []config.IgnoredBuild { - ignored := make([]config.IgnoredBuild, 0) - var build config.IgnoredBuild - for _, goos := range goos { - for _, arch := range archs { - build = config.IgnoredBuild{ - Goos: goos, - Goarch: arch, - } - if _, ok := AlwaysIgnored[build]; ok || !pie && InternalLinkPIESupported(goos, arch) || pie && !InternalLinkPIESupported(goos, arch) { - ignored = append(ignored, build) - } - } - } - return ignored -} - // Build configures a goreleaser build. // https://goreleaser.com/customization/build/ -func Build(dist string, pie bool) config.Build { - var goos []string - var archs []string - var ignore []config.IgnoredBuild - var armVersions []string +func Build(dist string, buildOrRest bool, pie bool) config.Build { + goos := []string{"darwin", "linux", "windows"} + archs := Architectures id := dist ldflags := []string{"-s", "-w"} if pie { ldflags = append(ldflags, "-buildmode=pie") id = id + "-pie" } + + if dist == ContribDistro && !buildOrRest { + // only return build config for contrib build file + return config.Build{ + ID: dist, + Builder: "prebuilt", + PreBuilt: config.PreBuiltOptions{ + Path: "artifacts/otelcol-contrib_{{ .Target }}" + + "/otelcol-contrib{{- if eq .Os \"windows\" }}.exe{{ end }}", + }, + Goos: goos, + Goarch: archs, + Goarm: ArmVersions(dist), + Dir: "_build", + Binary: dist, + Ignore: generateIgnored(dist, goos, archs, pie), + } + } + if dist == K8sDistro { goos = K8sGoos archs = K8sArchs - armVersions = make([]string, 0) - } else { - goos = []string{"darwin", "linux", "windows"} - archs = Architectures - armVersions = ArmVersions } - ignore = generateIgnored(goos, archs, pie) + return config.Build{ ID: id, Dir: "_build", @@ -152,12 +157,39 @@ func Build(dist string, pie bool) config.Build { }, Goos: goos, Goarch: archs, - Goarm: armVersions, - Ignore: ignore, + Goarm: ArmVersions(dist), + Ignore: IgnoreBuildCombinations(dist), } } -func Archives(dist string) (r []config.Archive) { +func generateIgnored(dist string, goos, archs []string, pie bool) []config.IgnoredBuild { + if dist == K8sDistro { + return nil + } + ignored := make([]config.IgnoredBuild, 0) + var build config.IgnoredBuild + for _, goos := range goos { + for _, arch := range archs { + build = config.IgnoredBuild{ + Goos: goos, + Goarch: arch, + } + if _, ok := AlwaysIgnored[build]; ok || !pie && InternalLinkPIESupported(goos, arch) || pie && !InternalLinkPIESupported(goos, arch) { + ignored = append(ignored, build) + } + } + } + return ignored +} + +func ArmVersions(dist string) []string { + if dist == K8sDistro { + return nil + } + return []string{"7"} +} + +func Archives(dist string) []config.Archive { return []config.Archive{ Archive(dist, true), Archive(dist, false), @@ -182,7 +214,7 @@ func Archive(dist string, pie bool) config.Archive { func WinPackages(dist string) []config.MSI { if _, ok := MSIWindowsDists[dist]; !ok { - return []config.MSI{} + return nil } return []config.MSI{ WinPackage(dist), @@ -204,9 +236,9 @@ func WinPackage(dist string) config.MSI { } } -func Packages(dist string) (r []config.NFPM) { +func Packages(dist string) []config.NFPM { if dist == K8sDistro { - return []config.NFPM{} + return nil } return []config.NFPM{ Package(dist), @@ -236,21 +268,17 @@ func Package(dist string) config.NFPM { }) } return config.NFPM{ - ID: dist, - Builds: []string{dist, buildPie}, - Formats: []string{"deb", "rpm"}, - + ID: dist, + Builds: []string{dist, buildPie}, + Formats: []string{"deb", "rpm"}, License: "Apache 2.0", Description: fmt.Sprintf("OpenTelemetry Collector - %s", dist), Maintainer: "The OpenTelemetry Collector maintainers ", Overrides: map[string]config.NFPMOverridables{ "rpm": { - Dependencies: []string{ - "/bin/sh", - }, + Dependencies: []string{"/bin/sh"}, }, }, - NFPMOverridables: config.NFPMOverridables{ PackageName: dist, Scripts: config.NFPMScripts{ @@ -264,16 +292,14 @@ func Package(dist string) config.NFPM { } func DockerImages(dist string) []config.Docker { - r := make([]config.Docker, 0) + var r []config.Docker for _, arch := range Architectures { - if dist == K8sDistro { - if _, ok := K8sDockerSkipArchs[arch]; ok { - continue - } + if dist == K8sDistro && K8sDockerSkipArchs[arch] { + continue } switch arch { case ArmArch: - for _, vers := range ArmVersions { + for _, vers := range ArmVersions(dist) { r = append(r, DockerImage(dist, arch, vers)) } default: @@ -347,7 +373,7 @@ func DockerManifest(prefix, version, dist string) config.DockerManifest { } switch arch { case ArmArch: - for _, armVers := range ArmVersions { + for _, armVers := range ArmVersions(dist) { dockerArchTag := strings.ReplaceAll(archName(arch, armVers), "/", "") imageTemplates = append( imageTemplates, diff --git a/cmd/goreleaser/main.go b/cmd/goreleaser/main.go index b466e06d..ae9ffcaa 100644 --- a/cmd/goreleaser/main.go +++ b/cmd/goreleaser/main.go @@ -19,12 +19,14 @@ import ( "log" "os" + "github.com/goreleaser/goreleaser-pro/v2/pkg/config" "gopkg.in/yaml.v3" "github.com/open-telemetry/opentelemetry-collector-releases/cmd/goreleaser/internal" ) var distFlag = flag.String("d", "", "Collector distributions to build") +var contribBuildOrRestFlag = flag.Bool("generate-build-step", false, "Collector Contrib distribution only - switch between build and package config file - set to true to generate build step, false to generate package step") func main() { flag.Parse() @@ -32,8 +34,14 @@ func main() { if len(*distFlag) == 0 { log.Fatal("no distribution to build") } + var project config.Project - project := internal.Generate(*distFlag) + if *distFlag == internal.ContribDistro && *contribBuildOrRestFlag { + // Special care needs to be taken for otelcol-contrib since it has a split setup + project = internal.GenerateContribBuildOnly(*distFlag, *contribBuildOrRestFlag) + } else { + project = internal.Generate(*distFlag, *contribBuildOrRestFlag) + } partial := map[string]any{ "partial": map[string]any{ diff --git a/distributions/otelcol-contrib/.goreleaser-build.yaml b/distributions/otelcol-contrib/.goreleaser-build.yaml new file mode 100644 index 00000000..b5f60c0d --- /dev/null +++ b/distributions/otelcol-contrib/.goreleaser-build.yaml @@ -0,0 +1,43 @@ +partial: + by: target +version: 2 +project_name: opentelemetry-collector-releases +builds: + - id: otelcol-contrib + goos: + - darwin + - linux + - windows + goarch: + - "386" + - amd64 + - arm + - arm64 + - ppc64le + - s390x + goarm: + - "7" + ignore: + - goos: darwin + goarch: "386" + - goos: darwin + goarch: arm + - goos: darwin + goarch: s390x + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 + - goos: windows + goarch: s390x + dir: _build + binary: otelcol-contrib + ldflags: + - -s + - -w + flags: + - -trimpath + env: + - CGO_ENABLED=0 +monorepo: + tag_prefix: v diff --git a/distributions/otelcol-contrib/.goreleaser.yaml b/distributions/otelcol-contrib/.goreleaser.yaml index 15c5a02a..f1229d29 100644 --- a/distributions/otelcol-contrib/.goreleaser.yaml +++ b/distributions/otelcol-contrib/.goreleaser.yaml @@ -102,13 +102,9 @@ builds: goarch: s390x dir: _build binary: otelcol-contrib - ldflags: - - -s - - -w - flags: - - -trimpath - env: - - CGO_ENABLED=0 + builder: prebuilt + prebuilt: + path: artifacts/otelcol-contrib_{{ .Target }}/otelcol-contrib{{- if eq .Os "windows" }}.exe{{ end }} archives: - id: otelcol-contrib-pie builds: diff --git a/scripts/build.sh b/scripts/build.sh index bcf810b3..e6b325f4 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -6,7 +6,7 @@ BUILDER='' # default values skipcompilation=false -while getopts d:s:b:g: flag +while getopts d:s:b: flag do case "${flag}" in d) distributions=${OPTARG};; diff --git a/scripts/generate-goreleaser.sh b/scripts/generate-goreleaser.sh index 7b6c7ae7..e3262bd6 100755 --- a/scripts/generate-goreleaser.sh +++ b/scripts/generate-goreleaser.sh @@ -23,5 +23,9 @@ echo "Distributions to generate: $distributions"; for distribution in $(echo "$distributions" | tr "," "\n") do + if [[ "$distribution" == "otelcol-contrib" ]]; then + ${GO} run cmd/goreleaser/main.go -d "${distribution}" --generate-build-step > "./distributions/${distribution}/.goreleaser-build.yaml" + fi + ${GO} run cmd/goreleaser/main.go -d "${distribution}" > "./distributions/${distribution}/.goreleaser.yaml" done From e8449ae6f11b0dc0879018e3d8a081b12e522aa2 Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Wed, 4 Dec 2024 16:03:58 +0100 Subject: [PATCH 2/8] release pipeline fixes --- .github/workflows/base-release.yaml | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/base-release.yaml b/.github/workflows/base-release.yaml index bc2fddd3..22f88060 100644 --- a/.github/workflows/base-release.yaml +++ b/.github/workflows/base-release.yaml @@ -84,6 +84,36 @@ jobs: run: | echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + - name: Create artifacts directory to store build artifacts + if: inputs.distribution == 'otelcol-contrib' + run: mkdir -p distributions/otelcol-contrib/artifacts + + # otelcol-contrib is built in a separate stage + - name: Build ${{ inputs.distribution }} + if: inputs.distribution == 'otelcol-contrib' + uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0 + with: + distribution: goreleaser-pro + version: ${{ env.GORELEASER_PRO_VERSION }} + workdir: distributions/${{ inputs.distribution }} + args: release --clean --split --timeout 2h --config .goreleaser-build.yaml --release-header-tmpl=../../.github/release-template.md + env: + GOOS: ${{ matrix.GOOS }} + GOARCH: ${{ matrix.GOARCH }} + GOARM: 7 # Default is 6 + GOAMD64: v1 + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + COSIGN_YES: true + + - name: Move built artifacts + if: inputs.distribution == 'otelcol-contrib' + run: mv distributions/otelcol-contrib/dist/**/* distributions/otelcol-contrib/artifacts/ + + - name: Show built or downloaded content + if: inputs.distribution == 'otelcol-contrib' + run: ls -laR distributions/otelcol-contrib/artifacts + - uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0 with: distribution: goreleaser-pro From d4f041417ba81af9c0785ccda69a7c3e6165f9ed Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Wed, 11 Dec 2024 10:34:22 +0100 Subject: [PATCH 3/8] fixes after rebasing Signed-off-by: Moritz Wiesinger --- cmd/goreleaser/internal/configure.go | 19 +++--- .../otelcol-contrib/.goreleaser-build.yaml | 61 +++++++++++++++++++ .../otelcol-contrib/.goreleaser.yaml | 11 +--- 3 files changed, 74 insertions(+), 17 deletions(-) diff --git a/cmd/goreleaser/internal/configure.go b/cmd/goreleaser/internal/configure.go index d93a05e4..2f57dd44 100644 --- a/cmd/goreleaser/internal/configure.go +++ b/cmd/goreleaser/internal/configure.go @@ -118,26 +118,30 @@ func Build(dist string, buildOrRest bool, pie bool) config.Build { archs := Architectures id := dist ldflags := []string{"-s", "-w"} + var prebuiltPath string + if pie { ldflags = append(ldflags, "-buildmode=pie") id = id + "-pie" + prebuiltPath = fmt.Sprintf("artifacts/otelcol-contrib%s_{{ .Target }}/otelcol-contrib{{- if eq .Os \"windows\" }}.exe{{ end }}", "-pie") + } else { + prebuiltPath = "artifacts/otelcol-contrib_{{ .Target }}/otelcol-contrib{{- if eq .Os \"windows\" }}.exe{{ end }}" } if dist == ContribDistro && !buildOrRest { // only return build config for contrib build file return config.Build{ - ID: dist, + ID: id, Builder: "prebuilt", PreBuilt: config.PreBuiltOptions{ - Path: "artifacts/otelcol-contrib_{{ .Target }}" + - "/otelcol-contrib{{- if eq .Os \"windows\" }}.exe{{ end }}", + Path: prebuiltPath, }, Goos: goos, Goarch: archs, Goarm: ArmVersions(dist), Dir: "_build", Binary: dist, - Ignore: generateIgnored(dist, goos, archs, pie), + Ignore: generateIgnored(goos, archs, pie), } } @@ -158,14 +162,11 @@ func Build(dist string, buildOrRest bool, pie bool) config.Build { Goos: goos, Goarch: archs, Goarm: ArmVersions(dist), - Ignore: IgnoreBuildCombinations(dist), + Ignore: generateIgnored(goos, archs, pie), } } -func generateIgnored(dist string, goos, archs []string, pie bool) []config.IgnoredBuild { - if dist == K8sDistro { - return nil - } +func generateIgnored(goos, archs []string, pie bool) []config.IgnoredBuild { ignored := make([]config.IgnoredBuild, 0) var build config.IgnoredBuild for _, goos := range goos { diff --git a/distributions/otelcol-contrib/.goreleaser-build.yaml b/distributions/otelcol-contrib/.goreleaser-build.yaml index b5f60c0d..a622f3aa 100644 --- a/distributions/otelcol-contrib/.goreleaser-build.yaml +++ b/distributions/otelcol-contrib/.goreleaser-build.yaml @@ -3,6 +3,53 @@ partial: version: 2 project_name: opentelemetry-collector-releases builds: + - id: otelcol-contrib-pie + goos: + - darwin + - linux + - windows + goarch: + - "386" + - amd64 + - arm + - arm64 + - ppc64le + - s390x + goarm: + - "7" + ignore: + - goos: darwin + goarch: "386" + - goos: darwin + goarch: arm + - goos: darwin + goarch: ppc64le + - goos: darwin + goarch: s390x + - goos: linux + goarch: "386" + - goos: linux + goarch: arm + - goos: linux + goarch: s390x + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 + - goos: windows + goarch: ppc64le + - goos: windows + goarch: s390x + dir: _build + binary: otelcol-contrib + ldflags: + - -s + - -w + - -buildmode=pie + flags: + - -trimpath + env: + - CGO_ENABLED=0 - id: otelcol-contrib goos: - darwin @@ -20,10 +67,24 @@ builds: ignore: - goos: darwin goarch: "386" + - goos: darwin + goarch: amd64 - goos: darwin goarch: arm + - goos: darwin + goarch: arm64 - goos: darwin goarch: s390x + - goos: linux + goarch: amd64 + - goos: linux + goarch: arm64 + - goos: linux + goarch: ppc64le + - goos: windows + goarch: "386" + - goos: windows + goarch: amd64 - goos: windows goarch: arm - goos: windows diff --git a/distributions/otelcol-contrib/.goreleaser.yaml b/distributions/otelcol-contrib/.goreleaser.yaml index f1229d29..e9b9d611 100644 --- a/distributions/otelcol-contrib/.goreleaser.yaml +++ b/distributions/otelcol-contrib/.goreleaser.yaml @@ -51,14 +51,9 @@ builds: goarch: s390x dir: _build binary: otelcol-contrib - ldflags: - - -s - - -w - - -buildmode=pie - flags: - - -trimpath - env: - - CGO_ENABLED=0 + builder: prebuilt + prebuilt: + path: artifacts/otelcol-contrib-pie_{{ .Target }}/otelcol-contrib{{- if eq .Os "windows" }}.exe{{ end }} - id: otelcol-contrib goos: - darwin From d48178e9ee09e293ad3204d2929c5301a5856351 Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Mon, 16 Dec 2024 12:56:03 +0100 Subject: [PATCH 4/8] trigger build From f46b86c5e36688ea261538015983ce61f28344b4 Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Mon, 16 Dec 2024 13:08:17 +0100 Subject: [PATCH 5/8] downgrade ubuntu version back to 22.04 Signed-off-by: Moritz Wiesinger --- .github/workflows/base-package-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/base-package-tests.yaml b/.github/workflows/base-package-tests.yaml index 57d10102..a58179e8 100644 --- a/.github/workflows/base-package-tests.yaml +++ b/.github/workflows/base-package-tests.yaml @@ -13,7 +13,7 @@ on: jobs: package-tests: name: Package Tests - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: type: ${{ fromJSON(inputs.type) }} From f0cfc667116bc861773fcb625986a4f3d08c99fd Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Wed, 18 Dec 2024 16:21:49 +0100 Subject: [PATCH 6/8] try to restore state before rebase Signed-off-by: Moritz Wiesinger --- cmd/goreleaser/internal/configure.go | 93 +++++-------------- .../otelcol-contrib/.goreleaser-build.yaml | 61 ------------ .../otelcol-contrib/.goreleaser.yaml | 61 ------------ distributions/otelcol-k8s/.goreleaser.yaml | 32 ------- distributions/otelcol-otlp/.goreleaser.yaml | 66 ------------- distributions/otelcol/.goreleaser.yaml | 66 ------------- 6 files changed, 25 insertions(+), 354 deletions(-) diff --git a/cmd/goreleaser/internal/configure.go b/cmd/goreleaser/internal/configure.go index 2f57dd44..75281bdb 100644 --- a/cmd/goreleaser/internal/configure.go +++ b/cmd/goreleaser/internal/configure.go @@ -47,29 +47,8 @@ var ( K8sDockerSkipArchs = map[string]bool{"arm": true, "386": true} K8sGoos = []string{"linux"} K8sArchs = []string{"amd64", "arm64", "ppc64le", "s390x"} - AlwaysIgnored = map[config.IgnoredBuild]bool{ - {Goos: "darwin", Goarch: "386"}: true, - {Goos: "darwin", Goarch: "arm"}: true, - {Goos: "darwin", Goarch: "s390x"}: true, - {Goos: "windows", Goarch: "arm"}: true, - {Goos: "windows", Goarch: "arm64"}: true, - {Goos: "windows", Goarch: "s390x"}: true, - } ) -// Copied from go/src/internal/platform/supported.go, see: -// https://cs.opensource.google/go/go/+/d7fcb5cf80953f1d63246f1ae9defa60c5ce2d76:src/internal/platform/supported.go;l=222 -func InternalLinkPIESupported(goos, goarch string) bool { - switch goos + "/" + goarch { - case "android/arm64", - "darwin/amd64", "darwin/arm64", - "linux/amd64", "linux/arm64", "linux/ppc64le", - "windows/386", "windows/amd64", "windows/arm", "windows/arm64": - return true - } - return false -} - func GenerateContribBuildOnly(dist string, buildOrRest bool) config.Project { return config.Project{ ProjectName: "opentelemetry-collector-releases", @@ -106,42 +85,31 @@ func Generate(dist string, buildOrRest bool) config.Project { func Builds(dist string, buildOrRest bool) []config.Build { return []config.Build{ - Build(dist, buildOrRest, true), - Build(dist, buildOrRest, false), + Build(dist, buildOrRest), } } // Build configures a goreleaser build. // https://goreleaser.com/customization/build/ -func Build(dist string, buildOrRest bool, pie bool) config.Build { +func Build(dist string, buildOrRest bool) config.Build { goos := []string{"darwin", "linux", "windows"} archs := Architectures - id := dist - ldflags := []string{"-s", "-w"} - var prebuiltPath string - - if pie { - ldflags = append(ldflags, "-buildmode=pie") - id = id + "-pie" - prebuiltPath = fmt.Sprintf("artifacts/otelcol-contrib%s_{{ .Target }}/otelcol-contrib{{- if eq .Os \"windows\" }}.exe{{ end }}", "-pie") - } else { - prebuiltPath = "artifacts/otelcol-contrib_{{ .Target }}/otelcol-contrib{{- if eq .Os \"windows\" }}.exe{{ end }}" - } if dist == ContribDistro && !buildOrRest { // only return build config for contrib build file return config.Build{ - ID: id, + ID: dist, Builder: "prebuilt", PreBuilt: config.PreBuiltOptions{ - Path: prebuiltPath, + Path: "artifacts/otelcol-contrib_{{ .Target }}" + + "/otelcol-contrib{{- if eq .Os \"windows\" }}.exe{{ end }}", }, Goos: goos, Goarch: archs, Goarm: ArmVersions(dist), Dir: "_build", Binary: dist, - Ignore: generateIgnored(goos, archs, pie), + Ignore: IgnoreBuildCombinations(dist), } } @@ -151,36 +119,33 @@ func Build(dist string, buildOrRest bool, pie bool) config.Build { } return config.Build{ - ID: id, + ID: dist, Dir: "_build", Binary: dist, BuildDetails: config.BuildDetails{ Env: []string{"CGO_ENABLED=0"}, Flags: []string{"-trimpath"}, - Ldflags: ldflags, + Ldflags: []string{"-s", "-w"}, }, Goos: goos, Goarch: archs, Goarm: ArmVersions(dist), - Ignore: generateIgnored(goos, archs, pie), + Ignore: IgnoreBuildCombinations(dist), } } -func generateIgnored(goos, archs []string, pie bool) []config.IgnoredBuild { - ignored := make([]config.IgnoredBuild, 0) - var build config.IgnoredBuild - for _, goos := range goos { - for _, arch := range archs { - build = config.IgnoredBuild{ - Goos: goos, - Goarch: arch, - } - if _, ok := AlwaysIgnored[build]; ok || !pie && InternalLinkPIESupported(goos, arch) || pie && !InternalLinkPIESupported(goos, arch) { - ignored = append(ignored, build) - } - } +func IgnoreBuildCombinations(dist string) []config.IgnoredBuild { + if dist == K8sDistro { + return nil + } + return []config.IgnoredBuild{ + {Goos: "darwin", Goarch: "386"}, + {Goos: "darwin", Goarch: "arm"}, + {Goos: "darwin", Goarch: "s390x"}, + {Goos: "windows", Goarch: "arm"}, + {Goos: "windows", Goarch: "arm64"}, + {Goos: "windows", Goarch: "s390x"}, } - return ignored } func ArmVersions(dist string) []string { @@ -192,24 +157,17 @@ func ArmVersions(dist string) []string { func Archives(dist string) []config.Archive { return []config.Archive{ - Archive(dist, true), - Archive(dist, false), + Archive(dist), } } // Archive configures a goreleaser archive (tarball). // https://goreleaser.com/customization/archive/ -func Archive(dist string, pie bool) config.Archive { - id := dist - build := dist - if pie { - id = id + "-pie" - build = build + "-pie" - } +func Archive(dist string) config.Archive { return config.Archive{ - ID: id, + ID: dist, NameTemplate: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}", - Builds: []string{build}, + Builds: []string{dist}, } } @@ -249,7 +207,6 @@ func Packages(dist string) []config.NFPM { // Package configures goreleaser to build a system package. // https://goreleaser.com/customization/nfpm/ func Package(dist string) config.NFPM { - buildPie := dist + "-pie" nfpmContents := config.NFPMContents{ { Source: fmt.Sprintf("%s.service", dist), @@ -270,7 +227,7 @@ func Package(dist string) config.NFPM { } return config.NFPM{ ID: dist, - Builds: []string{dist, buildPie}, + Builds: []string{dist}, Formats: []string{"deb", "rpm"}, License: "Apache 2.0", Description: fmt.Sprintf("OpenTelemetry Collector - %s", dist), diff --git a/distributions/otelcol-contrib/.goreleaser-build.yaml b/distributions/otelcol-contrib/.goreleaser-build.yaml index a622f3aa..b5f60c0d 100644 --- a/distributions/otelcol-contrib/.goreleaser-build.yaml +++ b/distributions/otelcol-contrib/.goreleaser-build.yaml @@ -3,53 +3,6 @@ partial: version: 2 project_name: opentelemetry-collector-releases builds: - - id: otelcol-contrib-pie - goos: - - darwin - - linux - - windows - goarch: - - "386" - - amd64 - - arm - - arm64 - - ppc64le - - s390x - goarm: - - "7" - ignore: - - goos: darwin - goarch: "386" - - goos: darwin - goarch: arm - - goos: darwin - goarch: ppc64le - - goos: darwin - goarch: s390x - - goos: linux - goarch: "386" - - goos: linux - goarch: arm - - goos: linux - goarch: s390x - - goos: windows - goarch: arm - - goos: windows - goarch: arm64 - - goos: windows - goarch: ppc64le - - goos: windows - goarch: s390x - dir: _build - binary: otelcol-contrib - ldflags: - - -s - - -w - - -buildmode=pie - flags: - - -trimpath - env: - - CGO_ENABLED=0 - id: otelcol-contrib goos: - darwin @@ -67,24 +20,10 @@ builds: ignore: - goos: darwin goarch: "386" - - goos: darwin - goarch: amd64 - goos: darwin goarch: arm - - goos: darwin - goarch: arm64 - goos: darwin goarch: s390x - - goos: linux - goarch: amd64 - - goos: linux - goarch: arm64 - - goos: linux - goarch: ppc64le - - goos: windows - goarch: "386" - - goos: windows - goarch: amd64 - goos: windows goarch: arm - goos: windows diff --git a/distributions/otelcol-contrib/.goreleaser.yaml b/distributions/otelcol-contrib/.goreleaser.yaml index e9b9d611..6323ebea 100644 --- a/distributions/otelcol-contrib/.goreleaser.yaml +++ b/distributions/otelcol-contrib/.goreleaser.yaml @@ -12,48 +12,6 @@ msi: - opentelemetry.ico - config.yaml builds: - - id: otelcol-contrib-pie - goos: - - darwin - - linux - - windows - goarch: - - "386" - - amd64 - - arm - - arm64 - - ppc64le - - s390x - goarm: - - "7" - ignore: - - goos: darwin - goarch: "386" - - goos: darwin - goarch: arm - - goos: darwin - goarch: ppc64le - - goos: darwin - goarch: s390x - - goos: linux - goarch: "386" - - goos: linux - goarch: arm - - goos: linux - goarch: s390x - - goos: windows - goarch: arm - - goos: windows - goarch: arm64 - - goos: windows - goarch: ppc64le - - goos: windows - goarch: s390x - dir: _build - binary: otelcol-contrib - builder: prebuilt - prebuilt: - path: artifacts/otelcol-contrib-pie_{{ .Target }}/otelcol-contrib{{- if eq .Os "windows" }}.exe{{ end }} - id: otelcol-contrib goos: - darwin @@ -71,24 +29,10 @@ builds: ignore: - goos: darwin goarch: "386" - - goos: darwin - goarch: amd64 - goos: darwin goarch: arm - - goos: darwin - goarch: arm64 - goos: darwin goarch: s390x - - goos: linux - goarch: amd64 - - goos: linux - goarch: arm64 - - goos: linux - goarch: ppc64le - - goos: windows - goarch: "386" - - goos: windows - goarch: amd64 - goos: windows goarch: arm - goos: windows @@ -101,10 +45,6 @@ builds: prebuilt: path: artifacts/otelcol-contrib_{{ .Target }}/otelcol-contrib{{- if eq .Os "windows" }}.exe{{ end }} archives: - - id: otelcol-contrib-pie - builds: - - otelcol-contrib-pie - name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}' - id: otelcol-contrib builds: - otelcol-contrib @@ -131,7 +71,6 @@ nfpms: id: otelcol-contrib builds: - otelcol-contrib - - otelcol-contrib-pie formats: - deb - rpm diff --git a/distributions/otelcol-k8s/.goreleaser.yaml b/distributions/otelcol-k8s/.goreleaser.yaml index 12725579..9ff03c57 100644 --- a/distributions/otelcol-k8s/.goreleaser.yaml +++ b/distributions/otelcol-k8s/.goreleaser.yaml @@ -5,27 +5,6 @@ project_name: opentelemetry-collector-releases env: - COSIGN_YES=true builds: - - id: otelcol-k8s-pie - goos: - - linux - goarch: - - amd64 - - arm64 - - ppc64le - - s390x - ignore: - - goos: linux - goarch: s390x - dir: _build - binary: otelcol-k8s - ldflags: - - -s - - -w - - -buildmode=pie - flags: - - -trimpath - env: - - CGO_ENABLED=0 - id: otelcol-k8s goos: - linux @@ -34,13 +13,6 @@ builds: - arm64 - ppc64le - s390x - ignore: - - goos: linux - goarch: amd64 - - goos: linux - goarch: arm64 - - goos: linux - goarch: ppc64le dir: _build binary: otelcol-k8s ldflags: @@ -51,10 +23,6 @@ builds: env: - CGO_ENABLED=0 archives: - - id: otelcol-k8s-pie - builds: - - otelcol-k8s-pie - name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}' - id: otelcol-k8s builds: - otelcol-k8s diff --git a/distributions/otelcol-otlp/.goreleaser.yaml b/distributions/otelcol-otlp/.goreleaser.yaml index d2ee1022..a1e9681c 100644 --- a/distributions/otelcol-otlp/.goreleaser.yaml +++ b/distributions/otelcol-otlp/.goreleaser.yaml @@ -11,53 +11,6 @@ msi: extra_files: - opentelemetry.ico builds: - - id: otelcol-otlp-pie - goos: - - darwin - - linux - - windows - goarch: - - "386" - - amd64 - - arm - - arm64 - - ppc64le - - s390x - goarm: - - "7" - ignore: - - goos: darwin - goarch: "386" - - goos: darwin - goarch: arm - - goos: darwin - goarch: ppc64le - - goos: darwin - goarch: s390x - - goos: linux - goarch: "386" - - goos: linux - goarch: arm - - goos: linux - goarch: s390x - - goos: windows - goarch: arm - - goos: windows - goarch: arm64 - - goos: windows - goarch: ppc64le - - goos: windows - goarch: s390x - dir: _build - binary: otelcol-otlp - ldflags: - - -s - - -w - - -buildmode=pie - flags: - - -trimpath - env: - - CGO_ENABLED=0 - id: otelcol-otlp goos: - darwin @@ -75,24 +28,10 @@ builds: ignore: - goos: darwin goarch: "386" - - goos: darwin - goarch: amd64 - goos: darwin goarch: arm - - goos: darwin - goarch: arm64 - goos: darwin goarch: s390x - - goos: linux - goarch: amd64 - - goos: linux - goarch: arm64 - - goos: linux - goarch: ppc64le - - goos: windows - goarch: "386" - - goos: windows - goarch: amd64 - goos: windows goarch: arm - goos: windows @@ -109,10 +48,6 @@ builds: env: - CGO_ENABLED=0 archives: - - id: otelcol-otlp-pie - builds: - - otelcol-otlp-pie - name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}' - id: otelcol-otlp builds: - otelcol-otlp @@ -136,7 +71,6 @@ nfpms: id: otelcol-otlp builds: - otelcol-otlp - - otelcol-otlp-pie formats: - deb - rpm diff --git a/distributions/otelcol/.goreleaser.yaml b/distributions/otelcol/.goreleaser.yaml index 5be5f72f..ec3b4132 100644 --- a/distributions/otelcol/.goreleaser.yaml +++ b/distributions/otelcol/.goreleaser.yaml @@ -12,53 +12,6 @@ msi: - opentelemetry.ico - config.yaml builds: - - id: otelcol-pie - goos: - - darwin - - linux - - windows - goarch: - - "386" - - amd64 - - arm - - arm64 - - ppc64le - - s390x - goarm: - - "7" - ignore: - - goos: darwin - goarch: "386" - - goos: darwin - goarch: arm - - goos: darwin - goarch: ppc64le - - goos: darwin - goarch: s390x - - goos: linux - goarch: "386" - - goos: linux - goarch: arm - - goos: linux - goarch: s390x - - goos: windows - goarch: arm - - goos: windows - goarch: arm64 - - goos: windows - goarch: ppc64le - - goos: windows - goarch: s390x - dir: _build - binary: otelcol - ldflags: - - -s - - -w - - -buildmode=pie - flags: - - -trimpath - env: - - CGO_ENABLED=0 - id: otelcol goos: - darwin @@ -76,24 +29,10 @@ builds: ignore: - goos: darwin goarch: "386" - - goos: darwin - goarch: amd64 - goos: darwin goarch: arm - - goos: darwin - goarch: arm64 - goos: darwin goarch: s390x - - goos: linux - goarch: amd64 - - goos: linux - goarch: arm64 - - goos: linux - goarch: ppc64le - - goos: windows - goarch: "386" - - goos: windows - goarch: amd64 - goos: windows goarch: arm - goos: windows @@ -110,10 +49,6 @@ builds: env: - CGO_ENABLED=0 archives: - - id: otelcol-pie - builds: - - otelcol-pie - name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}' - id: otelcol builds: - otelcol @@ -140,7 +75,6 @@ nfpms: id: otelcol builds: - otelcol - - otelcol-pie formats: - deb - rpm From f3868d6b97b02dde8e27bc468d1d0e5e46cd2d3b Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Wed, 18 Dec 2024 16:33:54 +0100 Subject: [PATCH 7/8] run tests to ensure that everything works Signed-off-by: Moritz Wiesinger --- .github/workflows/package-test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/package-test.yaml b/.github/workflows/package-test.yaml index b0ab6cfc..674cc662 100644 --- a/.github/workflows/package-test.yaml +++ b/.github/workflows/package-test.yaml @@ -1,6 +1,8 @@ name: Package Tests - Contrib on: + pull_request: + branches: [main] schedule: - cron: "0 2 * * *" # every day at 2am UTC From 853c1725948a163f6fd5b2a2098bf83852f03556 Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Wed, 18 Dec 2024 16:38:31 +0100 Subject: [PATCH 8/8] revert after successful testing Signed-off-by: Moritz Wiesinger --- .github/workflows/package-test.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/package-test.yaml b/.github/workflows/package-test.yaml index 674cc662..b0ab6cfc 100644 --- a/.github/workflows/package-test.yaml +++ b/.github/workflows/package-test.yaml @@ -1,8 +1,6 @@ name: Package Tests - Contrib on: - pull_request: - branches: [main] schedule: - cron: "0 2 * * *" # every day at 2am UTC