forked from kubicorn/kubicorn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
161 lines (127 loc) · 5.87 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
ifndef VERBOSE
MAKEFLAGS += --silent
endif
PKGS=$(shell go list ./... | grep -v /vendor)
CI_PKGS=$(shell go list ./... | grep -v /vendor | grep -v test)
FMT_PKGS=$(shell go list -f {{.Dir}} ./... | grep -v vendor | grep -v test | tail -n +2)
GOLANG_IMAGE=golang:1.9.3
GIT_SHA=$(shell git rev-parse --verify HEAD)
VERSION=$(shell cat VERSION)
PWD=$(shell pwd)
GOBUILD=go build -o bin/kubicorn -ldflags "-X github.com/kubicorn/kubicorn/pkg/version.GitSha=${GIT_SHA} -X github.com/kubicorn/kubicorn/pkg/version.KubicornVersion=${VERSION}"
default: authorsfile compile ## Parse Bootstrap scripts and create kubicorn executable in the ./bin directory and the AUTHORS file.
all: default install
compile: ## Create the kubicorn executable in the ./bin directory.
${GOBUILD} main.go
install: ## Create the kubicorn executable in $GOPATH/bin directory.
install -m 0755 bin/kubicorn ${GOPATH}/bin/kubicorn
bindata: ## Generate the bindata for the bootstrap scripts that are built into the binary
which go-bindata > /dev/null || go get -u github.com/jteeuwen/go-bindata/...
rm -rf bootstrap/bootstrap.go
go-bindata -pkg bootstrap -o bootstrap/bootstrap.go bootstrap/
build: authors clean build-linux-amd64 build-darwin-amd64 build-freebsd-amd64 build-windows-amd64
authorsfile: ## Update the AUTHORS file from the git logs
git log --all --format='%aN <%cE>' | sort -u | egrep -v "noreply|mailchimp|@Kris" > AUTHORS
clean: ## Clean the project tree from binary files, and any bootstrap files.
rm -rf bin/*
rm -rf bootstrap/bootstrap.go
gofmt: install-tools ## Go fmt your code
echo "Fixing format of go files..."; \
for package in $(FMT_PKGS); \
do \
gofmt -w $$package ; \
goimports -l -w $$package ; \
done
# Because of https://github.com/golang/go/issues/6376 We actually have to build this in a container
build-linux-amd64: ## Create the kubicorn executable for Linux 64-bit OS in the ./bin directory. Requires Docker.
mkdir -p bin
docker run \
-u $$(id -u):$$(id -g) \
-it \
-w /go/src/github.com/kubicorn/kubicorn \
-v ${PWD}:/go/src/github.com/kubicorn/kubicorn \
-e GOPATH=/go \
--rm ${GOLANG_IMAGE} make docker-build-linux-amd64
docker-build-linux-amd64:
${GOBUILD} -o bin/linux-amd64
build-darwin-amd64: ## Create the kubicorn executable for Darwin (osX) 64-bit OS in the ./bin directory. Requires Docker.
GOOS=darwin GOARCH=amd64 ${GOBUILD} -o bin/darwin-amd64 &
build-freebsd-amd64: ## Create the kubicorn executable for FreeBSD 64-bit OS in the ./bin directory. Requires Docker.
GOOS=freebsd GOARCH=amd64${GOBUILD} -o bin/freebsd-amd64 &
build-windows-amd64: ## Create the kubicorn executable for Windows 64-bit OS in the ./bin directory. Requires Docker.
GOOS=windows GOARCH=amd64${GOBUILD} -o bin/windows-amd64 &
linux: shell
shell: ## Exec into a container with the kubicorn source mounted inside
docker run \
-i -t \
-w /go/src/github.com/kubicorn/kubicorn \
-v ${PWD}:/go/src/github.com/kubicorn/kubicorn \
--rm ${GOLANG_IMAGE} /bin/bash
lint: install-tools ## check for style mistakes all Go files using golint
golint $(PKGS)
bashlint:
if which shellcheck > /dev/null; then \
find . -path ./vendor -prune -o -name '*.sh' -print0 | xargs -n1 -0 shellcheck -s bash -e SC2001; \
else \
echo shellcheck not installed. try something like: apt-get install shellcheck; \
fi
# bootstrap scripts
# located in the kubicorn/bootstrap repository
.PHONY: bootstrap
bootstrap: ## create a submodule for bootstrap scripts
git submodule deinit -f -- bootstrap
rm -rf .git/modules/bootstrap
git rm -rf bootstrap
git submodule add [email protected]:kubicorn/bootstrap.git bootstrap
git submodule init
git submodule update
git --git-dir ./bootstrap/.git checkout origin/${VERSION}
.PHONY: bootstrap-master
bootstrap-master:
git --git-dir ./bootstrap/.git checkout origin/master
.PHONY: bootstrap-version
bootstrap-version:
git --git-dir ./bootstrap/.git checkout origin/${VERSION}
# versioning
bump-major:
./scripts/bump-version.sh major
bump-minor:
./scripts/bump-version.sh minor
bump-patch:
./scripts/bump-version.sh patch
.PHONY: test
test: ## Run the INTEGRATION TESTS. This will create cloud resources and potentially cost money.
go test -timeout 20m -v $(PKGS)
.PHONY: ci
ci: ## Run the CI TESTS. This will never cost money, and will never communicate with a cloud API.
go test -timeout 20m -v $(CI_PKGS)
.PHONY: check-code
check-code: install-tools ## Run code checks
PKGS="${FMT_PKGS}" GOFMT="gofmt" GOLINT="golint" ./scripts/ci-checks.sh
vet: ## apply go vet to all the Go files
@go vet $(PKGS)
check-headers: ## Check if the headers are valid. This is ran in CI.
./scripts/check-header.sh
update-headers: ## Update the headers in the repository. Required for all new files.
./scripts/headers.sh
.PHONY: apimachinery
apimachinery:
go get k8s.io/kubernetes/cmd/libs/go2idl/conversion-gen
go get k8s.io/kubernetes/cmd/libs/go2idl/defaulter-gen
${GOPATH}/bin/conversion-gen --skip-unsafe=true --input-dirs github.com/kubicorn/kubicorn/apis/cluster/v1alpha1 --v=0 --output-file-base=zz_generated.conversion
${GOPATH}/bin/conversion-gen --skip-unsafe=true --input-dirs github.com/kubicorn/kubicorn/apis/cluster/v1alpha1 --v=0 --output-file-base=zz_generated.conversion
${GOPATH}/bin/defaulter-gen --input-dirs github.com/kubicorn/kubicorn/apis/cluster/v1alpha1 --v=0 --output-file-base=zz_generated.defaults
${GOPATH}/bin/defaulter-gen --input-dirs github.com/kubicorn/kubicorn/apis/cluster/v1alpha1 --v=0 --output-file-base=zz_generated.defaults
.PHONY: install-tools
install-tools:
GOIMPORTS_CMD=$(shell command -v goimports 2> /dev/null)
ifndef GOIMPORTS_CMD
go get golang.org/x/tools/cmd/goimports
endif
GOLINT_CMD=$(shell command -v golint 2> /dev/null)
ifndef GOLINT_CMD
go get golang.org/x/lint/golint
endif
.PHONY: help
help: ## Show help messages for make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'