Skip to content

Commit

Permalink
update: ldflags for version and build information, update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ybelMekk committed Sep 7, 2021
1 parent 82397f6 commit cc12415
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ builds:
dir: .
main: ./main/debuk
binary: debuk
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
checksum:
name_template: 'checksums.txt'
changelog:
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local:
go build -o tool/debuk main/debuk/*.go
debuk:
go install main/debuk/debuk.go
go install main/debuk/debuk.go
test:
go test ./... -count=1
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,17 @@ KAFKA_SCHEMA_REGISTRY_PASSWORD:password
## Local Development

* Be sure to run your local cluster, use: [minkube](https://minikube.sigs.k8s.io/docs/start/)
* Create local test cluster
* Create a `test` cluster

```
kubectl create n test
```

* Create fake a secret
```
kubectl apply -f path/to/secret
```

```
make test
make debuk
```
13 changes: 12 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (

var (
VERSION string
COMMIT string
DATE string
BUILT_BY string

rootCmd = &cobra.Command{
Use: "debuk [COMMANDS] [FLAGS]",
Expand All @@ -19,8 +22,11 @@ This application is a tool to generate the needed files to quickly start debuggi
}
)

func Execute(version string) {
func Execute(version, commit, date, builtBy string) {
VERSION = version
COMMIT = commit
DATE = date
BUILT_BY = builtBy

if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
Expand All @@ -35,6 +41,8 @@ const (
ExpireFlag = "expire"
PoolFlag = "pool"
SecretNameFlag = "secret-name"

CommitInformation = "commit"
)

func init() {
Expand All @@ -58,6 +66,9 @@ func init() {
applyCommand.Flags().StringP(SecretNameFlag, "s", "", "Preferred secret-name instead of generated (optional)")
viper.BindPFlag(SecretNameFlag, applyCommand.Flags().Lookup(SecretNameFlag))

versionCmd.Flags().BoolP(CommitInformation, "i", false, "Detailed commit information for this debuk version (optional)")
viper.BindPFlag(CommitInformation, versionCmd.Flags().Lookup(DestFlag))

rootCmd.AddCommand(applyCommand)
rootCmd.AddCommand(versionCmd)
}
Expand Down
14 changes: 12 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ import (
var versionCmd = &cobra.Command{
Use: "version",
Short: "Show debuk client version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(cmd.Use + " " + VERSION)
RunE: func(cmd *cobra.Command, args []string) error {
result, err := cmd.Flags().GetBool(CommitInformation)
if err != nil {
return err
}

if result {
fmt.Printf("%s: %s commit: %s date: %s builtBy: %s", cmd.Use, VERSION, COMMIT, DATE, BUILT_BY)
} else {
fmt.Printf("%s: %s", cmd.Use, VERSION)
}
return nil
},
}
2 changes: 1 addition & 1 deletion doc/debuk.puml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ group Time limit exceeded
aivenator -> kubernetes : Delete Secret
kubernetes -> aivenator : AivenApplication Secret resource deleted
aivenator -> aiven : Delete serviceuser and credentials
aivenator -> aivenator : Annotate aivenApplication for deletion
aivenator -> aivenator : Annotate aivenApplication scheduled for deletion
aivenator -> kubernetes : Delete aivenApplication
end
end
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ module github.com/nais/debuk
go 1.17

require (
github.com/nais/liberator v0.0.0-20210825131439-d28ee52da1a0
github.com/nais/liberator v0.0.0-20210907092402-a4e20461546a
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/text v0.3.5 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/ini.v1 v1.63.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
9 changes: 6 additions & 3 deletions main/debuk/debuk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package main
import "github.com/nais/debuk/cmd"

var (
// VERSION is set during build
VERSION = "v0.1"
// Is set during build
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)

func main() {
cmd.Execute(VERSION)
cmd.Execute(version, commit, date, builtBy)
}

0 comments on commit cc12415

Please sign in to comment.