Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add version flag #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
TIMESTAMP = $(shell date +"%Y%m%d%H%M%S")
BRANCH = $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
COMMIT = $(shell git rev-parse HEAD)
VERSION = $(shell git describe --tags)
LDFLAGSPREFIX = github.com/AliyunContainerService/image-syncer/pkg/utils
LDFLAGS = "-X $(LDFLAGSPREFIX).Version=$(VERSION) -X $(LDFLAGSPREFIX).Branch=$(BRANCH) -X $(LDFLAGSPREFIX).Commit=$(COMMIT) -X $(LDFLAGSPREFIX).Timestamp=$(TIMESTAMP)"
.PHONY: cmd clean

cmd: $(wildcard ./pkg/client/*.go ./pkg/sync/*.go ./pkg/tools/*.go ./cmd/*.go ./*.go)
go build -o image-syncer ./main.go
go build -ldflags $(LDFLAGS) -o image-syncer ./main.go

clean:
rm image-syncer
11 changes: 10 additions & 1 deletion cmd/image-syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (

osFilterList, archFilterList []string

forceUpdate bool
forceUpdate, version bool
)

// RootCmd describes "image-syncer" command
Expand All @@ -31,6 +31,14 @@ var RootCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceErrors = true

if version {
fmt.Println("app-version: ", utils.Version)
fmt.Println("git-branch: ", utils.Branch)
fmt.Println("git-commit: ", utils.Commit)
fmt.Println("build-timestamp: ", utils.Timestamp)
return nil
}

// work starts here
client, err := client.NewSyncClient(configFile, authFile, imagesFile, logPath, successImagesFile, outputImagesFormat,
procNum, retries, utils.RemoveEmptyItems(osFilterList), utils.RemoveEmptyItems(archFilterList), forceUpdate)
Expand All @@ -55,6 +63,7 @@ func init() {
RootCmd.PersistentFlags().BoolVar(&forceUpdate, "force", false, "force update manifest whether the destination manifest exists")
RootCmd.PersistentFlags().StringVar(&successImagesFile, "output-success-images", "", "output success images in a new file")
RootCmd.PersistentFlags().StringVar(&outputImagesFormat, "output-images-format", "yaml", "success images output format, json or yaml")
RootCmd.PersistentFlags().BoolVar(&version, "version", false, "print app version")
}

// Execute executes the RootCmd
Expand Down
8 changes: 8 additions & 0 deletions pkg/utils/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package utils

var (
Version = "v0.1.0"
Branch = ""
Commit = ""
Timestamp = ""
)