Accepting request 1103279 from home:witekbedyk:branches:server:monitoring

- Add 0001-do_not_discover_user_host_for_reproducible_builds.patch
- Require Go >= 1.19 for building
- Require Go >= 1.18 for building Red Hat packages

OBS-URL: https://build.opensuse.org/request/show/1103279
OBS-URL: https://build.opensuse.org/package/show/server:monitoring/golang-github-prometheus-promu?expand=0&rev=32
This commit is contained in:
Witek Bedyk 2023-08-17 15:14:57 +00:00 committed by Git OBS Bridge
parent eb52279fd6
commit 65c1a1f4b3
4 changed files with 88 additions and 4 deletions

View File

@ -0,0 +1,74 @@
Index: promu-0.15.0/cmd/build.go
===================================================================
--- promu-0.15.0.orig/cmd/build.go
+++ promu-0.15.0/cmd/build.go
@@ -32,6 +32,10 @@ import (
"github.com/prometheus/promu/util/sh"
)
+const (
+ sourceDateEpoch = "SOURCE_DATE_EPOCH"
+)
+
var (
buildcmd = app.Command("build", "Build a Go project")
buildCgoFlagSet bool
@@ -155,7 +159,7 @@ func getLdflags(info repository.Info) st
tmplOutput = new(bytes.Buffer)
fnMap = template.FuncMap{
"date": buildDate.UTC().Format,
- "host": os.Hostname,
+ "host": HostFunc,
"repoPath": RepoPathFunc,
"user": UserFunc,
}
@@ -191,13 +195,13 @@ func getLdflags(info repository.Info) st
func getBuildDate() time.Time {
var buildDate time.Time
- sourceDate := os.Getenv("SOURCE_DATE_EPOCH")
+ sourceDate := os.Getenv(sourceDateEpoch)
if sourceDate == "" {
buildDate = time.Now()
} else {
unixBuildDate, err := strconv.ParseInt(sourceDate, 10, 64)
if err != nil {
- fatal(errors.Wrap(err, "Failed to parse SOURCE_DATE_EPOCH"))
+ fatal(errors.Wrap(err, "Failed to parse "+sourceDateEpoch))
} else {
buildDate = time.Unix(unixBuildDate, 0)
}
@@ -205,10 +209,31 @@ func getBuildDate() time.Time {
return buildDate
}
+func HostFunc() string {
+ if isReproducibleBuild() {
+ return "reproducible"
+ } else {
+ hostname, err := os.Hostname()
+ if err != nil {
+ return "unknown-host"
+ } else {
+ return hostname
+ }
+ }
+}
+
// UserFunc returns the current username.
func UserFunc() (interface{}, error) {
- // os/user.Current() doesn't always work without CGO
- return shellOutput("whoami"), nil
+ if isReproducibleBuild() {
+ return "reproducible", nil
+ } else {
+ // os/user.Current() doesn't always work without CGO
+ return shellOutput("whoami"), nil
+ }
+}
+
+func isReproducibleBuild() bool {
+ return os.Getenv(sourceDateEpoch) != ""
}
// RepoPathFunc returns the repository path.

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Aug 8 11:53:00 UTC 2023 - Witek Bedyk <witold.bedyk@suse.com>
- Add 0001-do_not_discover_user_host_for_reproducible_builds.patch
- Require Go >= 1.19 for building
- Require Go >= 1.18 for building Red Hat packages
-------------------------------------------------------------------
Tue Jul 04 10:41:07 UTC 2023 - kastl@b1-systems.de

View File

@ -25,15 +25,18 @@ Group: System/Management
URL: https://github.com/prometheus/promu
Source: promu-%{version}.tar.gz
Source1: vendor.tar.gz
# PATCH-FIX-UPSTREAM Fix setting reproducible user and host during the build
# https://github.com/prometheus/promu/pull/267
Patch1: 0001-do_not_discover_user_host_for_reproducible_builds.patch
BuildRequires: golang-packaging
ExcludeArch: s390
%{go_provides}
%if 0%{?rhel}
# Fix ERROR: No build ID note found in
%undefine _missing_build_ids_terminate_build
BuildRequires: golang >= 1.17
BuildRequires: golang >= 1.18
%else
BuildRequires: golang(API) = 1.18
BuildRequires: golang(API) >= 1.19
%endif
%description

BIN
vendor.tar.gz (Stored with Git LFS)

Binary file not shown.