Skip to content

Commit

Permalink
Add Makefile (kubedb#412)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored May 26, 2019
1 parent 3e0be30 commit 48e4bab
Show file tree
Hide file tree
Showing 95 changed files with 2,549 additions and 1,169 deletions.
15 changes: 10 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ _testmain.go
*.test
*.prof

dist/
.idea/
.vscode/
coverage.txt
apiserver.local.config/
**/.env
**/junit.xml
/.idea
/.vscode
/apiserver.local.config
/coverage.txt
/dist

/bin
/.go
179 changes: 179 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
SHELL=/bin/bash -o pipefail

# The binary to build (just the basename).
BIN := apimachinery

# 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 := apis client pkg hack/gencrd # 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))

BASEIMAGE_PROD ?= gcr.io/distroless/static
BASEIMAGE_DBG ?= debian:stretch

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:
./hack/codegen.sh

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)

.PHONY: .go/$(OUTBIN)
$(OUTBIN): $(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 \
"
@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 push

.PHONY: ci
ci: lint test build #cover

.PHONY: clean
clean:
rm -rf .go bin
15 changes: 11 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@ go 1.12

require (
github.com/appscode/docker-registry-client v0.0.0-20180426150142-1bb02bb202b0
github.com/appscode/go v0.0.0-20190424183524-60025f1135c9
github.com/appscode/go v0.0.0-20190523031839-1468ee3a76e8
github.com/appscode/osm v0.0.0-20190225021050-90ec9897e91b // indirect
github.com/aws/aws-sdk-go v1.14.33 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/evanphx/json-patch v4.2.0+incompatible
github.com/go-openapi/spec v0.19.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/gorilla/mux v1.7.2 // indirect
github.com/graymeta/stow v0.0.0-00010101000000-000000000000
github.com/json-iterator/go v1.1.6
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/orcaman/concurrent-map v0.0.0-20190314100340-2693aad1ed75
github.com/pkg/errors v0.8.1
github.com/prometheus/common v0.4.0 // indirect
github.com/prometheus/client_golang v0.9.3 // indirect
github.com/prometheus/common v0.4.1 // indirect
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/spf13/cobra v0.0.4 // indirect
google.golang.org/genproto v0.0.0-20190508193815-b515fa19cec8 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5
k8s.io/api v0.0.0-20190503110853-61630f889b3c
k8s.io/apiextensions-apiserver v0.0.0-20190508184259-7784d62bc471
k8s.io/apimachinery v0.0.0-20190508063446-a3da69d3723c
k8s.io/apiserver v0.0.0-20190508183956-3a0abf14e58a // indirect
k8s.io/client-go v11.0.0+incompatible
k8s.io/klog v0.3.1 // indirect
k8s.io/kube-openapi v0.0.0-20190502190224-411b2483e503
kmodules.xyz/client-go v0.0.0-20190524133821-9c8a87771aea
kmodules.xyz/custom-resources v0.0.0-20190225012057-ed1c15a0bbda
kmodules.xyz/custom-resources v0.0.0-20190508103408-464e8324c3ec
kmodules.xyz/monitoring-agent-api v0.0.0-20190508125842-489150794b9b
kmodules.xyz/objectstore-api v0.0.0-20190506085934-94c81c8acca9
kmodules.xyz/offshoot-api v0.0.0-20190508142450-1c69d50f3c1c
Expand Down
Loading

0 comments on commit 48e4bab

Please sign in to comment.