Merge pull request #110 from hasIan/add_version_tag
Add SHA and build date metadata to Truss binary
This commit is contained in:
Коммит
5cecfb2704
5
Makefile
5
Makefile
|
@ -1,5 +1,8 @@
|
|||
# Makefile for Truss.
|
||||
#
|
||||
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S_%Z')
|
||||
SHA := $(shell git rev-parse --short=10 HEAD)
|
||||
|
||||
# Build native Truss by default.
|
||||
default: truss
|
||||
|
||||
|
@ -20,7 +23,7 @@ gobindata:
|
|||
# Install truss and protoc-gen-truss-protocast
|
||||
truss: gobindata
|
||||
go install github.com/TuneLab/go-truss/cmd/protoc-gen-truss-protocast
|
||||
go install github.com/TuneLab/go-truss/cmd/truss
|
||||
go install -ldflags "-X main.Version=$(SHA) -X main.BuildDate=$(BUILD_DATE)" github.com/TuneLab/go-truss/cmd/truss
|
||||
|
||||
# Run the go tests and the truss integration tests
|
||||
test: test-go test-integration
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
# truss
|
||||
|
||||
The `truss` binary reads in gRPC files that define a single gRPC *service* and outputs:
|
||||
`truss` reads gRPC files that define a single gRPC service and outputs the following:
|
||||
|
||||
1. Markdown and html documentation based on comments in the gRPC files.
|
||||
2. Golang code for a gokit microservice that includes:
|
||||
- Logging
|
||||
- Metrics/Instrumentation
|
||||
1. Markdown and HTML documentation based on comments in the gRPC files.
|
||||
2. Golang code for a [Go Kit](http://gokit.io) microservice that includes the following:
|
||||
- gRPC transport
|
||||
- http/json transport (including all encoding/decoding)
|
||||
- no-op handler methods for each *service* rpc, ready for business logic to be added
|
||||
3. Golang code for a cli gokit microservice client that includes:
|
||||
- HTTP/JSON transport (including all encoding/decoding)
|
||||
- no-op handler methods for each service RPC, ready for business logic to be added
|
||||
3. Golang code for a CLI Go Kit microservice client that includes the following:
|
||||
- gRPC transport
|
||||
- http/json transport (including all encoding/decoding)
|
||||
- no-op handler methods for each *service* rpc, ready for marshalling command line arguments into a request object
|
||||
4. An web based api explorer (through naive swagger generation)
|
||||
- HTTP/JSON transport (including all encoding/decoding)
|
||||
- no-op handler methods for each service RPC, ready for marshalling command line
|
||||
arguments into a request object and sending a request to a server
|
||||
4. An web based API explorer (through naive Swagger generation)
|
||||
|
||||
|
|
|
@ -24,22 +24,45 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
pbPackageFlag = flag.String("pbout", "", "The go package path where the protoc-gen-go .pb.go structs will be written.")
|
||||
svcPackageFlag = flag.String("svcout", "", "The go package path where the generated service directory will be written.")
|
||||
verboseFlag = flag.Bool("v", false, "Verbose output with stack traces for errors.")
|
||||
pbPackageFlag = flag.String("pbout", "", "Go package path where the protoc-gen-go .pb.go files will be written")
|
||||
svcPackageFlag = flag.String("svcout", "", "Go package path where the generated Go service will be written")
|
||||
verboseFlag = flag.Bool("v", false, "verbose output")
|
||||
)
|
||||
|
||||
var binName = filepath.Base(os.Args[0])
|
||||
|
||||
const (
|
||||
noVersion string = "<no-version>"
|
||||
noBuildDate string = "<no-build-date>"
|
||||
)
|
||||
|
||||
var (
|
||||
Version string = noVersion
|
||||
BuildDate string = noBuildDate
|
||||
)
|
||||
|
||||
func init() {
|
||||
var buildinfo string
|
||||
if Version != "" && Version != noVersion {
|
||||
buildinfo = fmt.Sprintf("version: %s", Version)
|
||||
}
|
||||
if BuildDate != "" && BuildDate != noBuildDate {
|
||||
buildinfo = fmt.Sprintf("%s built: %s", buildinfo, strings.Replace(BuildDate, "_", " ", -1))
|
||||
}
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [*.proto]...\n", filepath.Base(os.Args[0]))
|
||||
if buildinfo != "" {
|
||||
fmt.Fprintf(os.Stderr, "%s (%s)\n", binName, strings.TrimSpace(buildinfo))
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS] protofile [protofile2...protofileN]\n", binName)
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if len(flag.Args()) == 0 {
|
||||
fmt.Fprintf(os.Stderr, "%s: missing .proto file(s)\n", filepath.Base(os.Args[0]))
|
||||
fmt.Fprintf(os.Stderr, "Try '%s --help' for more information.\n", filepath.Base(os.Args[0]))
|
||||
fmt.Fprintf(os.Stderr, "%s: missing .proto file(s)\n", binName)
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -117,7 +140,7 @@ func parseInput() (*truss.Config, error) {
|
|||
return nil, err
|
||||
}
|
||||
if p.Root == "" {
|
||||
return nil, errors.New("svcout not in gopath GOPATH")
|
||||
return nil, errors.New("svcout not in GOPATH")
|
||||
}
|
||||
if !fileExists(p.Dir) {
|
||||
return nil, errors.Errorf("specified package path for service output directory does not exist: %q", p.Dir)
|
||||
|
|
Загрузка…
Ссылка в новой задаче