forked from kubeflow/model-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
205 lines (163 loc) · 6.57 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
# useful paths
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
PROJECT_BIN := $(PROJECT_PATH)/bin
# add tools bin directory
PATH := $(PROJECT_BIN):$(PATH)
MLMD_VERSION ?= 1.14.0
# docker executable
DOCKER ?= docker
# default Dockerfile
DOCKERFILE ?= Dockerfile
# container registry
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
IMG := ${IMG_REGISTRY}/$(IMG_ORG)/$(IMG_REPO)
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/opendatahub-io/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/opendatahub-io/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/opendatahub-io/model-registry/internal/ml_metadata/proto";#' metadata_store_service.proto
internal/ml_metadata/proto/%.pb.go: api/grpc/ml_metadata/proto/%.proto
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/opendatahub-io/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
@if git diff --cached --name-only | grep -q "api/openapi/model-registry.yaml" || \
git diff --name-only | grep -q "api/openapi/model-registry.yaml" || \
[ -n "${FORCE_SERVER_GENERATION}" ]; then \
ROOT_FOLDER="." ./scripts/gen_openapi_server.sh; \
else \
echo "INFO api/openapi/model-registry.yaml is not staged or modified, will not re-generate server"; \
fi
# 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
rm -rf 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
clean:
rm -Rf ./model-registry internal/ml_metadata/proto/*.go internal/converter/generated/*.go pkg/openapi
.PHONY: clean/odh
clean/odh:
rm -Rf ./model-registry
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.54.2
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/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
.PHONY: build
build: gen vet lint
go build
.PHONY: build/odh
build/odh: vet
go build
.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:
$(DOCKER) login -u "${DOCKER_USER}" -p "${DOCKER_PWD}" "${IMG_REGISTRY}"
# build docker image
.PHONY: image/build
image/build:
${DOCKER} build . -f ${DOCKERFILE} -t ${IMG}:$(IMG_VERSION)
# push docker image
.PHONY: image/push
image/push:
${DOCKER} push ${IMG}:$(IMG_VERSION)
all: model-registry