forked from schemahero/schemahero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
227 lines (192 loc) · 6.43 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
SHELL := /bin/bash
VERSION ?=`git describe --tags`
DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
VERSION_PACKAGE = github.com/schemahero/schemahero/pkg/version
GIT_TREE = $(shell git rev-parse --is-inside-work-tree 2>/dev/null)
ifneq "$(GIT_TREE)" ""
define GIT_UPDATE_INDEX_CMD
git update-index --assume-unchanged
endef
define GIT_SHA
`git rev-parse HEAD`
endef
else
define GIT_UPDATE_INDEX_CMD
echo "Not a git repo, skipping git update-index"
endef
define GIT_SHA
""
endef
endif
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
define LDFLAGS
-ldflags "\
-X ${VERSION_PACKAGE}.version=${VERSION} \
-X ${VERSION_PACKAGE}.gitSHA=${GIT_SHA} \
-X ${VERSION_PACKAGE}.buildTime=${DATE} \
-w -extldflags \"-static\" \
"
endef
else # all other OSes, including Windows and Darwin
define LDFLAGS
-ldflags "\
-X ${VERSION_PACKAGE}.version=${VERSION} \
-X ${VERSION_PACKAGE}.gitSHA=${GIT_SHA} \
-X ${VERSION_PACKAGE}.buildTime=${DATE} \
"
endef
endif
export GO111MODULE=on
# export GOPROXY=https://proxy.golang.org
all: generate fmt vet manifests bin/kubectl-schemahero manager test
.PHONY: clean-and-tidy
clean-and-tidy:
@go clean -modcache ||:
@go mod tidy ||:
.PHONY: envtest
envtest:
./hack/envtest.sh
.PHONY: test
test: fmt vet manifests envtest
go test ./pkg/... ./cmd/... -coverprofile cover.out
.PHONY: manager
manager: fmt vet bin/manager
.PHONY: bin/manager
bin/manager:
go build \
-tags netgo -installsuffix netgo \
${LDFLAGS} \
-o bin/manager \
./cmd/manager
.PHONY: run
run: generate fmt vet bin/manager
./bin/manager run \
--log-level debug \
--database-name="*"
.PHONY: run-database
run-database: generate fmt vet bin/manager
./bin/manager run \
--enable-database-controller \
--manager-image localhost:32000/schemahero/schemahero-manager \
--manager-tag latest
.PHONY: install
install: manifests generate local
kubectl apply -f config/crds/v1
.PHONY: deploy
deploy: manifests
kubectl apply -f config/crds/v1
kustomize build config/default | kubectl apply -f -
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) \
rbac:roleName=manager-role webhook \
crd:crdVersions=v1,generateEmbeddedObjectMeta=true \
output:crd:artifacts:config=config/crds/v1 \
paths="./..."
cp -R config/crds/v1/ pkg/installer/assets
.PHONY: fmt
fmt:
go fmt ./pkg/... ./cmd/...
.PHONY: vet
vet:
go vet ./pkg/... ./cmd/...
.PHONY: generate
generate: controller-gen client-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/...
$(CLIENT_GEN) \
--output-package=github.com/schemahero/schemahero/pkg/client \
--clientset-name schemaheroclientset \
--input-base github.com/schemahero/schemahero/pkg/apis \
--input databases/v1alpha4 \
--input schemas/v1alpha4 \
-h ./hack/boilerplate.go.txt
.PHONY: bin/kubectl-schemahero
bin/kubectl-schemahero:
go build \
-tags netgo -installsuffix netgo \
${LDFLAGS} \
-o bin/kubectl-schemahero \
./cmd/kubectl-schemahero
@echo "built bin/kubectl-schemahero"
.PHONY: local
local: bin/kubectl-schemahero manager
docker build -t schemahero/schemahero-manager -f ./Dockerfile.manager .
docker tag schemahero/schemahero-manager localhost:32000/schemahero/schemahero-manager:latest
docker push localhost:32000/schemahero/schemahero-manager:latest
.PHONY: kind
kind: bin/kubectl-schemahero manager
.PHONY: contoller-gen
controller-gen:
ifeq (, $(shell which controller-gen))
go install sigs.k8s.io/controller-tools/cmd/[email protected]
CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
.PHONY: client-gen
client-gen:
ifeq (, $(shell which client-gen))
go install k8s.io/code-generator/cmd/[email protected]
CLIENT_GEN=$(shell go env GOPATH)/bin/client-gen
else
CLIENT_GEN=$(shell which client-gen)
endif
.PHONY: sbom
sbom: spdx-generator
mkdir -p sbom
$(SPDX_GENERATOR) -o ./sbom
.PHONY: spdx-generator
spdx-generator:
ifeq (, $(shell which spdx-sbom-generator))
mkdir -p sbom
curl -L https://github.com/spdx/spdx-sbom-generator/releases/download/v0.0.10/spdx-sbom-generator-v0.0.10-linux-amd64.tar.gz -o ./sbom/spdx-sbom-generator-v0.0.10-linux-amd64.tar.gz
tar xzvf ./sbom/spdx-sbom-generator-v0.0.10-linux-amd64.tar.gz -C sbom
SPDX_GENERATOR=./sbom/spdx-sbom-generator
else
SPDX_GENERATOR=$(shell which spdx-sbom-generator)
endif
.PHONY: release-tarballs
release-tarballs:
rm -rf release
mkdir -p ./release
# Build the kubectl plugins
rm -rf ./bin/kubectl-schemahero
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make bin/kubectl-schemahero
mv bin/kubectl-schemahero ./kubectl-schemahero
tar czvf ./release/kubectl-schemahero_linux_amd64.tar.gz ./kubectl-schemahero README.md LICENSE
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 make bin/kubectl-schemahero
mv bin/kubectl-schemahero ./kubectl-schemahero
tar czvf ./release/kubectl-schemahero_linux_arm64.tar.gz ./kubectl-schemahero README.md LICENSE
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 make bin/kubectl-schemahero
mv bin/kubectl-schemahero ./kubectl-schemahero.exe
tar czvf ./release/kubectl-schemahero_windows_amd64.tar.gz ./kubectl-schemahero.exe README.md LICENSE
rm kubectl-schemahero.exe
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 make bin/kubectl-schemahero
mv bin/kubectl-schemahero ./kubectl-schemahero
tar czvf ./release/kubectl-schemahero_darwin_amd64.tar.gz ./kubectl-schemahero README.md LICENSE
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 make bin/kubectl-schemahero
mv bin/kubectl-schemahero ./kubectl-schemahero
tar czvf ./release/kubectl-schemahero_darwin_arm64.tar.gz ./kubectl-schemahero README.md LICENSE
rm -rf ./kubectl-schemahero
.PHONY: release
release: release-tarballs
# build the docker images for in-cluster
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make bin/manager
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make bin/kubectl-schemahero
docker build -t schemahero/schemahero:${GITHUB_TAG} -f ./deploy/Dockerfile.schemahero .
docker build -t schemahero/schemahero-manager:${GITHUB_TAG} -f ./deploy/Dockerfile.manager .
docker push schemahero/schemahero:${GITHUB_TAG}
docker push schemahero/schemahero-manager:${GITHUB_TAG}
cosign attach sbom -sbom ./sbom/bom-go-mod.spdx schemahero/schemahero:${GITHUB_TAG}
cosign attach sbom -sbom ./sbom/bom-go-mod.spdx schemahero/schemahero-manager:${GITHUB_TAG}
cosign sign -key ./cosign.key schemahero/schemahero:${GITHUB_TAG}
cosign sign -key ./cosign.key schemahero/schemahero-manager:${GITHUB_TAG}
.PHONY: scan
scan:
trivy fs \
--security-checks vuln \
--exit-code=1 \
--severity="HIGH,CRITICAL" \
--ignore-unfixed \
./