-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tamal Saha <[email protected]>
- Loading branch information
Showing
56 changed files
with
2,544 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
SHELL=/bin/bash -o pipefail | ||
|
||
# The binary to build (just the basename). | ||
BIN := kubedb | ||
COMPRESS ?= no | ||
|
||
# This version-strategy uses git tags to set the version string | ||
git_branch := $(shell git rev-parse --abbrev-ref HEAD) | ||
git_tag := $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "") | ||
commit_hash := $(shell git rev-parse --verify HEAD) | ||
commit_timestamp := $(shell date --date="@$$(git show -s --format=%ct)" --utc +%FT%T) | ||
|
||
VERSION := $(shell git describe --tags --always --dirty) | ||
version_strategy := commit_hash | ||
ifdef git_tag | ||
VERSION := $(git_tag) | ||
version_strategy := tag | ||
else | ||
ifeq (,$(findstring $(git_branch),master HEAD)) | ||
ifneq (,$(patsubst release-%,,$(git_branch))) | ||
VERSION := $(git_branch) | ||
version_strategy := branch | ||
endif | ||
endif | ||
endif | ||
|
||
### | ||
### These variables should not need tweaking. | ||
### | ||
|
||
SRC_DIRS := cmd pkg hack/gendocs # directories which hold app source (not vendored) | ||
|
||
DOCKER_PLATFORMS := linux/amd64 linux/arm linux/arm64 | ||
BIN_PLATFORMS := $(DOCKER_PLATFORMS) windows/amd64 darwin/amd64 | ||
|
||
# Used internally. Users should pass GOOS and/or GOARCH. | ||
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS)) | ||
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH)) | ||
|
||
GO_VERSION ?= 1.12.5 | ||
BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)-stretch | ||
|
||
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN) | ||
ifeq ($(OS),windows) | ||
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN).exe | ||
endif | ||
|
||
# Directories that we need created to build/test. | ||
BUILD_DIRS := bin/$(OS)_$(ARCH) \ | ||
.go/bin/$(OS)_$(ARCH) \ | ||
.go/cache | ||
|
||
# If you want to build all binaries, see the 'all-build' rule. | ||
# If you want to build all containers, see the 'all-container' rule. | ||
# If you want to build AND push all containers, see the 'all-push' rule. | ||
all: fmt build | ||
|
||
# For the following OS/ARCH expansions, we transform OS/ARCH into OS_ARCH | ||
# because make pattern rules don't match with embedded '/' characters. | ||
|
||
build-%: | ||
@$(MAKE) build \ | ||
--no-print-directory \ | ||
GOOS=$(firstword $(subst _, ,$*)) \ | ||
GOARCH=$(lastword $(subst _, ,$*)) | ||
|
||
all-build: $(addprefix build-, $(subst /,_, $(BIN_PLATFORMS))) | ||
|
||
version: | ||
@echo version=$(VERSION) | ||
@echo version_strategy=$(version_strategy) | ||
@echo git_tag=$(git_tag) | ||
@echo git_branch=$(git_branch) | ||
@echo commit_hash=$(commit_hash) | ||
@echo commit_timestamp=$(commit_timestamp) | ||
|
||
gen: | ||
@true | ||
|
||
fmt: $(BUILD_DIRS) | ||
@docker run \ | ||
-i \ | ||
--rm \ | ||
-u $$(id -u):$$(id -g) \ | ||
-v $$(pwd):/src \ | ||
-w /src \ | ||
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \ | ||
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \ | ||
-v $$(pwd)/.go/cache:/.cache \ | ||
--env HTTP_PROXY=$(HTTP_PROXY) \ | ||
--env HTTPS_PROXY=$(HTTPS_PROXY) \ | ||
$(BUILD_IMAGE) \ | ||
./hack/fmt.sh $(SRC_DIRS) | ||
|
||
build: $(OUTBIN) | ||
|
||
# The following structure defeats Go's (intentional) behavior to always touch | ||
# result files, even if they have not changed. This will still run `go` but | ||
# will not trigger further work if nothing has actually changed. | ||
|
||
$(OUTBIN): .go/$(OUTBIN).stamp | ||
@true | ||
|
||
# This will build the binary under ./.go and update the real binary iff needed. | ||
.PHONY: .go/$(OUTBIN).stamp | ||
.go/$(OUTBIN).stamp: $(BUILD_DIRS) | ||
@echo "making $(OUTBIN)" | ||
@docker run \ | ||
-i \ | ||
--rm \ | ||
-u $$(id -u):$$(id -g) \ | ||
-v $$(pwd):/src \ | ||
-w /src \ | ||
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \ | ||
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \ | ||
-v $$(pwd)/.go/cache:/.cache \ | ||
--env HTTP_PROXY=$(HTTP_PROXY) \ | ||
--env HTTPS_PROXY=$(HTTPS_PROXY) \ | ||
$(BUILD_IMAGE) \ | ||
/bin/bash -c " \ | ||
ARCH=$(ARCH) \ | ||
OS=$(OS) \ | ||
VERSION=$(VERSION) \ | ||
version_strategy=$(version_strategy) \ | ||
git_branch=$(git_branch) \ | ||
git_tag=$(git_tag) \ | ||
commit_hash=$(commit_hash) \ | ||
commit_timestamp=$(commit_timestamp) \ | ||
./hack/build.sh \ | ||
" | ||
@if [ $(COMPRESS) = yes ] && [ $(OS) != windows ]; then \ | ||
echo "compressing $(OUTBIN)"; \ | ||
upx --brute .go/$(OUTBIN); \ | ||
fi | ||
@if ! cmp -s .go/$(OUTBIN) $(OUTBIN); then \ | ||
mv .go/$(OUTBIN) $(OUTBIN); \ | ||
date >$@; \ | ||
fi | ||
@echo | ||
|
||
test: $(BUILD_DIRS) | ||
@docker run \ | ||
-i \ | ||
--rm \ | ||
-u $$(id -u):$$(id -g) \ | ||
-v $$(pwd):/src \ | ||
-w /src \ | ||
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \ | ||
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \ | ||
-v $$(pwd)/.go/cache:/.cache \ | ||
--env HTTP_PROXY=$(HTTP_PROXY) \ | ||
--env HTTPS_PROXY=$(HTTPS_PROXY) \ | ||
$(BUILD_IMAGE) \ | ||
/bin/bash -c " \ | ||
ARCH=$(ARCH) \ | ||
OS=$(OS) \ | ||
VERSION=$(VERSION) \ | ||
./hack/test.sh $(SRC_DIRS) \ | ||
" | ||
|
||
ADDTL_LINTERS := goconst,gofmt,goimports,unparam | ||
|
||
.PHONY: lint | ||
lint: $(BUILD_DIRS) | ||
@echo "running linter" | ||
@docker run \ | ||
-i \ | ||
--rm \ | ||
-u $$(id -u):$$(id -g) \ | ||
-v $$(pwd):/src \ | ||
-w /src \ | ||
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \ | ||
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \ | ||
-v $$(pwd)/.go/cache:/.cache \ | ||
--env HTTP_PROXY=$(HTTP_PROXY) \ | ||
--env HTTPS_PROXY=$(HTTPS_PROXY) \ | ||
--env GO111MODULE=on \ | ||
--env GOFLAGS="-mod=vendor" \ | ||
$(BUILD_IMAGE) \ | ||
golangci-lint run --enable $(ADDTL_LINTERS) | ||
|
||
$(BUILD_DIRS): | ||
@mkdir -p $@ | ||
|
||
.PHONY: dev | ||
dev: gen fmt build | ||
|
||
.PHONY: ci | ||
ci: lint test build #cover | ||
|
||
.PHONY: qa | ||
qa: docker-manifest | ||
@if [ "$$APPSCODE_ENV" = "prod" ]; then \ | ||
echo "Nothing to do in prod env. Are you trying to 'release' binaries to prod?"; \ | ||
exit 1; \ | ||
fi | ||
@if [ "$(version_strategy)" = "git_tag" ]; then \ | ||
echo "Are you trying to 'release' binaries to prod?"; \ | ||
exit 1; \ | ||
fi | ||
@$(MAKE) clean all-build --no-print-directory | ||
|
||
.PHONY: release | ||
release: docker-manifest | ||
@if [ "$$APPSCODE_ENV" != "prod" ]; then \ | ||
echo "'release' only works in PROD env."; \ | ||
exit 1; \ | ||
fi | ||
@if [ "$(version_strategy)" != "git_tag" ]; then \ | ||
echo "'apply_tag' to release binaries and/or docker images."; \ | ||
exit 1; \ | ||
fi | ||
@$(MAKE) clean all-build --no-print-directory | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf .go bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,29 @@ | ||
package main | ||
|
||
import v "github.com/appscode/go/version" | ||
import ( | ||
v "github.com/appscode/go/version" | ||
) | ||
|
||
var ( | ||
Version string | ||
VersionStrategy string | ||
Os string | ||
Arch string | ||
CommitHash string | ||
GitBranch string | ||
GitTag string | ||
GitBranch string | ||
CommitHash string | ||
CommitTimestamp string | ||
BuildTimestamp string | ||
BuildHost string | ||
BuildHostOs string | ||
BuildHostArch string | ||
GoVersion string | ||
Compiler string | ||
Platform string | ||
) | ||
|
||
func init() { | ||
v.Version.Version = Version | ||
v.Version.VersionStrategy = VersionStrategy | ||
v.Version.Os = Os | ||
v.Version.Arch = Arch | ||
v.Version.CommitHash = CommitHash | ||
v.Version.GitBranch = GitBranch | ||
v.Version.GitTag = GitTag | ||
v.Version.GitBranch = GitBranch | ||
v.Version.CommitHash = CommitHash | ||
v.Version.CommitTimestamp = CommitTimestamp | ||
v.Version.BuildTimestamp = BuildTimestamp | ||
v.Version.BuildHost = BuildHost | ||
v.Version.BuildHostOs = BuildHostOs | ||
v.Version.BuildHostArch = BuildHostArch | ||
v.Version.GoVersion = GoVersion | ||
v.Version.Compiler = Compiler | ||
v.Version.Platform = Platform | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.