-
Notifications
You must be signed in to change notification settings - Fork 77
/
Makefile
103 lines (81 loc) · 3.51 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
# Image URL to use all building/pushing image targets
PADDLEJOB_IMG ?= registry.baidubce.com/paddleflow-public/paddlecloud/paddlejob
SAMPLESET_IMG ?= registry.baidubce.com/paddleflow-public/paddlecloud/sampleset
RUNTIME_IMG ?= registry.baidubce.com/paddleflow-public/paddlecloud/runtime
SERVING_IMG ?= registry.baidubce.com/paddleflow-public/paddlecloud/serving
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:maxDescLen=0,generateEmbeddedObjectMeta=true,trivialVersions=true,preserveUnknownFields=false"
# Set version
VERSION=v0.4.0
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Run tests
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
# test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.11.0/hack/setup-envtest.sh
# source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Build all controller manager docker images
docker-build-all: docker-build-paddlejob docker-build-sampleset docker-build-runtime docker-build-serving
# Build paddlejob controller image
docker-build-paddlejob: test
docker build . -f docker/Dockerfile.paddlejob -t ${PADDLEJOB_IMG}:${VERSION}
# Build sampleset controller image
docker-build-sampleset: test
docker build . --build-arg RUNTIME_IMG=${RUNTIME_IMG} --build-arg GIT_VERSION=${VERSION} \
-f docker/Dockerfile.sampleset -t ${SAMPLESET_IMG}:${VERSION}
docker-build-runtime: test
docker build . -f docker/Dockerfile.runtime -t ${RUNTIME_IMG}:${VERSION}
docker-build-serving: test
docker build . -f docker/Dockerfile.serving -t ${SERVING_IMG}:${VERSION}
# Push all docker images
docker-push-all: docker-push-paddlejob docker-push-sampleset docker-push-runtime docker-push-serving
# Push the docker image
docker-push-paddlejob:
docker push ${PADDLEJOB_IMG}:${VERSION}
# Push the sampleset docker image
docker-push-sampleset:
docker push ${SAMPLESET_IMG}:${VERSION}
docker-push-runtime:
docker push ${RUNTIME_IMG}:${VERSION}
docker-push-serving:
docker push ${SERVING_IMG}:${VERSION}
update-api-doc:
bash docs/api-doc-gen/gen_api_doc.sh
# Download controller-gen locally if necessary
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen:
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1)
# Download kustomize locally if necessary
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize:
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef