Skip to content

Commit 550eed5

Browse files
author
llcao
committed
update makefile to add test, build and images targets.
fix typo. move yaml_test to test section.
1 parent 6accf0c commit 550eed5

File tree

2 files changed

+122
-93
lines changed

2 files changed

+122
-93
lines changed

.travis.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

Makefile

Lines changed: 122 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,179 @@
1-
2-
# Image URL to use all building/pushing image targets
3-
CONTROLLER_IMG ?= ibmcloud-cluster-api-controller
4-
CLUSTERCTL_IMG ?= ibmcloud-cluster-api-clusterctl
5-
VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
6-
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
7-
REGISTRY ?= k8scloudprovider
8-
1+
GIT_HOST = sigs.k8s.io
92
PWD := $(shell pwd)
103
BASE_DIR := $(shell basename $(PWD))
114
# Keep an existing GOPATH, make a private one if it is undefined
125
GOPATH_DEFAULT := $(PWD)/.go
136
export GOPATH ?= $(GOPATH_DEFAULT)
147
GOBIN_DEFAULT := $(GOPATH)/bin
158
export GOBIN ?= $(GOBIN_DEFAULT)
16-
17-
# goang dep tools
18-
DEP = github.com/golang/dep/cmd/dep
19-
DEP_CHECK := $(shell command -v dep 2> /dev/null)
9+
TESTARGS_DEFAULT := "-v"
10+
export TESTARGS ?= $(TESTARGS_DEFAULT)
11+
PKG := $(shell awk -F "\"" '/^ignored = / { print $$2 }' Gopkg.toml)
12+
DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR)
13+
SOURCES := $(shell find $(DEST) -name '*.go')
2014

2115
HAS_DEP := $(shell command -v dep;)
16+
HAS_LINT := $(shell command -v golint;)
2217
HAS_KUSTOMIZE := $(shell command -v kustomize;)
18+
GOX_PARALLEL ?= 3
19+
TARGETS ?= darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le
20+
DIST_DIRS = find * -type d -exec
2321

2422
GENERATE_YAML_PATH=cmd/clusterctl/examples/ibmcloud
2523
GENERATE_YAML_EXEC=generate-yaml.sh
2624
GENERATE_YAML_TEST_FOLDER=dummy-make-auto-test
2725

28-
all: test manager
26+
GOOS ?= $(shell go env GOOS)
27+
VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
28+
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
29+
GOFLAGS :=
30+
TAGS :=
31+
LDFLAGS := "-w -s -X 'main.version=${VERSION}'"
2932

30-
# Run tests
31-
test: depend generate fmt vet manifests generate_yaml_test
32-
go test ./pkg/... ./cmd/... -coverprofile cover.out
33+
# Image URL to use all building/pushing image targets
34+
CONTROLLER_IMG ?= ibmcloud-cluster-api-controller
35+
CLUSTERCTL_IMG ?= ibmcloud-cluster-api-clusterctl
36+
VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
37+
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
38+
REGISTRY ?= k8scloudprovider
3339

40+
ifneq ("$(realpath $(DEST))", "$(realpath $(PWD))")
41+
$(error Please run 'make' from $(DEST). Current directory is $(PWD))
42+
endif
3443

35-
# Build manager binary
36-
build: manager clusterctl
44+
all: test build images
3745

38-
manager: generate fmt vet
39-
go build -o bin/manager cmd/manager/main.go
46+
############################################################
47+
# depend section
48+
############################################################
49+
$(GOBIN):
50+
echo "create gobin"
51+
mkdir -p $(GOBIN)
4052

41-
clusterctl:
42-
go build -o bin/clusterctl cmd/clusterctl/main.go
53+
work: $(GOBIN)
4354

44-
# Run against the configured Kubernetes cluster in ~/.kube/config
45-
run: depend generate fmt vet
46-
go run ./cmd/manager/main.go
55+
depend: work
56+
ifndef HAS_DEP
57+
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
58+
endif
59+
dep ensure
4760

48-
# Install CRDs into a cluster
49-
install: manifests
50-
kubectl apply -f config/crds
61+
depend-update: work
62+
dep ensure -update
5163

52-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
53-
deploy: manifests
54-
cat provider-components.yaml | kubectl apply -f -
64+
############################################################
65+
# generate section
66+
############################################################
67+
generate:
68+
ifndef GOPATH
69+
$(error GOPATH not defined, please define GOPATH. Run "go help gopath" to learn more about GOPATH)
70+
endif
71+
go generate ./pkg/... ./cmd/...
5572

56-
# Generate manifests e.g. CRD, RBAC etc.
57-
manifests:
58-
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go crd
59-
kustomize build config/default/ > provider-components.yaml
60-
echo "---" >> provider-components.yaml
61-
kustomize build vendor/sigs.k8s.io/cluster-api/config/default/ >> provider-components.yaml
73+
############################################################
74+
# check section
75+
############################################################
76+
check: fmt vet lint
6277

63-
# Run go fmt against code
64-
fmt:
65-
go fmt ./pkg/... ./cmd/...
78+
fmt: depend generate
79+
hack/verify-gofmt.sh
6680

