From 01969bff441d97146d32b5c5ffb4ad12b0602afe Mon Sep 17 00:00:00 2001 From: Richard Hagen Date: Tue, 12 Mar 2024 10:00:53 +0100 Subject: [PATCH] Easy RX CLI Install (#87) * move main and read build info * set version * tweaks * Tweak readme --- .gitignore | 4 ++-- .goreleaser.yml | 2 ++ Dockerfile | 2 +- README.md | 7 ++++++- main.go => cli/rx/main.go | 0 cmd/root.go | 10 ++++++++++ 6 files changed, 21 insertions(+), 4 deletions(-) rename main.go => cli/rx/main.go (100%) diff --git a/.gitignore b/.gitignore index 2715449..c551b29 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ /vendor/* debug radix-cli -rx -rx-test +/rx +/rx-test .idea/ .dccache diff --git a/.goreleaser.yml b/.goreleaser.yml index ca7f169..73e4265 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -3,6 +3,8 @@ builds: - id: rx binary: rx + main: ./cli/rx + env: - CGO_ENABLED=0 goos: diff --git a/Dockerfile b/Dockerfile index d571037..859dcde 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ COPY . /app RUN addgroup -S -g 1000 radix && adduser -S -u 1000 -G radix radix # Build -RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -a -installsuffix cgo -o ./rootfs/rx +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -a -installsuffix cgo -o ./rootfs/rx ./cli/rx ## Run operator FROM scratch diff --git a/README.md b/README.md index 1fb1cf3..022b74b 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ Radix CLI in the [Radix documentation](https://radix.equinor.com/docs/topic-radi ## Installation +### If using Go: +```sh +go install github.com/equinor/radix-cli/cli/rx@latest +``` + ### Linux or Mac #### Binaries @@ -166,7 +171,7 @@ We are making releases available as GitHub releases using [go-releaser](https:// To generate a local version for debugging purposes, it can be built using: ``` -CGO_ENABLED=0 GOOS=darwin go build -ldflags "-s -w" -a -installsuffix cgo -o ./rx +CGO_ENABLED=0 GOOS=darwin go build -ldflags "-s -w" -a -installsuffix cgo -o ./rx ./cli/rx ``` ### Security diff --git a/main.go b/cli/rx/main.go similarity index 100% rename from main.go rename to cli/rx/main.go diff --git a/cmd/root.go b/cmd/root.go index 48bd7d2..4e01cca 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "runtime/debug" "strings" "time" @@ -38,6 +39,15 @@ func Execute() { } } +func init() { + if Version == "dev" { + if info, ok := debug.ReadBuildInfo(); ok { + Version = info.Main.Version + rootCmd.Version = info.Main.Version + } + } +} + func setVerbosePersistentFlag(cmd *cobra.Command) *bool { return cmd.PersistentFlags().Bool(flagnames.Verbose, false, "Verbose output") }