generated from ouzi-dev/bigbang
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
243 lines (202 loc) · 6.62 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# Get current directory
DIR := ${CURDIR}
SOURCE_FILES?=./...
TEST_PATTERN?=.
TEST_OPTIONS?=
# reenable after this is fixed for go 1.13
TEST_COVERAGE_OPTIONS ?= # -coverpkg=./... -covermode=atomic -coverprofile=coverage.out
OS=$(shell uname -s)
GO ?= go
BINDIR := $(DIR)/bin
LDFLAGS := -w -s
TARGETS ?= darwin/amd64 linux/amd64 windows/amd64
DIST_DIRS = find * -type d -exec
SHELL = /bin/bash
BASE_BUILD_PATH = github.com/ouzi-dev/credstash-operator
BUILD_PATH = $(BASE_BUILD_PATH)/cmd/manager
NAME = credstash-operator
GIT_SHORT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_TAG := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
HAS_GOX := $(shell command -v gox;)
HAS_GIT := $(shell command -v git;)
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
HAS_GO_IMPORTS := $(shell command -v goimports;)
HAS_GO_MOCKGEN := $(shell command -v mockgen;)
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
GOLANGCI_LINT_VERSION := v1.24.0
GOLANGCI_VERSION_CHECK := $(shell golangci-lint --version | grep -oh $(GOLANGCI_LINT_VERSION);)
DOCKER_REPO := quay.io/ouzi/credstash-operator
TMP_VERSION := $(GIT_SHORT_COMMIT)
GCLOUD_KEY_FILE := /etc/google-service-account/service-account.json
ifndef VERSION
ifeq ($(GIT_DIRTY), clean)
ifdef GIT_TAG
TMP_VERSION = $(GIT_TAG)
endif
endif
endif
VERSION ?= $(TMP_VERSION)
BINARY_VERSION ?= ${VERSION}
# Only set Version if building a tag or VERSION is set
ifneq ($(BINARY_VERSION),)
LDFLAGS += -X $(BASE_BUILD_PATH)/version.Version=${BINARY_VERSION}
endif
.PHONY: setup-lint
setup-lint:
@echo "bootstrap lint..."
ifndef HAS_GOLANGCI_LINT
@echo "golangci-lint $(GOLANGCI_LINT_VERSION) not found..."
@GOPROXY=direct GOSUMDB=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
else
@echo "golangci-lint found, checking version..."
ifeq ($(GOLANGCI_VERSION_CHECK), )
@echo "found different version, installing golangci-lint $(GOLANGCI_LINT_VERSION)..."
@GOPROXY=direct GOSUMDB=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
else
@echo "golangci-lint version $(GOLANGCI_VERSION_CHECK) found!"
endif
endif
# Install all the build and lint dependencies
.PHONY: setup
setup: setup-lint
ifndef HAS_GOX
$(GO) get -u github.com/mitchellh/gox
endif
ifndef HAS_GO_IMPORTS
$(GO) get golang.org/x/tools/cmd/goimports
endif
ifndef HAS_GO_MOCKGEN
$(GO) get github.com/golang/mock/gomock
$(GO) install github.com/golang/mock/mockgen
endif
@which ./bin/openapi-gen > /dev/null || go build -o ./bin/openapi-gen k8s.io/kube-openapi/cmd/openapi-gen
test:
$(GO) test $(TEST_OPTIONS) \
-v -failfast \
$(TEST_COVERAGE_OPTIONS) \
$(SOURCE_FILES) \
-run $(TEST_PATTERN) -timeout=2m
cover: test
$(GO) tool cover -html=coverage.out
fmt:
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done
lint:
golangci-lint run \
--enable-all \
-D gochecknoglobals \
-D gochecknoinits \
-D dupl \
--skip-files \
pkg/apis/credstash/v1alpha1/zz_generated.deepcopy.go,\
pkg/apis/credstash/v1alpha1/zz_generated.openapi.go \
--timeout 2m \
./...
.DEFAULT_GOAL := build
info:
@echo "How are you: $(GIT_DIRTY)"
@echo "Version: ${VERSION}"
@echo "Git Tag: ${GIT_TAG}"
@echo "Git Commit: ${GIT_SHORT_COMMIT}"
.PHONY: build
build: build-cross
# usage: make clean build-cross dist VERSION=v0.2-alpha
.PHONY: build-cross
build-cross: LDFLAGS += -extldflags "-static"
build-cross:
CGO_ENABLED=0 gox -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}/$(NAME)" -osarch='$(TARGETS)' -ldflags '$(LDFLAGS)' $(BUILD_PATH)
.PHONY: dist
dist:
( \
cd _dist && \
$(DIST_DIRS) tar -zcf $(NAME)-${VERSION}-{}.tar.gz {} \; && \
$(DIST_DIRS) zip -r $(NAME)-${VERSION}-{}.zip {} \; \
)
.PHONY: docker-build
docker-build: clean info
@gcloud builds submit --config build/cloudbuild-build.yaml \
--substitutions=_TAG_VERSION=$(VERSION),_QUAY_REPO=$(DOCKER_REPO) .
.PHONY: docker-push
docker-push: clean info
@gcloud builds submit --config build/cloudbuild-push.yaml \
--substitutions=_TAG_VERSION=$(VERSION),_QUAY_REPO=$(DOCKER_REPO) .
.PHONY: clean
clean: helm-clean
@rm -rf $(BINDIR) ./_dist
.PHONY: generate
generate: setup
@operator-sdk generate k8s
@operator-sdk generate crds
@./bin/openapi-gen --logtostderr=true \
-o "" -i ./pkg/apis/credstash/v1alpha1 \
-O zz_generated.openapi \
-p ./pkg/apis/credstash/v1alpha1 \
-h ./hack/boilerplate.go.txt -r "-"
@go generate ./...
@cp deploy/crds/credstash.ouzi.tech_credstashsecrets_crd.yaml deploy/helm/credstash-operator/crds/crds.yaml
CHART_NAME ?= credstash-operator
CHART_VERSION ?= 0.0.0
CHART_PATH ?= deploy/helm
CHART_DIST ?= $(CHART_PATH)/$(CHART_NAME)/dist
HELM_PLUGIN_PUSH_URL := https://github.com/chartmuseum/helm-push
HELM_PLUGIN_PUSH_VERSION := v0.8.1
HELM_REPO_URL := https://charts.ouzi.io
HELM_REPO_NAME := ouzi
.PHONY: helm-clean
helm-clean:
rm -rf $(CHART_PATH)/$(CHART_NAME)/charts
rm -rf $(CHART_DIST)
# does not work without explicitly specifying the api version
# see: https://github.com/helm/helm/issues/6505
.PHONY: helm-validate
helm-validate:
helm template credstash-operator \
--namespace credstash-operator \
--debug \
-a apiregistration.k8s.io/v1beta1 \
-a cert-manager.io/v1alpha2 \
-a monitoring.coreos.com/v1 \
-a apiextensions.k8s.io/v1beta1 \
-a credstash.ouzi.tech/v1 \
$(CHART_PATH)/${CHART_NAME}
.PHONY: helm-package
helm-package: helm-clean
@helm package \
--version=$(VERSION) \
--app-version=$(VERSION) \
--dependency-update \
--destination $(CHART_DIST) \
$(CHART_PATH)/$(CHART_NAME)
.PHONY: helm-lint
helm-lint:
helm lint $(CHART_PATH)/$(CHART_NAME)
.PHONY: helm-push-init
helm-push-init:
@helm plugin install $(HELM_PLUGIN_PUSH_URL) --version $(HELM_PLUGIN_PUSH_VERSION) || echo "Plugin already installed - nothing to do"
@helm repo add $(HELM_REPO_NAME) $(HELM_REPO_URL)
@helm repo update
helm-push: helm-push-init
@helm push $(CHART_DIST)/$(CHART_NAME)-$(VERSION).tgz $(HELM_REPO_NAME)
.PHONY: semantic-release
semantic-release:
@npm ci
@npx semantic-release
.PHONY: semantic-release-dry-run
semantic-release-dry-run:
@npm ci
@npx semantic-release -d
package-lock.json: package.json
@npm install
.PHONY: init-gcloud-cli
init-gcloud-cli:
ifneq ("$(wildcard $(GCLOUD_KEY_FILE))","")
gcloud auth activate-service-account --key-file=$(GCLOUD_KEY_FILE)
else
@echo $(GCLOUD_KEY_FILE) not present
endif
.PHONY: install-npm-check-updates
install-npm-check-updates:
npm install npm-check-updates
.PHONY: update-npm-dependencies
update-npm-dependencies: install-npm-check-updates
ncu -u
npm install