From 65c1a1f4b372589760407b4028f21c695dac07880538da6c93a68ae7f3fbb047 Mon Sep 17 00:00:00 2001 From: Witek Bedyk Date: Thu, 17 Aug 2023 15:14:57 +0000 Subject: [PATCH] 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 --- ...er_user_host_for_reproducible_builds.patch | 74 +++++++++++++++++++ golang-github-prometheus-promu.changes | 7 ++ golang-github-prometheus-promu.spec | 7 +- vendor.tar.gz | 4 +- 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 0001-do_not_discover_user_host_for_reproducible_builds.patch diff --git a/0001-do_not_discover_user_host_for_reproducible_builds.patch b/0001-do_not_discover_user_host_for_reproducible_builds.patch new file mode 100644 index 0000000..fb57518 --- /dev/null +++ b/0001-do_not_discover_user_host_for_reproducible_builds.patch @@ -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. diff --git a/golang-github-prometheus-promu.changes b/golang-github-prometheus-promu.changes index 8ea9a86..6d3bead 100644 --- a/golang-github-prometheus-promu.changes +++ b/golang-github-prometheus-promu.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Tue Aug 8 11:53:00 UTC 2023 - Witek Bedyk + +- 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 diff --git a/golang-github-prometheus-promu.spec b/golang-github-prometheus-promu.spec index 40e3659..5656e26 100644 --- a/golang-github-prometheus-promu.spec +++ b/golang-github-prometheus-promu.spec @@ -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 diff --git a/vendor.tar.gz b/vendor.tar.gz index def0ea2..183e3c1 100644 --- a/vendor.tar.gz +++ b/vendor.tar.gz @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ba8f21bf9db61392c4d9fe4bab4c995155ae0b6cf893d572afffb04fef15db45 -size 1961663 +oid sha256:d01b7ba3c525d28e851655e78029a2cd3d89079995765a66ee3a3559c93fa9d4 +size 1961604