Skip to content

Commit

Permalink
start with adding goreleaser generation code
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Wiesinger <[email protected]>
  • Loading branch information
mowies committed Nov 14, 2024
1 parent 94281a6 commit 5e445b5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
54 changes: 36 additions & 18 deletions cmd/goreleaser/internal/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,24 @@ 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}
K8sGoos = []string{"linux"}
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",
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion cmd/goreleaser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,29 @@ 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()

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{
Expand Down
4 changes: 4 additions & 0 deletions scripts/generate-goreleaser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5e445b5

Please sign in to comment.