67-
# Run go vet against code
68-
vet:
69-
go vet ./pkg/... ./cmd/...
81+
lint: depend generate
82+
ifndef HAS_LINT
83+
go get -u golang.org/x/lint/golint
84+
echo "installing golint"
85+
endif
86+
hack/verify-golint.sh
7087

71-
generate_yaml_test:
88+
vet: depend generate
89+
go vet ./...
90+
91+
############################################################
92+
# test section
93+
############################################################
94+
test: unit functional fmt vet generate_yaml_test
7295

96+
unit: depend generate check
97+
go test -tags=unit $(shell go list ./...) $(TESTARGS)
98+
99+
functional:
100+
@echo "$@ not yet implemented"
101+
102+
# Generate manifests e.g. CRD, RBAC etc.
103+
generate_yaml_test:
73104
ifndef HAS_KUSTOMIZE
74105
# for now, higher version has some problem so we stick to 1.0.11
75106
wget https://github.com/kubernetes-sigs/kustomize/releases/download/v1.0.11/kustomize_1.0.11_linux_amd64
76107
mv kustomize_1.0.11_linux_amd64 /usr/local/bin/kustomize
77108
chmod +x /usr/local/bin/kustomize
78109
endif
79-
80110
# Create a dummy file for test only
81111
echo 'clouds' > cmd/clusterctl/examples/ibmcloud/dummy-clouds-test.yaml
82112
$(GENERATE_YAML_PATH)/$(GENERATE_YAML_EXEC) -f dummy-clouds-test.yaml ubuntu $(GENERATE_YAML_TEST_FOLDER)
83113
# the folder will be generated under same folder of $(GENERATE_YAML_PATH)
84114
rm -fr $(GENERATE_YAML_PATH)/$(GENERATE_YAML_TEST_FOLDER)
85115
rm -f cmd/clusterctl/examples/ibmcloud/dummy-clouds-test.yaml
86116

87-
# Generate code
88-
generate:
89-
ifndef GOPATH
90-
$(error GOPATH not defined, please define GOPATH. Run "go help gopath" to learn more about GOPATH)
91-
endif
92-
go generate ./pkg/... ./cmd/...
117+
############################################################
118+
# build section
119+
############################################################
120+
build: manager clusterctl
121+
122+
manager: depend generate check
123+
CGO_ENABLED=0 GOOS=$(GOOS) go build \
124+
-ldflags $(LDFLAGS) \
125+
-o bin/manager \
126+
cmd/manager/main.go
127+
128+
clusterctl: depend generate check
129+
CGO_ENABLED=0 GOOS=$(GOOS) go build \
130+
-ldflags $(LDFLAGS) \
131+
-o bin/clusterctl \
132+
cmd/clusterctl/main.go
133+
134+
############################################################
135+
# deploy section
136+
############################################################
137+
# Run against the configured Kubernetes cluster in ~/.kube/config
138+
run: depend generate check
139+
go run ./cmd/manager/main.go
93140

141+
# Install CRDs into a cluster
142+
install: generate_yaml_test
143+
kubectl apply -f config/crds
144+
145+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
146+
deploy: generate_yaml_test
147+
cat provider-components.yaml | kubectl apply -f -
148+
149+
############################################################
150+
# images section
151+
############################################################
94152
# Build the docker image
95-
docker-build: test
153+
build-images: test
96154
docker build . -f cmd/manager/Dockerfile -t $(REGISTRY)/$(CONTROLLER_IMG):$(VERSION)
97155
docker build . -f cmd/clusterctl/Dockerfile -t $(REGISTRY)/$(CLUSTERCTL_IMG):$(VERSION)
98156

99157
# Push the docker image
100-
docker-push:
158+
push-images:
159+
@echo "push images to $(REGISTRY)"
101160
docker push $(REGISTRY)/$(CONTROLLER_IMG):$(VERSION)
102161
docker push $(REGISTRY)/$(CLUSTERCTL_IMG):$(VERSION)
103162

104-
quick-image:
163+
build-push-images:
105164
docker build . -f cmd/manager/Dockerfile -t $(REGISTRY)/$(CONTROLLER_IMG):$(VERSION)
106165
docker push $(REGISTRY)/$(CONTROLLER_IMG):$(VERSION)
107166
docker build . -f cmd/clusterctl/Dockerfile -t $(REGISTRY)/$(CLUSTERCTL_IMG):$(VERSION)
108167
docker push $(REGISTRY)/$(CLUSTERCTL_IMG):$(VERSION)
109168

110-
$(GOBIN):
111-
echo "create gobin"
112-
mkdir -p $(GOBIN)
113-
114-
work: $(GOBIN)
115-
116-
depend: work
117-
ifndef HAS_DEP
118-
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
119-
endif
120-
dep ensure
121-
169+
############################################################
170+
# clean section
171+
############################################################
122172
clean:
123173
rm -f bin/manager bin/clusterctl
174+
175+
realclean: clean
176+
rm -rf vendor
177+
if [ "$(GOPATH)" = "$(GOPATH_DEFAULT)" ]; then \
178+
rm -rf $(GOPATH); \
179+
fi

0 commit comments

Comments
 (0)