Skip to content

Instantly share code, notes, and snippets.

@duglin
Last active December 17, 2016 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duglin/c584ccfa54aca37ac0032b8cbb7d79f8 to your computer and use it in GitHub Desktop.
Save duglin/c584ccfa54aca37ac0032b8cbb7d79f8 to your computer and use it in GitHub Desktop.
Makefile
all: init build test lint
.PHONY: format coverage
# If DOCKER is defined then make it the full docker cmd line we want to use
ifneq ($(origin DOCKER),undefined)
DOCKER=docker run --rm -ti \
-v $(PWD):/go/src/github.com/kubernetes-incubator/service-catalog \
scbuildimage
endif
BINDIR=bin
GO_VERSION=1.7.3
GO_BUILD=go build
export GOPATH=$(shell cd ../../../..;pwd):$(PWD)/vendor
COVERAGE?=$(CURDIR)/coverage.html
SC_PKG=github.com/kubernetes-incubator/service-catalog
SRC_FILES=$(shell sh -c "find contrib pkg -name \\*.go | sort | uniq")
SRC_DIRS=$(shell sh -c "find contrib pkg -name \\*.go -exec dirname {} \\; | sort | uniq")
SRC_PKGS=$(addprefix $(SC_PKG)/,$(SRC_DIRS))
# This section builds the output binaries
#########################################
build: init \
$(BINDIR)/controller $(BINDIR)/registry $(BINDIR)/k8s-broker \
$(BINDIR)/service-catalog $(BINDIR)/user-broker
$(BINDIR)/controller: pkg/controller/catalog
$(DOCKER) $(GO_BUILD) -o $@ $(SC_PKG)/$^
$(BINDIR)/registry: contrib/registry
$(DOCKER) $(GO_BUILD) -o $@ $(SC_PKG)/$^
$(BINDIR)/k8s-broker: contrib/broker/k8s
$(DOCKER) $(GO_BUILD) -o $@ $(SC_PKG)/$^
$(BINDIR)/service-catalog: cmd/service-catalog
$(DOCKER) $(GO_BUILD) -o $@ $(SC_PKG)/$^
$(BINDIR)/user-broker: contrib/broker/k8s
$(DOCKER) $(GO_BUILD) -o $@ $(SC_PKG)/$^
# Some prereq stuff
###################
# .init is used to know when some Glide dependencies are out of date
init: .scBuildImage .init
.init: glide.yaml
$(DOCKER) glide install --strip-vendor
echo > .init
# .scBuildImage is used to know when the docker image ("scbuildimage") is out
# of date with the Dockerfile.
.scBuildImage: hack/Dockerfile
docker build -t scbuildimage - < hack/Dockerfile
echo > .scBuildImage
# Util targets
##############
format: init
$(DOCKER) gofmt -w -s $(addprefix ./,$(SRC_DIRS))
coverage: init
$(DOCKER) hack/coverage.sh --html "$(COVERAGE)" $(addprefix ./,$(SRC_DIRS))
lint: init
@echo Running lint:
@for i in $(SRC_PKGS); do \
$(DOCKER) go fmt $$i && \
$(DOCKER) golint --set_exit_status $$i/... && \
$(DOCKER) go vet $$i ; \
done
test:
@echo Running tests:
@for i in $(SRC_PKGS); do \
$(DOCKER) go test $$i ; \
done
clean:
rm -rf $(BINDIR)
rm -f .init
rm -f .scBuildImage
docker rmi -f scbuildimage > /dev/null 2>&1 || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment