This repository was archived by the owner on May 24, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +7
-5
lines changed Expand file tree Collapse file tree 3 files changed +7
-5
lines changed Original file line number Diff line number Diff line change 1
1
# Build the manager binary
2
2
FROM golang:1.16 as builder
3
+ ARG VERSION
3
4
4
5
WORKDIR /workspace
5
6
# Copy the Go Modules manifests
@@ -15,7 +16,7 @@ COPY api/ api/
15
16
COPY controllers/ controllers/
16
17
17
18
# Build
18
- RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
19
+ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" - a -o manager main.go
19
20
20
21
# Use distroless as minimal base image to package the manager binary
21
22
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Original file line number Diff line number Diff line change @@ -94,13 +94,13 @@ test: manifests generate fmt vet ## Run tests.
94
94
# #@ Build
95
95
96
96
build : generate fmt vet # # Build manager binary.
97
- go build -o bin/manager main.go
97
+ go build -ldflags " -X main.version= ${VERSION} " - o bin/manager main.go
98
98
99
99
run : manifests generate fmt vet # # Run a controller from your host.
100
- go run ./main.go $(ARGS )
100
+ go run -ldflags " -X main.version= ${VERSION} " ./main.go $(ARGS )
101
101
102
102
docker-build : test # # Build docker image with the manager.
103
- docker build -t ${IMG} .
103
+ docker build -t ${IMG} . --build-arg VERSION= ${VERSION}
104
104
105
105
docker-push : # # Push docker image with the manager.
106
106
docker push ${IMG}
Original file line number Diff line number Diff line change @@ -45,10 +45,11 @@ import (
45
45
var (
46
46
scheme = runtime .NewScheme ()
47
47
setupLog = ctrl .Log .WithName ("setup" )
48
+ version string
48
49
)
49
50
50
51
func printVersion () {
51
- // log .Info(fmt.Sprintf("Operator Version: %s", version.Version ))
52
+ setupLog .Info (fmt .Sprintf ("Operator Version: %s" , version ))
52
53
setupLog .Info (fmt .Sprintf ("Go Version: %s" , runt .Version ()))
53
54
setupLog .Info (fmt .Sprintf ("Go OS/Arch: %s/%s" , runt .GOOS , runt .GOARCH ))
54
55
setupLog .Info (fmt .Sprintf ("Version of kubernetes: %v" , controllers .RunningK8sVersion ))
You can’t perform that action at this time.
0 commit comments