File tree Expand file tree Collapse file tree 4 files changed +33
-6
lines changed
Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Original file line number Diff line number Diff line change 1212# Build the preflight binary
1313COPY . /go/src/preflight-trigger
1414WORKDIR /go/src/preflight-trigger
15- RUN make build
15+ RUN make build RELEASE_TAG=${release_tag}
1616
1717
1818FROM registry.access.redhat.com/ubi9/ubi-micro:latest
Original file line number Diff line number Diff line change @@ -8,12 +8,13 @@ export CONTAINER_ENGINE ?= podman
88export BIN_NAME
99export REGISTRY ?= quay.io
1010export REGISTRY_NAMESPACE ?= opdev
11+ VERSION =$(shell git rev-parse HEAD)
1112export RELEASE_TAG ?= "0.0.0"
1213
1314
1415.PHONY : binary-build
1516binary-build :
16- $(CONTAINER_ENGINE ) run --rm -v $(PWD ) :/usr/src/$(BIN_NAME ) -w /usr/src/$(BIN_NAME ) -e GOOS=linux -e GOARCH=amd64 docker.io/library/golang:alpine go build -o $(BIN_NAME )
17+ $(CONTAINER_ENGINE ) run --rm -v $(PWD ) :/usr/src/$(BIN_NAME ) -w /usr/src/$(BIN_NAME ) -e GOOS=linux -e GOARCH=amd64 docker.io/library/golang:alpine go build -ldflags " -X github.com/redhat-openshift-ecosystem/preflight-trigger/cmd.commit= $( VERSION ) -X github.com/redhat-openshift-ecosystem/preflight-trigger/cmd.version= $( RELEASE_TAG ) " - o $(BIN_NAME )
1718
1819.PHONY : image-build
1920image-build :
@@ -25,7 +26,7 @@ image-push:
2526
2627.PHONY : build
2728build :
28- CGO_ENABLED=0 go build -o $(BIN_NAME ) main.go
29+ CGO_ENABLED=0 go build -ldflags " -X github.com/redhat-openshift-ecosystem/preflight-trigger/cmd.commit= $( VERSION ) -X github.com/redhat-openshift-ecosystem/preflight-trigger/cmd.version= $( RELEASE_TAG ) " - o $(BIN_NAME ) main.go
2930 @ls | grep -e ' ^preflight-trigger$$' & > /dev/null
3031
3132.PHONY : vet
Original file line number Diff line number Diff line change @@ -58,9 +58,10 @@ var CommandFlags FlagsData
5858
5959// rootCmd represents the base command when called without any subcommands
6060var rootCmd = & cobra.Command {
61- Use : "preflight-trigger" ,
62- Short : "Create on-demand preflight jobs in openshift-ci system" ,
63- Long : `` ,
61+ Use : "preflight-trigger" ,
62+ Short : "Create on-demand preflight jobs in openshift-ci system" ,
63+ Long : `` ,
64+ Version : Version .String (),
6465}
6566
6667// Execute adds all child commands to the root command and sets flags appropriately.
Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import "fmt"
4+
5+ var (
6+ projectName = "github.com/redhat-openshift-ecosystem/preflight-trigger"
7+ version = "unknown"
8+ commit = "unknown"
9+ )
10+
11+ var Version = VersionContext {
12+ Name : projectName ,
13+ Version : version ,
14+ Commit : commit ,
15+ }
16+
17+ type VersionContext struct {
18+ Name string `json:"name"`
19+ Version string `json:"version"`
20+ Commit string `json:"commit"`
21+ }
22+
23+ func (vc * VersionContext ) String () string {
24+ return fmt .Sprintf ("%s <commit: %s>" , vc .Version , vc .Commit )
25+ }
You can’t perform that action at this time.
0 commit comments