internal/common: introduce git revision and rpm version
The variables are set to the git revision from which the build is triggered and rpm version from the spec file, if it is build using RPM. This can be later used to query exact source version while running osbuild-composer. It is necessary to use both, because none of them is available in all possible scenarios. Use either git-rev (preferably) or RPM version (NEVRA) instead of the "devel" build type. It was just a placeholder.
This commit is contained in:
parent
c8032c7bbc
commit
d7d4e02c8c
3 changed files with 36 additions and 1 deletions
27
internal/common/constants.go
Normal file
27
internal/common/constants.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package common
|
||||
|
||||
import "fmt"
|
||||
|
||||
// These constants are set during buildtime using additional
|
||||
// compiler flags. Not all of them are necessarily defined
|
||||
// because RPMs can be build from a tarball and spec file without
|
||||
// being in a git repository. On the other hand when building
|
||||
// composer inside of a container, there is no RPM layer so in
|
||||
// that case the RPM version doesn't exist at all.
|
||||
var (
|
||||
// Git revision from which this code was built
|
||||
GitRev = "undefined"
|
||||
|
||||
// RPM Version
|
||||
RpmVersion = "undefined"
|
||||
)
|
||||
|
||||
func BuildVersion() string {
|
||||
if GitRev != "undefined" {
|
||||
return fmt.Sprintf("git-rev:%s", GitRev)
|
||||
} else if RpmVersion != "undefined" {
|
||||
return fmt.Sprintf("NEVRA:%s", RpmVersion)
|
||||
} else {
|
||||
return "devel"
|
||||
}
|
||||
}
|
||||
|
|
@ -561,7 +561,7 @@ func (api *API) statusHandler(writer http.ResponseWriter, request *http.Request,
|
|||
DBVersion: "0",
|
||||
SchemaVersion: "0",
|
||||
Backend: "osbuild-composer",
|
||||
Build: "devel",
|
||||
Build: common.BuildVersion(),
|
||||
Messages: make([]string, 0),
|
||||
})
|
||||
common.PanicOnError(err)
|
||||
|
|
|
|||
|
|
@ -124,6 +124,14 @@ export GOPATH=$GO_BUILD_PATH:%{gopath}
|
|||
export GOFLAGS=-mod=vendor
|
||||
%endif
|
||||
|
||||
# Set the commit hash so that composer can report what source version
|
||||
# was used to build it. This has to be set explicitly when calling rpmbuild,
|
||||
# this script will not attempt to automatically discover it.
|
||||
%if %{?commit:1}0
|
||||
export LDFLAGS="${LDFLAGS} -X 'github.com/osbuild/osbuild-composer/internal/common.GitRev=%{commit}'"
|
||||
%endif
|
||||
export LDFLAGS="${LDFLAGS} -X 'github.com/osbuild/osbuild-composer/internal/common.RpmVersion=%{name}-%{epoch}:%{version}-%{release}.%{_arch}'"
|
||||
|
||||
%gobuild -o _bin/osbuild-composer %{goipath}/cmd/osbuild-composer
|
||||
%gobuild -o _bin/osbuild-worker %{goipath}/cmd/osbuild-worker
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue