DRY ldflags; include build time into version string (#541)
This commit is contained in:
parent
706caa44bf
commit
af79994595
17
Makefile
17
Makefile
@ -4,6 +4,8 @@ BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n')
|
|||||||
GO_VERSION = $(shell go version | awk {'print $$3'})
|
GO_VERSION = $(shell go version | awk {'print $$3'})
|
||||||
DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')"
|
DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')"
|
||||||
DOCKER_LATEST_TAG = "sosedoff/pgweb:latest"
|
DOCKER_LATEST_TAG = "sosedoff/pgweb:latest"
|
||||||
|
LDFLAGS = -s -w
|
||||||
|
PKG = github.com/sosedoff/pgweb
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
@echo ""
|
@echo ""
|
||||||
@ -37,22 +39,21 @@ build:
|
|||||||
go build
|
go build
|
||||||
@echo "You can now execute ./pgweb"
|
@echo "You can now execute ./pgweb"
|
||||||
|
|
||||||
|
release: LDFLAGS += -X $(PKG)/pkg/command.GitCommit=$(GIT_COMMIT)
|
||||||
|
release: LDFLAGS += -X $(PKG)/pkg/command.BuildTime=$(BUILD_TIME)
|
||||||
|
release: LDFLAGS += -X $(PKG)/pkg/command.GoVersion=$(GO_VERSION)
|
||||||
release:
|
release:
|
||||||
@echo "Building binaries..."
|
@echo "Building binaries..."
|
||||||
@gox \
|
@gox \
|
||||||
-osarch "$(TARGETS)" \
|
-osarch "$(TARGETS)" \
|
||||||
-ldflags "-s -w -X github.com/sosedoff/pgweb/pkg/command.GitCommit=$(GIT_COMMIT) -X github.com/sosedoff/pgweb/pkg/command.BuildTime=$(BUILD_TIME) -X github.com/sosedoff/pgweb/pkg/command.GoVersion=$(GO_VERSION)" \
|
-ldflags "$(LDFLAGS)" \
|
||||||
-output "./bin/pgweb_{{.OS}}_{{.Arch}}"
|
-output "./bin/pgweb_{{.OS}}_{{.Arch}}"
|
||||||
|
|
||||||
@echo "Building ARM binaries..."
|
@echo "Building ARM binaries..."
|
||||||
GOOS=linux GOARCH=arm GOARM=5 go build \
|
GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "$(LDFLAGS)" -o "./bin/pgweb_linux_arm_v5"
|
||||||
-ldflags "-s -w -X github.com/sosedoff/pgweb/pkg/command.GitCommit=$(GIT_COMMIT) -X github.com/sosedoff/pgweb/pkg/command.BuildTime=$(BUILD_TIME) -X github.com/sosedoff/pgweb/pkg/command.GoVersion=$(GO_VERSION)" \
|
|
||||||
-o "./bin/pgweb_linux_arm_v5"
|
|
||||||
|
|
||||||
@echo "Building ARM64 binaries..."
|
@echo "Building ARM64 binaries..."
|
||||||
GOOS=linux GOARCH=arm64 GOARM=7 go build \
|
GOOS=linux GOARCH=arm64 GOARM=7 go build -ldflags "$(LDFLAGS)" -o "./bin/pgweb_linux_arm64_v7"
|
||||||
-ldflags "-s -w -X github.com/sosedoff/pgweb/pkg/command.GitCommit=$(GIT_COMMIT) -X github.com/sosedoff/pgweb/pkg/command.BuildTime=$(BUILD_TIME) -X github.com/sosedoff/pgweb/pkg/command.GoVersion=$(GO_VERSION)" \
|
|
||||||
-o "./bin/pgweb_linux_arm64_v7"
|
|
||||||
|
|
||||||
@echo "\nPackaging binaries...\n"
|
@echo "\nPackaging binaries...\n"
|
||||||
@./script/package.sh
|
@./script/package.sh
|
||||||
@ -77,4 +78,4 @@ docker-release:
|
|||||||
|
|
||||||
docker-push:
|
docker-push:
|
||||||
docker push $(DOCKER_RELEASE_TAG)
|
docker push $(DOCKER_RELEASE_TAG)
|
||||||
docker push $(DOCKER_LATEST_TAG)
|
docker push $(DOCKER_LATEST_TAG)
|
||||||
|
@ -161,12 +161,19 @@ func initOptions() {
|
|||||||
|
|
||||||
func printVersion() {
|
func printVersion() {
|
||||||
chunks := []string{fmt.Sprintf("Pgweb v%s", command.Version)}
|
chunks := []string{fmt.Sprintf("Pgweb v%s", command.Version)}
|
||||||
|
|
||||||
if command.GitCommit != "" {
|
if command.GitCommit != "" {
|
||||||
chunks = append(chunks, fmt.Sprintf("(git: %s)", command.GitCommit))
|
chunks = append(chunks, fmt.Sprintf("(git: %s)", command.GitCommit))
|
||||||
}
|
}
|
||||||
|
|
||||||
if command.GoVersion != "" {
|
if command.GoVersion != "" {
|
||||||
chunks = append(chunks, fmt.Sprintf("(go: %s)", command.GoVersion))
|
chunks = append(chunks, fmt.Sprintf("(go: %s)", command.GoVersion))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if command.BuildTime != "" {
|
||||||
|
chunks = append(chunks, fmt.Sprintf("(build time: %s)", command.BuildTime))
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(strings.Join(chunks, " "))
|
fmt.Println(strings.Join(chunks, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user