forked from kubeflow/kfctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·241 lines (193 loc) · 9.66 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
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
GCLOUD_PROJECT ?= kubeflow-images-public
GOLANG_VERSION ?= 1.12.7
GOPATH ?= $(HOME)/go
# To build without the cache set the environment variable
# export DOCKER_BUILD_OPTS=--no-cache
KFCTL_IMG ?= gcr.io/$(GCLOUD_PROJECT)/kfctl
TAG ?= $(eval TAG := $(shell git describe --tags --long --always))$(TAG)
REPO ?= $(shell echo $$(cd ../kubeflow && git config --get remote.origin.url) | sed 's/git@\(.*\):\(.*\).git$$/https:\/\/\1\/\2/')
BRANCH ?= $(shell cd ../kubeflow && git branch | grep '^*' | awk '{print $$2}')
KFCTL_TARGET ?= kfctl
MOUNT_KUBE ?= -v $(HOME)/.kube:/root/.kube
MOUNT_GCP ?= -v $(HOME)/.config:/root/.config
# set to -V
VERBOSE ?=
PLUGINS_ENVIRONMENT ?= $(GOPATH)/src/github.com/kubeflow/kfctl/bin
export GO111MODULE = on
export GO = go
# Location of junit file
JUNIT_FILE ?= /tmp/report.xml
%.so:
cd cmd/plugins/$* && \
${GO} build -i -gcflags '-N -l' -o ../../../bin/$*.so -buildmode=plugin $*.go
%.init:
@echo kfctl init test/$* $(VERBOSE) --platform $* --project $(GCLOUD_PROJECT) --version master && \
PLUGINS_ENVIRONMENT=$(PLUGINS_ENVIRONMENT) kfctl init $(PWD)/test/$* $(VERBOSE) --platform $* --project $(GCLOUD_PROJECT) --version master
%.init-no-platform:
@echo kfctl init test/$* $(VERBOSE) --version master && \
kfctl init $(PWD)/test/$* $(VERBOSE) --version master
%.generate:
@echo kfctl generate all $(VERBOSE) '(--platform '$*')' && \
cd test/$* && \
PLUGINS_ENVIRONMENT=$(PLUGINS_ENVIRONMENT) kfctl generate all $(VERBOSE) --mount-local --email gcp-deploy@$(GCLOUD_PROJECT).iam.gserviceaccount.com
%.md:
all: build
auth:
gcloud auth configure-docker
# Run go fmt against code
fmt:
@${GO} fmt ./config ./cmd/... ./pkg/...
# Run go vet against code
vet:
@${GO} vet ./config ./cmd/... ./pkg/...
generate:
@${GO} generate ./config ./pkg/apis/apps/kfdef/... ./pkg/utils/... ./pkg/kfapp/minikube ./pkg/kfapp/gcp/... ./cmd/kfctl/...
${GOPATH}/bin/deepcopy-gen:
GO111MODULE=off ${GO} get k8s.io/code-generator/cmd/deepcopy-gen
config/zz_generated.deepcopy.go: config/types.go
${GOPATH}/bin/deepcopy-gen -i github.com/kubeflow/kfctl/v3/config -O zz_generated.deepcopy && \
mv ${GOPATH}/src/github.com/kubeflow/kfctl/v3/config/zz_generated.deepcopy.go config/ && rm -rf v3
pkg/apis/apps/kfdef/v1alpha1/zz_generated.deepcopy.go: pkg/apis/apps/kfdef/v1alpha1/application_types.go
${GOPATH}/bin/deepcopy-gen -i github.com/kubeflow/kfctl/v3/pkg/apis/apps/kfdef/... -O zz_generated.deepcopy && \
mv ${GOPATH}/src/github.com/kubeflow/kfctl/v3/pkg/apis/apps/kfdef/v1alpha1/zz_generated.deepcopy.go pkg/apis/apps/kfdef/v1alpha1/ && rm -rf v3
pkg/apis/apps/kfdef/v1beta1/zz_generated.deepcopy.go: pkg/apis/apps/kfdef/v1beta1/application_types.go
${GOPATH}/bin/deepcopy-gen -i github.com/kubeflow/kfctl/v3/pkg/apis/apps/kfdef/... -O zz_generated.deepcopy && \
mv ${GOPATH}/src/github.com/kubeflow/kfctl/v3/pkg/apis/apps/kfdef/v1beta1/zz_generated.deepcopy.go pkg/apis/apps/kfdef/v1beta1/ && rm -rf v3
pkg/apis/apps/plugins/gcp/v1alpha1/zz_generated.deepcopy.go: pkg/apis/apps/plugins/gcp/v1alpha1/types.go
${GOPATH}/bin/deepcopy-gen -i github.com/kubeflow/kfctl/v3/pkg/apis/apps/plugins/gcp/... -O zz_generated.deepcopy && \
mv ${GOPATH}/src/github.com/kubeflow/kfctl/v3/pkg/apis/apps/plugins/gcp/v1alpha1/zz_generated.deepcopy.go pkg/apis/apps/plugins/gcp/v1alpha1/ && rm -rf v3
pkg/apis/apps/plugins/aws/v1alpha1/zz_generated.deepcopy.go: pkg/apis/apps/plugins/aws/v1alpha1/types.go
${GOPATH}/bin/deepcopy-gen -i github.com/kubeflow/kfctl/v3/pkg/apis/apps/plugins/aws/... -O zz_generated.deepcopy && \
mv ${GOPATH}/src/github.com/kubeflow/kfctl/v3/pkg/apis/apps/plugins/aws/v1alpha1/zz_generated.deepcopy.go pkg/apis/apps/plugins/aws/v1alpha1/ && rm -rf v3
pkg/kfconfig/zz_generated.deepcopy.go: pkg/kfconfig/types.go
${GOPATH}/bin/deepcopy-gen -i github.com/kubeflow/kfctl/v3/pkg/kfconfig/... -O zz_generated.deepcopy && \
mv ${GOPATH}/src/github.com/kubeflow/kfctl/v3/pkg/kfconfig/zz_generated.deepcopy.go pkg/kfconfig/ && rm -rf v3
pkg/kfconfig/awsplugin/zz_generated.deepcopy.go: pkg/kfconfig/awsplugin/types.go
${GOPATH}/bin/deepcopy-gen -i github.com/kubeflow/kfctl/v3/pkg/kfconfig/awsplugin/... -O zz_generated.deepcopy && \
mv ${GOPATH}/src/github.com/kubeflow/kfctl/v3/pkg/kfconfig/awsplugin/zz_generated.deepcopy.go pkg/kfconfig/awsplugin/ && rm -rf v3
pkg/kfconfig/gcpplugin/zz_generated.deepcopy.go: pkg/kfconfig/gcpplugin/types.go
${GOPATH}/bin/deepcopy-gen -i github.com/kubeflow/kfctl/v3/pkg/kfconfig/gcpplugin/... -O zz_generated.deepcopy && \
mv ${GOPATH}/src/github.com/kubeflow/kfctl/v3/pkg/kfconfig/gcpplugin/zz_generated.deepcopy.go pkg/kfconfig/gcpplugin/ && rm -rf v3
deepcopy: ${GOPATH}/bin/deepcopy-gen config/zz_generated.deepcopy.go \
pkg/apis/apps/kfdef/v1alpha1/zz_generated.deepcopy.go \
pkg/apis/apps/kfdef/v1beta1/zz_generated.deepcopy.go \
pkg/apis/apps/plugins/gcp/v1alpha1/zz_generated.deepcopy.go \
pkg/apis/apps/plugins/aws/v1alpha1/zz_generated.deepcopy.go \
pkg/kfconfig/zz_generated.deepcopy.go \
pkg/kfconfig/awsplugin/zz_generated.deepcopy.go \
pkg/kfconfig/gcpplugin/zz_generated.deepcopy.go
build: build-kfctl
build-kfctl: deepcopy generate fmt vet
${GO} build -i -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/kfctl cmd/kfctl/main.go
# Release tarballs suitable for upload to GitHub release pages
build-kfctl-tgz: build-kfctl
chmod a+rx ./bin/kfctl
rm -f bin/*.tgz
cd bin && tar -cvzf kfctl_$(TAG)_linux.tar.gz ./kfctl
cp -f ./bin/kfctl_$(TAG)_linux.tar.gz ./bin/kfctl_$(TAG)_darwin.tar.gz
# push the releases to a GitHub page
push-to-github-release: build-kfctl-tgz
github-release upload \
--user kubeflow \
--repo kubeflow \
--tag $(TAG) \
--name "kfctl_$(TAG)_linux.tar.gz" \
--file bin/kfctl_$(TAG)_linux.tar.gz
github-release upload \
--user kubeflow \
--repo kubeflow \
--tag $(TAG) \
--name "kfctl_$(TAG)_darwin.tar.gz" \
--file bin/kfctl_$(TAG)_darwin.tar.gz
build-kfctl-container:
DOCKER_BUILDKIT=1 docker build \
--build-arg REPO="$(REPO)" \
--build-arg BRANCH=$(BRANCH) \
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
--build-arg VERSION=$(TAG) \
--target=$(KFCTL_TARGET) \
--tag $(KFCTL_IMG)/builder:$(TAG) .
@echo Built $(KFCTL_IMG)/builder:$(TAG)
mkdir -p bin
docker create \
--name=temp_kfctl_container \
$(KFCTL_IMG)/builder:$(TAG)
docker cp temp_kfctl_container:/usr/local/bin/kfctl ./bin/kfctl
docker rm temp_kfctl_container
@echo Exported kfctl binary to bin/kfctl
# build containers using GCLOUD_PROJECT
build-gcb:
gcloud --project=$(GCLOUD_PROJECT)\
builds submit \
--machine-type=n1-highcpu-32 \
--substitutions=TAG_NAME=$(TAG)
--config=cloudbuild.yaml .
# Build but don't attach the latest tag. This allows manual testing/inspection of the image
# first.
push: build
docker push $(BOOTSTRAPPER_IMG):$(TAG)
@echo Pushed $(BOOTSTRAPPER_IMG):$(TAG)
push-latest: push
gcloud container images add-tag --quiet $(BOOTSTRAPPER_IMG):$(TAG) $(BOOTSTRAPPER_IMG):latest --verbosity=info
echo created $(BOOTSTRAPPER_IMG):latest
push-kfctl-container: build-kfctl-container
docker push $(KFCTL_IMG):$(TAG)
@echo Pushed $(KFCTL_IMG):$(TAG)
push-kfctl-container-latest: push-kfctl-container
gcloud container images add-tag --quiet $(KFCTL_IMG):$(TAG) $(KFCTL_IMG):latest --verbosity=info
@echo created $(KFCTL_IMG):latest
install: build-kfctl dockerfordesktop.so
@echo copying bin/kfctl to /usr/local/bin
@cp bin/kfctl /usr/local/bin
run-kfctl-container: build-kfctl-container
docker run $(MOUNT_KUBE) $(MOUNT_GCP) --entrypoint /bin/sh -it $(KFCTL_IMG):$(TAG)
#***************************************************************************************************
# Build a docker container that can be used to build kfctl
#
# The rules in this section are used to build the docker image that provides
# a suitable go build environment for kfctl
build-builder-container:
docker build \
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
--target=builder \
--tag $(KFCTL_IMG):$(TAG) .
@echo Built $(KFCTL_IMG):$(TAG)
# build containers using GCLOUD_PROJECT
build-builder-container-gcb:
gcloud --project=$(GCLOUD_PROJECT) \
builds submit \
--machine-type=n1-highcpu-32 \
--substitutions=TAG_NAME=$(TAG),_TARGET=builder \
--config=cloudbuild.yaml .
#***************************************************************************************************
clean:
rm -rf test && mkdir test
doc:
doctoc ./cmd/kfctl/README.md README.md k8sSpec/README.md developer_guide.md
#**************************************************************************************************
# rules to run unittests
#
test: build-kfctl
go test ./... -v
# Run the unittests and output a junit report for use with prow
test-junit: build-kfctl
echo Running tests ... junit_file=$(JUNIT_FILE)
go test ./... -v 2>&1 | go-junit-report > $(JUNIT_FILE)
#***************************************************************************************************
test-init: clean install dockerfordesktop.init minikube.init gcp.init none.init-no-platform
test-generate: test-init dockerfordesktop.generate minikube.generate gcp.generate none.generate
test-apply: test-generate dockerfordesktop.apply minikube.apply gcp.apply none.apply