Add build system and version info
This commit is contained in:
parent
9146db7952
commit
c799a79c2e
|
@ -0,0 +1,2 @@
|
||||||
|
*~
|
||||||
|
*.bak
|
|
@ -1,2 +1,4 @@
|
||||||
*~
|
*~*
|
||||||
*.bak
|
*.bak
|
||||||
|
cmd/msgbus/msgbus
|
||||||
|
cmd/msgbusd/msgbusd
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Build
|
||||||
|
FROM golang:alpine AS build
|
||||||
|
|
||||||
|
ARG TAG
|
||||||
|
ARG BUILD
|
||||||
|
|
||||||
|
ENV LIBRARY msgbus
|
||||||
|
ENV SERVER msgbusd
|
||||||
|
ENV CLIENT msgbus
|
||||||
|
ENV REPO prologic/$LIBRARY
|
||||||
|
|
||||||
|
RUN apk add --update git make build-base && \
|
||||||
|
rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
WORKDIR /go/src/github.com/$REPO
|
||||||
|
COPY . /go/src/github.com/$REPO
|
||||||
|
RUN make TAG=$TAG BUILD=$BUILD build
|
||||||
|
|
||||||
|
# Runtime
|
||||||
|
FROM scratch
|
||||||
|
|
||||||
|
ENV LIBRARY msgbud
|
||||||
|
ENV SERVER msgbusd
|
||||||
|
ENV CLIENT msgbus
|
||||||
|
ENV REPO prologic/$LIBRARY
|
||||||
|
|
||||||
|
LABEL msgbud.app main
|
||||||
|
|
||||||
|
COPY --from=build /go/src/github.com/${REPO}/cmd/${SERVER}/${SERVER} /${SERVER}
|
||||||
|
COPY --from=build /go/src/github.com/${REPO}/cmd/${CLIENT}/${CLIENT} /${CLIENT}
|
||||||
|
|
||||||
|
EXPOSE 8000/tcp
|
||||||
|
|
||||||
|
ENTRYPOINT ["/msgbusd"]
|
||||||
|
CMD []
|
|
@ -0,0 +1,44 @@
|
||||||
|
.PHONY: dev build image test deps clean
|
||||||
|
|
||||||
|
CGO_ENABLED=0
|
||||||
|
COMMIT=`git rev-parse --short HEAD`
|
||||||
|
LIBRARY=msgbus
|
||||||
|
SERVER=msgbusd
|
||||||
|
CLIENT=msgbus
|
||||||
|
REPO?=prologic/$(LIBRARY)
|
||||||
|
TAG?=latest
|
||||||
|
BUILD?=-dev
|
||||||
|
|
||||||
|
BUILD_TAGS="netgo static_build"
|
||||||
|
BUILD_LDFLAGS="-w -X github.com/$(REPO).GitCommit=$(COMMIT) -X github.com/$(REPO)/Build=$(BUILD)"
|
||||||
|
|
||||||
|
all: dev
|
||||||
|
|
||||||
|
dev: build
|
||||||
|
@./cmd/$(SERVER)/$(SERVER)
|
||||||
|
|
||||||
|
deps:
|
||||||
|
@go get ./...
|
||||||
|
|
||||||
|
build: clean deps
|
||||||
|
@echo " -> Building $(SERVER) $(TAG)$(BUILD) ..."
|
||||||
|
@cd cmd/$(SERVER) && \
|
||||||
|
go build -tags $(BUILD_TAGS) -installsuffix netgo \
|
||||||
|
-ldflags $(BUILD_LDFLAGS) .
|
||||||
|
@echo "Built $$(./cmd/$(SERVER)/$(SERVER) -v)"
|
||||||
|
@echo
|
||||||
|
@echo " -> Building $(CLIENT) $(TAG)$(BUILD) ..."
|
||||||
|
@cd cmd/$(CLIENT) && \
|
||||||
|
go build -tags $(BUILD_TAGS) -installsuffix netgo \
|
||||||
|
-ldflags $(BUILD_LDFLAGS) .
|
||||||
|
@echo "Built $$(./cmd/$(CLIENT)/$(CLIENT) -v)"
|
||||||
|
|
||||||
|
image:
|
||||||
|
@docker build --build-arg TAG=$(TAG) --build-arg BUILD=$(BUILD) -t $(REPO):$(TAG) .
|
||||||
|
@echo "Image created: $(REPO):$(TAG)"
|
||||||
|
|
||||||
|
test:
|
||||||
|
@go test -v -cover -race $(TEST_ARGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -rf $(APP)
|
|
@ -7,14 +7,17 @@ import (
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"github.com/prologic/msgbus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configFile string
|
var configFile string
|
||||||
|
|
||||||
// RootCmd represents the base command when called without any subcommands
|
// RootCmd represents the base command when called without any subcommands
|
||||||
var RootCmd = &cobra.Command{
|
var RootCmd = &cobra.Command{
|
||||||
Use: "msgbus",
|
Use: "msgbus",
|
||||||
Short: "Command-line client for msgbus",
|
Version: msgbus.FullVersion(),
|
||||||
|
Short: "Command-line client for msgbus",
|
||||||
Long: `This is the command-line client for the msgbus daemon msgbusd.
|
Long: `This is the command-line client for the msgbus daemon msgbusd.
|
||||||
|
|
||||||
This lets you publish, subscribe and pull messages from a running msgbusd
|
This lets you publish, subscribe and pull messages from a running msgbusd
|
||||||
|
|
|
@ -2,26 +2,37 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prologic/msgbus"
|
"github.com/prologic/msgbus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
func main() {
|
||||||
bind string
|
|
||||||
ttl time.Duration
|
var (
|
||||||
)
|
version bool
|
||||||
|
bind string
|
||||||
|
ttl time.Duration
|
||||||
|
)
|
||||||
|
|
||||||
|
flag.BoolVar(&version, "v", false, "display version information")
|
||||||
|
|
||||||
func init() {
|
|
||||||
flag.StringVar(&bind, "bind", ":8000", "interface and port to bind to")
|
flag.StringVar(&bind, "bind", ":8000", "interface and port to bind to")
|
||||||
flag.DurationVar(&ttl, "ttl", 60*time.Second, "default ttl")
|
flag.DurationVar(&ttl, "ttl", 60*time.Second, "default ttl")
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
flag.Parse()
|
||||||
|
|
||||||
|
if version {
|
||||||
|
fmt.Printf(msgbus.FullVersion())
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
options := msgbus.Options{DefaultTTL: ttl}
|
options := msgbus.Options{DefaultTTL: ttl}
|
||||||
http.Handle("/", msgbus.NewMessageBus(&options))
|
http.Handle("/", msgbus.NewMessageBus(&options))
|
||||||
log.Printf("msgbusd listening on %s", bind)
|
log.Printf("%s listening on %s", msgbus.Package, bind)
|
||||||
log.Fatal(http.ListenAndServe(bind, nil))
|
log.Fatal(http.ListenAndServe(bind, nil))
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package msgbus
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
//Package package name
|
||||||
|
Package = "msgbus"
|
||||||
|
|
||||||
|
// Version release version
|
||||||
|
Version = "0.1.0"
|
||||||
|
|
||||||
|
// Build will be overwritten automatically by the build system
|
||||||
|
Build = "dev"
|
||||||
|
|
||||||
|
// GitCommit will be overwritten automatically by the build system
|
||||||
|
GitCommit = "HEAD"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FullVersion display the full version, build and commit hash
|
||||||
|
func FullVersion() string {
|
||||||
|
return fmt.Sprintf("%s-%s-%s@%s", Package, Version, Build, GitCommit)
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package msgbus
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFullVersion(t *testing.T) {
|
||||||
|
version := FullVersion()
|
||||||
|
|
||||||
|
expected := Version + Build + " (" + GitCommit + ")"
|
||||||
|
|
||||||
|
if version != expected {
|
||||||
|
t.Fatalf("invalid version returned: %s", version)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue