forked from kubeflow/model-registry
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
269 lines (218 loc) · 9.15 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# useful paths
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
PROJECT_BIN := $(PROJECT_PATH)/bin
GO ?= "$(shell which go)"
BFF_PATH := $(PROJECT_PATH)/clients/ui/bff
UI_PATH := $(PROJECT_PATH)/clients/ui/frontend
# add tools bin directory
PATH := $(PROJECT_BIN):$(PATH)
MLMD_VERSION ?= 1.14.0
# docker executable
DOCKER ?= docker
# default Dockerfile
DOCKERFILE ?= Dockerfile
# container registry, default to empty (dockerhub) if not explicitly set
IMG_REGISTRY ?= quay.io
# container image organization
IMG_ORG ?= opendatahub
# container image version
IMG_VERSION ?= main
# container image repository
IMG_REPO ?= model-registry
# container image build path
BUILD_PATH ?= .
# container image
ifdef IMG_REGISTRY
IMG := ${IMG_REGISTRY}/${IMG_ORG}/${IMG_REPO}
else
IMG := ${IMG_ORG}/${IMG_REPO}
endif
# Change Dockerfile path depending on IMG_REPO
ifeq ($(IMG_REPO),model-registry-ui)
DOCKERFILE := $(UI_PATH)/Dockerfile
BUILD_PATH := $(UI_PATH)
endif
ifeq ($(IMG_REPO),model-registry-bff)
DOCKERFILE := $(BFF_PATH)/Dockerfile
BUILD_PATH := $(BFF_PATH)
endif
model-registry: build
# clean the ml-metadata protos and trigger a fresh new build which downloads
# ml-metadata protos based on specified MLMD_VERSION
.PHONY: update/ml_metadata
update/ml_metadata: clean/ml_metadata clean build
clean/ml_metadata:
rm -rf api/grpc/ml_metadata/proto/*.proto
api/grpc/ml_metadata/proto/metadata_source.proto:
mkdir -p api/grpc/ml_metadata/proto/
cd api/grpc/ml_metadata/proto/ && \
curl -LO "https://raw.githubusercontent.com/google/ml-metadata/v${MLMD_VERSION}/ml_metadata/proto/metadata_source.proto" && \
sed -i 's#syntax = "proto[23]";#&\noption go_package = "github.com/kubeflow/model-registry/internal/ml_metadata/proto";#' metadata_source.proto
api/grpc/ml_metadata/proto/metadata_store.proto:
mkdir -p api/grpc/ml_metadata/proto/
cd api/grpc/ml_metadata/proto/ && \
curl -LO "https://raw.githubusercontent.com/google/ml-metadata/v${MLMD_VERSION}/ml_metadata/proto/metadata_store.proto" && \
sed -i 's#syntax = "proto[23]";#&\noption go_package = "github.com/kubeflow/model-registry/internal/ml_metadata/proto";#' metadata_store.proto
api/grpc/ml_metadata/proto/metadata_store_service.proto:
mkdir -p api/grpc/ml_metadata/proto/
cd api/grpc/ml_metadata/proto/ && \
curl -LO "https://raw.githubusercontent.com/google/ml-metadata/v${MLMD_VERSION}/ml_metadata/proto/metadata_store_service.proto" && \
sed -i 's#syntax = "proto[23]";#&\noption go_package = "github.com/kubeflow/model-registry/internal/ml_metadata/proto";#' metadata_store_service.proto
internal/ml_metadata/proto/%.pb.go: api/grpc/ml_metadata/proto/%.proto
bin/protoc -I./api/grpc --go_out=./internal --go_opt=paths=source_relative \
--go-grpc_out=./internal --go-grpc_opt=paths=source_relative $<
.PHONY: gen/grpc
gen/grpc: internal/ml_metadata/proto/metadata_store.pb.go internal/ml_metadata/proto/metadata_store_service.pb.go
internal/converter/generated/converter.go: internal/converter/*.go
${GOVERTER} gen github.com/kubeflow/model-registry/internal/converter/
.PHONY: gen/converter
gen/converter: gen/grpc internal/converter/generated/converter.go
# validate the openapi schema
.PHONY: openapi/validate
openapi/validate: bin/openapi-generator-cli
${OPENAPI_GENERATOR} validate -i api/openapi/model-registry.yaml
# generate the openapi server implementation
.PHONY: gen/openapi-server
gen/openapi-server: bin/openapi-generator-cli openapi/validate internal/server/openapi/api_model_registry_service.go
internal/server/openapi/api_model_registry_service.go: bin/openapi-generator-cli api/openapi/model-registry.yaml
ROOT_FOLDER=${PROJECT_PATH} ./scripts/gen_openapi_server.sh
# generate the openapi schema model and client
.PHONY: gen/openapi
gen/openapi: bin/openapi-generator-cli openapi/validate pkg/openapi/client.go
pkg/openapi/client.go: bin/openapi-generator-cli api/openapi/model-registry.yaml clean-pkg-openapi
${OPENAPI_GENERATOR} generate \
-i api/openapi/model-registry.yaml -g go -o pkg/openapi --package-name openapi \
--ignore-file-override ./.openapi-generator-ignore --additional-properties=isGoSubmodule=true,enumClassPrefix=true,useOneOfDiscriminatorLookup=true
gofmt -w pkg/openapi
.PHONY: vet
vet:
${GO} vet ./...
.PHONY: clean-pkg-openapi
while IFS= read -r file; do rm -f "pkg/openapi/$file"; done < pkg/openapi/.openapi-generator/FILES
.PHONY: clean clean-pkg-openapi
clean:
rm -Rf ./model-registry internal/ml_metadata/proto/*.go internal/converter/generated/*.go internal/server/openapi/api_model_registry_service.go
.PHONY: clean/odh
clean/odh:
rm -Rf ./model-registry
bin/protoc:
./scripts/install_protoc.sh
bin/go-enum:
GOBIN=$(PROJECT_BIN) ${GO} install github.com/searKing/golang/tools/[email protected]
bin/protoc-gen-go:
GOBIN=$(PROJECT_BIN) ${GO} install google.golang.org/protobuf/cmd/[email protected]
bin/protoc-gen-go-grpc:
GOBIN=$(PROJECT_BIN) ${GO} install google.golang.org/grpc/cmd/[email protected]
GOLANGCI_LINT ?= ${PROJECT_BIN}/golangci-lint
bin/golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_BIN) v1.61.0
GOVERTER ?= ${PROJECT_BIN}/goverter
bin/goverter:
GOBIN=$(PROJECT_PATH)/bin ${GO} install github.com/jmattheis/goverter/cmd/[email protected]
OPENAPI_GENERATOR ?= ${PROJECT_BIN}/openapi-generator-cli
NPM ?= "$(shell which npm)"
bin/openapi-generator-cli:
ifeq (, $(shell which ${NPM} 2> /dev/null))
@echo "npm is not available please install it to be able to install openapi-generator"
exit 1
endif
ifeq (, $(shell which ${PROJECT_BIN}/openapi-generator-cli 2> /dev/null))
@{ \
set -e ;\
mkdir -p ${PROJECT_BIN} ;\
mkdir -p ${PROJECT_BIN}/openapi-generator-installation ;\
cd ${PROJECT_BIN} ;\
${NPM} install -g --prefix ${PROJECT_BIN}/openapi-generator-installation @openapitools/openapi-generator-cli ;\
ln -s openapi-generator-installation/bin/openapi-generator-cli openapi-generator-cli ;\
}
endif
.PHONY: clean/deps
clean/deps:
rm -Rf bin/*
.PHONY: deps
deps: bin/protoc bin/go-enum bin/protoc-gen-go bin/protoc-gen-go-grpc bin/golangci-lint bin/goverter bin/openapi-generator-cli
.PHONY: vendor
vendor:
${GO} mod vendor
# WARNING: DO NOT DELETE THIS TARGET, USED BY Dockerfile!!!
.PHONY: build/prepare
build/prepare: gen vet lint
# WARNING: DO NOT DELETE THIS TARGET, USED BY Dockerfile!!!
.PHONY: build/compile
build/compile:
${GO} build -buildvcs=false
# WARNING: DO NOT EDIT THIS TARGET DIRECTLY!!!
# Use build/prepare to add build prerequisites
# Use build/compile to add/edit go source compilation
# WARNING: Editing this target directly WILL affect the Dockerfile image build!!!
.PHONY: build
build: build/prepare build/compile
.PHONY: build/odh
build/odh: vet
${GO} build -buildvcs=false
.PHONY: gen
gen: deps gen/grpc gen/openapi gen/openapi-server gen/converter
${GO} generate ./...
.PHONY: lint
lint:
${GOLANGCI_LINT} run main.go
${GOLANGCI_LINT} run cmd/... internal/... ./pkg/...
.PHONY: test
test: gen
${GO} test ./internal/... ./pkg/...
.PHONY: test-nocache
test-nocache: gen
${GO} test ./internal/... ./pkg/... -count=1
.PHONY: test-cover
test-cover: gen
${GO} test ./internal/... ./pkg/... -coverprofile=coverage.txt
${GO} tool cover -html=coverage.txt -o coverage.html
.PHONY: run/proxy
run/proxy: gen
${GO} run main.go proxy --logtostderr=true
.PHONY: proxy
proxy: build
./model-registry proxy --logtostderr=true
# login to docker
.PHONY: docker/login
docker/login:
ifdef IMG_REGISTRY
$(DOCKER) login -u "${DOCKER_USER}" -p "${DOCKER_PWD}" "${IMG_REGISTRY}"
else
$(DOCKER) login -u "${DOCKER_USER}" -p "${DOCKER_PWD}"
endif
# build docker image
.PHONY: image/build
image/build:
${DOCKER} build ${BUILD_PATH} -f ${DOCKERFILE} -t ${IMG}:$(IMG_VERSION)
# build docker image using buildx
# PLATFORMS defines the target platforms for the model registry image be built to provide support to multiple
# architectures. (i.e. make docker-buildx). To use this option you need to:
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: image/buildx
image/buildx:
ifeq ($(DOCKER),docker)
# docker uses builder containers
- $(DOCKER) buildx rm model-registry-builder
$(DOCKER) buildx create --use --name model-registry-builder --platform=$(PLATFORMS)
$(DOCKER) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f ${DOCKERFILE} .
$(DOCKER) buildx rm model-registry-builder
else ifeq ($(DOCKER),podman)
# podman uses image manifests
$(DOCKER) manifest create -a ${IMG}
$(DOCKER) buildx build --platform=$(PLATFORMS) --manifest ${IMG} -f ${DOCKERFILE} .
$(DOCKER) manifest push ${IMG}
$(DOCKER) manifest rm ${IMG}
else
$(error Unsupported container tool $(DOCKER))
endif
# push docker image
.PHONY: image/push
image/push:
${DOCKER} push ${IMG}:$(IMG_VERSION)
all: model-registry