Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GoReleaser templating to support all collector distros #708

Merged
merged 9 commits into from
Nov 7, 2024
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ OTELCOL_BUILDER_DIR ?= ${HOME}/bin
OTELCOL_BUILDER ?= ${OTELCOL_BUILDER_DIR}/ocb

DISTRIBUTIONS ?= "otelcol,otelcol-contrib,otelcol-k8s,otelcol-otlp"
GEN_CONFIG_DISTRIBUTIONS ?= "otelcol,otelcol-contrib"

ci: check build
check: ensure-goreleaser-up-to-date
Expand All @@ -17,7 +16,7 @@ build: go ocb
generate: generate-sources generate-goreleaser

generate-goreleaser: go
@./scripts/generate-goreleaser.sh -d "${GEN_CONFIG_DISTRIBUTIONS}" -g ${GO}
@./scripts/generate-goreleaser.sh -d "${DISTRIBUTIONS}" -g ${GO}

generate-sources: go ocb
@./scripts/build.sh -d "${DISTRIBUTIONS}" -s true -b ${OTELCOL_BUILDER} -g ${GO}
Expand Down
2 changes: 1 addition & 1 deletion cmd/builder/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ sboms:
artifacts: archive
- id: package
artifacts: package


126 changes: 85 additions & 41 deletions cmd/goreleaser/internal/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ import (
const ArmArch = "arm"

var (
ImagePrefixes = []string{"otel", "ghcr.io/open-telemetry/opentelemetry-collector-releases"}
Architectures = []string{"386", "amd64", "arm", "arm64", "ppc64le", "s390x"}
ArmVersions = []string{"7"}
ImagePrefixes = []string{"otel", "ghcr.io/open-telemetry/opentelemetry-collector-releases"}
Architectures = []string{"386", "amd64", "arm", "arm64", "ppc64le", "s390x"}
ArmVersions = []string{"7"}
DefaultConfigDists = map[string]bool{"otelcol": true, "otelcol-contrib": true}
MSIWindowsDists = map[string]bool{"otelcol": true, "otelcol-contrib": true, "otelcol-otlp": true}
jackgopack4 marked this conversation as resolved.
Show resolved Hide resolved
K8sDockerSkipArchs = map[string]bool{"arm": true, "386": true}
K8sGoos = []string{"linux"}
K8sArchs = []string{"amd64", "arm64", "ppc64le", "s390x"}
)

func Generate(dist string) config.Project {
Expand Down Expand Up @@ -67,26 +72,42 @@ func Builds(dist string) []config.Build {
// Build configures a goreleaser build.
// https://goreleaser.com/customization/build/
func Build(dist string) config.Build {
var goos []string
var archs []string
var ignore []config.IgnoredBuild
var armVersions []string
flags := []string{"-trimpath"}
if dist == "otelcol-k8s" {
jackgopack4 marked this conversation as resolved.
Show resolved Hide resolved
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,
Dir: "_build",
Binary: dist,
BuildDetails: config.BuildDetails{
Env: []string{"CGO_ENABLED=0"},
Flags: []string{"-trimpath"},
Flags: flags,
jackgopack4 marked this conversation as resolved.
Show resolved Hide resolved
Ldflags: []string{"-s", "-w"},
},
Goos: []string{"darwin", "linux", "windows"},
Goarch: Architectures,
Goarm: ArmVersions,
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"},
},
Goos: goos,
Goarch: archs,
Goarm: armVersions,
Ignore: ignore,
}
}

Expand All @@ -107,6 +128,9 @@ func Archive(dist string) config.Archive {
}

func WinPackages(dist string) []config.MSI {
if _, ok := MSIWindowsDists[dist]; !ok {
return []config.MSI{}
}
return []config.MSI{
WinPackage(dist),
}
Expand All @@ -115,18 +139,22 @@ func WinPackages(dist string) []config.MSI {
// Package configures goreleaser to build a Windows MSI package.
// https://goreleaser.com/customization/msi/
func WinPackage(dist string) config.MSI {
files := []string{"opentelemetry.ico"}
if _, ok := DefaultConfigDists[dist]; ok {
files = append(files, "config.yaml")
}
return config.MSI{
ID: dist,
Name: fmt.Sprintf("%s_{{ .Version }}_{{ .Os }}_{{ .MsiArch }}", dist),
WXS: "windows-installer.wxs",
Files: []string{
"config.yaml",
"opentelemetry.ico",
},
ID: dist,
Name: fmt.Sprintf("%s_{{ .Version }}_{{ .Os }}_{{ .MsiArch }}", dist),
WXS: "windows-installer.wxs",
Files: files,
}
}

func Packages(dist string) (r []config.NFPM) {
if dist == "otelcol-k8s" {
return []config.NFPM{}
}
return []config.NFPM{
Package(dist),
}
Expand All @@ -135,6 +163,24 @@ func Packages(dist string) (r []config.NFPM) {
// Package configures goreleaser to build a system package.
// https://goreleaser.com/customization/nfpm/
func Package(dist string) config.NFPM {
nfpmContents := config.NFPMContents{
{
Source: fmt.Sprintf("%s.service", dist),
Destination: path.Join("/lib", "systemd", "system", fmt.Sprintf("%s.service", dist)),
},
{
Source: fmt.Sprintf("%s.conf", dist),
Destination: path.Join("/etc", dist, fmt.Sprintf("%s.conf", dist)),
Type: "config|noreplace",
},
}
if _, ok := DefaultConfigDists[dist]; ok {
nfpmContents = append(nfpmContents, &config.NFPMContent{
Source: "config.yaml",
Destination: path.Join("/etc", dist, "config.yaml"),
Type: "config|noreplace",
})
}
return config.NFPM{
ID: dist,
Builds: []string{dist},
Expand All @@ -158,29 +204,19 @@ func Package(dist string) config.NFPM {
PostInstall: "postinstall.sh",
PreRemove: "preremove.sh",
},
Contents: config.NFPMContents{
{
Source: fmt.Sprintf("%s.service", dist),
Destination: path.Join("/lib", "systemd", "system", fmt.Sprintf("%s.service", dist)),
},
{
Source: fmt.Sprintf("%s.conf", dist),
Destination: path.Join("/etc", dist, fmt.Sprintf("%s.conf", dist)),
Type: "config|noreplace",
},
{
Source: "config.yaml",
Destination: path.Join("/etc", dist, "config.yaml"),
Type: "config|noreplace",
},
},
Contents: nfpmContents,
},
}
}

func DockerImages(dist string) []config.Docker {
r := make([]config.Docker, 0)
for _, arch := range Architectures {
if dist == "otelcol-k8s" {
if _, ok := K8sDockerSkipArchs[arch]; ok {
continue
}
}
switch arch {
case ArmArch:
for _, vers := range ArmVersions {
Expand All @@ -197,7 +233,7 @@ func DockerImages(dist string) []config.Docker {
// https://goreleaser.com/customization/docker/
func DockerImage(dist, arch, armVersion string) config.Docker {
dockerArchName := archName(arch, armVersion)
var imageTemplates []string
imageTemplates := make([]string, 0)
for _, prefix := range ImagePrefixes {
dockerArchTag := strings.ReplaceAll(dockerArchName, "/", "")
imageTemplates = append(
Expand All @@ -210,7 +246,10 @@ func DockerImage(dist, arch, armVersion string) config.Docker {
label := func(name, template string) string {
return fmt.Sprintf("--label=org.opencontainers.image.%s={{%s}}", name, template)
}

files := make([]string, 0)
if _, ok := DefaultConfigDists[dist]; ok {
files = append(files, "config.yaml")
}
return config.Docker{
ImageTemplates: imageTemplates,
Dockerfile: "Dockerfile",
Expand All @@ -226,7 +265,7 @@ func DockerImage(dist, arch, armVersion string) config.Docker {
label("source", ".GitURL"),
"--label=org.opencontainers.image.licenses=Apache-2.0",
},
Files: []string{"config.yaml"},
Files: files,
Goos: "linux",
Goarch: arch,
Goarm: armVersion,
Expand All @@ -247,6 +286,11 @@ func DockerManifests(dist string) []config.DockerManifest {
func DockerManifest(prefix, version, dist string) config.DockerManifest {
var imageTemplates []string
for _, arch := range Architectures {
if dist == "otelcol-k8s" {
if _, ok := K8sDockerSkipArchs[arch]; ok {
continue
}
}
switch arch {
case ArmArch:
for _, armVers := range ArmVersions {
Expand Down
2 changes: 1 addition & 1 deletion distributions/otelcol-contrib/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ msi:
name: otelcol-contrib_{{ .Version }}_{{ .Os }}_{{ .MsiArch }}
wxs: windows-installer.wxs
extra_files:
- config.yaml
- opentelemetry.ico
- config.yaml
builds:
- id: otelcol-contrib
goos:
Expand Down
4 changes: 2 additions & 2 deletions distributions/otelcol-k8s/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
partial:
by: target
version: 2
monorepo:
tag_prefix: v
project_name: opentelemetry-collector-releases
env:
- COSIGN_YES=true
Expand Down Expand Up @@ -151,3 +149,5 @@ sboms:
artifacts: archive
- id: package
artifacts: package
monorepo:
tag_prefix: v
2 changes: 1 addition & 1 deletion distributions/otelcol/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ msi:
name: otelcol_{{ .Version }}_{{ .Os }}_{{ .MsiArch }}
wxs: windows-installer.wxs
extra_files:
- config.yaml
- opentelemetry.ico
- config.yaml
builds:
- id: otelcol
goos:
Expand Down