forked from kudobuilder/kudo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
137 lines (112 loc) · 3.52 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
SHELL=/bin/bash -o pipefail
# Image URL to use all building/pushing image targets
DOCKER_TAG ?= $(shell git rev-parse HEAD)
DOCKER_IMG ?= kudobuilder/controller
EXECUTABLE := manager
CLI := kubectl-kudo
GIT_VERSION_PATH := github.com/kudobuilder/kudo/pkg/version.gitVersion
GIT_VERSION := $(shell git describe --abbrev=0 --tags | cut -b 2-)
GIT_COMMIT_PATH := github.com/kudobuilder/kudo/pkg/version.gitCommit
GIT_COMMIT := $(shell git rev-parse HEAD | cut -b -8)
SOURCE_DATE_EPOCH := $(shell git show -s --format=format:%ct HEAD)
BUILD_DATE_PATH := github.com/kudobuilder/kudo/pkg/version.buildDate
DATE_FMT := "%Y-%m-%dT%H:%M:%SZ"
BUILD_DATE := $(shell date -u -d "@$SOURCE_DATE_EPOCH" "+${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "+${DATE_FMT}" 2>/dev/null || date -u "+${DATE_FMT}")
LDFLAGS := -X ${GIT_VERSION_PATH}=${GIT_VERSION} -X ${GIT_COMMIT_PATH}=${GIT_COMMIT} -X ${BUILD_DATE_PATH}=${BUILD_DATE}
export GO111MODULE=on
.PHONY: all
all: test manager
.PHONY: test
# Run tests
test:
go test ./pkg/... ./cmd/... -v -mod=readonly -coverprofile cover.out
# Run e2e tests
.PHONY: e2e-test
e2e-test: cli-fast
./hack/run-e2e-tests.sh
.PHONY: integration-test
# Run integration tests
integration-test: cli-fast
./hack/run-integration-tests.sh
.PHONY: test-clean
# Clean test reports
test-clean:
rm -f cover.out cover-integration.out
.PHONY: lint
lint:
ifeq (, $(shell which golangci-lint))
go get github.com/golangci/golangci-lint/cmd/golangci-lint
endif
golangci-lint run
.PHONY: download
download:
go mod download
.PHONY: prebuild
prebuild: generate lint
.PHONY: manager
# Build manager binary
manager: prebuild
# developer convenience for platform they are running
go build -ldflags "${LDFLAGS}" -o bin/$(EXECUTABLE) github.com/kudobuilder/kudo/cmd/manager
.PHONY: manager-clean
# Clean manager build
manager-clean:
rm -f bin/manager
.PHONY: run
# Run against the configured Kubernetes cluster in ~/.kube/config
run:
go run -ldflags "${LDFLAGS}" ./cmd/manager/main.go
.PHONY: deploy
# Install KUDO into a cluster via kubectl kudo init
deploy:
go run -ldflags "${LDFLAGS}" cmd/kubectl-kudo/main.go init
.PHONY: deploy-clean
deploy-clean:
go run ./cmd/kubectl-kudo init --dry-run --output yaml | kubectl delete -f -
.PHONY: generate
# Generate code
generate:
./hack/update_codegen.sh
.PHONY: generate-clean
generate-clean:
rm -rf hack/code-gen
.PHONY: cli-fast
# Build CLI but don't lint or run code generation first.
cli-fast:
go build -ldflags "${LDFLAGS}" -o bin/${CLI} cmd/kubectl-kudo/main.go
.PHONY: cli
# Build CLI
cli: prebuild cli-fast
.PHONY: cli-clean
# Clean CLI build
cli-clean:
rm -f bin/${CLI}
# Install CLI
cli-install:
go install -ldflags "${LDFLAGS}" ./cmd/kubectl-kudo
.PHONY: clean
# Clean all
clean: cli-clean test-clean manager-clean deploy-clean
.PHONY: docker-build
# Build the docker image
docker-build: generate lint
docker build --build-arg git_version_arg=${GIT_VERSION_PATH}=v${GIT_VERSION} \
--build-arg git_commit_arg=${GIT_COMMIT_PATH}=${GIT_COMMIT} \
--build-arg build_date_arg=${BUILD_DATE_PATH}=${BUILD_DATE} . -t ${DOCKER_IMG}:${DOCKER_TAG}
docker tag ${DOCKER_IMG}:${DOCKER_TAG} ${DOCKER_IMG}:v${GIT_VERSION}
docker tag ${DOCKER_IMG}:${DOCKER_TAG} ${DOCKER_IMG}:latest
.PHONY: docker-push
# Push the docker image
docker-push:
docker push ${DOCKER_IMG}:${DOCKER_TAG}
docker push ${DOCKER_IMG}:${GIT_VERSION}
docker push ${DOCKER_IMG}:latest
.PHONY: todo
# Show to-do items per file.
todo:
@grep \
--exclude-dir=hack \
--exclude=Makefile \
--text \
--color \
-nRo -E ' TODO:.*|SkipNow' .