Skip to content

Commit ccf133c

Browse files
authored
Merge pull request #25 from hlts2/fix/set-driver-version-info
Set driver version in the binary based on release version
2 parents 3d6898a + 639b13f commit ccf133c

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN go mod verify
1717
RUN find .
1818

1919
# Build the binary.
20-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s -X github.com/civo/civo-csi/driver.CSIVersion=${VERSION}" -o /app/civo-csi
20+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s -X github.com/civo/civo-csi/pkg/driver.Version=${VERSION}" -o /app/civo-csi
2121

2222

2323
############################

main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"flag"
56
"os"
67
"os/signal"
78
"strings"
@@ -13,10 +14,20 @@ import (
1314
"github.com/rs/zerolog/log"
1415
)
1516

17+
var (
18+
versionInfo = flag.Bool("version", false, "Print the driver version")
19+
)
20+
1621
func main() {
1722
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
1823
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
1924

25+
flag.Parse()
26+
if *versionInfo {
27+
log.Info().Str("version", driver.Version).Msg("CSI driver")
28+
return
29+
}
30+
2031
apiURL := strings.TrimSpace(os.Getenv("CIVO_API_URL"))
2132
apiKey := strings.TrimSpace(os.Getenv("CIVO_API_KEY"))
2233
region := strings.TrimSpace(os.Getenv("CIVO_REGION"))

pkg/driver/driver.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ import (
1717
"google.golang.org/grpc"
1818
)
1919

20-
// CSIVersion is the version of the csi to set in the User-Agent header
21-
var CSIVersion = "dev"
22-
2320
// Name is the name of the driver
2421
const Name string = "Civo CSI Driver"
2522

26-
// Version is the current release of the driver
27-
const Version string = "0.0.1"
23+
// Version is the current version of the driver to set in the User-Agent header
24+
var Version string = "0.0.1"
2825

2926
// DefaultVolumeSizeGB is the default size in Gigabytes of an unspecified volume
3027
const DefaultVolumeSizeGB int = 10

0 commit comments

Comments
 (0)