From 5e445b56420f0f1c4687c86873349dd5861c51ff Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Thu, 14 Nov 2024 12:57:05 +0100 Subject: [PATCH] start with adding goreleaser generation code Signed-off-by: Moritz Wiesinger --- cmd/goreleaser/internal/configure.go | 54 ++++++++++++++++++---------- cmd/goreleaser/main.go | 10 +++++- scripts/generate-goreleaser.sh | 4 +++ 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/cmd/goreleaser/internal/configure.go b/cmd/goreleaser/internal/configure.go index 32741f16..15030a1a 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} @@ -50,6 +49,17 @@ var ( K8sArchs = []string{"amd64", "arm64", "ppc64le", "s390x"} ) +func GenerateContribBuildOnly(dist string) config.Project { + return config.Project{ + ProjectName: "opentelemetry-collector-releases", + Builds: Builds(dist), + Version: 2, + Monorepo: config.Monorepo{ + TagPrefix: "v", + }, + } +} + func Generate(dist string) config.Project { return config.Project{ ProjectName: "opentelemetry-collector-releases", @@ -84,25 +94,12 @@ func Builds(dist string) []config.Build { func Build(dist string) config.Build { var goos []string var archs []string - var ignore []config.IgnoredBuild - var armVersions []string if dist == K8sDistro { goos = K8sGoos archs = K8sArchs - ignore = make([]config.IgnoredBuild, 0) - armVersions = make([]string, 0) } else { goos = []string{"darwin", "linux", "windows"} archs = Architectures - ignore = []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"}, - } - armVersions = ArmVersions } return config.Build{ ID: dist, @@ -115,9 +112,30 @@ func Build(dist string) config.Build { }, Goos: goos, Goarch: archs, - Goarm: armVersions, - Ignore: ignore, + Goarm: ArmVersions(dist), + Ignore: IgnoreBuildCombinations(dist), + } +} + +func IgnoreBuildCombinations(dist string) []config.IgnoredBuild { + if dist == K8sDistro { + return make([]config.IgnoredBuild, 0) + } + 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"}, + } +} + +func ArmVersions(dist string) []string { + if dist == K8sDistro { + return make([]string, 0) } + return []string{"7"} } func Archives(dist string) (r []config.Archive) { @@ -228,7 +246,7 @@ func DockerImages(dist string) []config.Docker { } switch arch { case ArmArch: - for _, vers := range ArmVersions { + for _, vers := range ArmVersions(dist) { r = append(r, DockerImage(dist, arch, vers)) } default: @@ -302,7 +320,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..e9735b00 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("b", false, "Collector Contrib distribution only - switch between build and package config file - set to true to generate build step, false to generate pacakge 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) + } else { + project = internal.Generate(*distFlag) + } partial := map[string]any{ "partial": map[string]any{ diff --git a/scripts/generate-goreleaser.sh b/scripts/generate-goreleaser.sh index 7b6c7ae7..91144359 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}" -b > "./distributions/${distribution}/.goreleaser-build.yaml" + fi + ${GO} run cmd/goreleaser/main.go -d "${distribution}" > "./distributions/${distribution}/.goreleaser.yaml" done