forked from nuclio/nuclio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
401 lines (317 loc) · 13 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# Copyright 2017 The Nuclio 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.
GO_VERSION := $(shell go version | cut -d " " -f 3)
GOPATH ?= $(shell go env GOPATH)
OS_NAME = $(shell uname)
# upstream repo
NUCLIO_DOCKER_REPO := quay.io/nuclio
# get default os / arch from go env
NUCLIO_DEFAULT_OS := $(shell go env GOOS)
NUCLIO_DEFAULT_ARCH := $(shell go env GOARCH)
ifeq ($(OS_NAME), Linux)
NUCLIO_DEFAULT_TEST_HOST := $(shell docker network inspect bridge | grep "Gateway" | grep -o '"[^"]*"$$')
# On EC2 we don't have gateway, use default
ifeq ($(NUCLIO_DEFAULT_TEST_HOST),)
NUCLIO_DEFAULT_TEST_HOST := "172.17.0.1"
endif
else
NUCLIO_DEFAULT_TEST_HOST := "docker.for.mac.host.internal"
endif
NUCLIO_OS := $(if $(NUCLIO_OS),$(NUCLIO_OS),$(NUCLIO_DEFAULT_OS))
NUCLIO_ARCH := $(if $(NUCLIO_ARCH),$(NUCLIO_ARCH),$(NUCLIO_DEFAULT_ARCH))
NUCLIO_LABEL := $(if $(NUCLIO_LABEL),$(NUCLIO_LABEL),latest)
NUCLIO_TEST_HOST := $(if $(NUCLIO_TEST_HOST),$(NUCLIO_TEST_HOST),$(NUCLIO_DEFAULT_TEST_HOST))
NUCLIO_VERSION_GIT_COMMIT = $(shell git rev-parse HEAD)
NUCLIO_VERSION_INFO = {\"git_commit\": \"$(NUCLIO_VERSION_GIT_COMMIT)\", \
\"label\": \"$(NUCLIO_LABEL)\", \
\"os\": \"$(NUCLIO_OS)\", \
\"arch\": \"$(NUCLIO_ARCH)\"}
# Dockerized tests variables - not available for changes
NUCLIO_DOCKER_TEST_DOCKERFILE_PATH := test/docker/Dockerfile
NUCLIO_DOCKER_TEST_TAG := nuclio/tester
# Add labels to docker images
NUCLIO_DOCKER_LABELS = --label nuclio.version_info="$(NUCLIO_VERSION_INFO)"
NUCLIO_DOCKER_IMAGE_TAG=$(NUCLIO_LABEL)-$(NUCLIO_ARCH)
# Link flags
GO_LINK_FLAGS ?= -s -w
GO_LINK_FLAGS_INJECT_VERSION := $(GO_LINK_FLAGS) -X github.com/nuclio/nuclio/pkg/version.gitCommit=$(NUCLIO_VERSION_GIT_COMMIT) \
-X github.com/nuclio/nuclio/pkg/version.label=$(NUCLIO_LABEL) \
-X github.com/nuclio/nuclio/pkg/version.os=$(NUCLIO_OS) \
-X github.com/nuclio/nuclio/pkg/version.arch=$(NUCLIO_ARCH)
# inject version info as file
NUCLIO_BUILD_ARGS_VERSION_INFO_FILE = --build-arg NUCLIO_VERSION_INFO_FILE_CONTENTS="$(NUCLIO_VERSION_INFO)"
# Docker client version to be used
DOCKER_CLI_VERSION := 18.09.6
#
# Must be first target
#
all:
$(error Please pick a target (run "make targets" to view targets))
#
# Version resources
#
helm-publish:
$(eval HELM_PUBLISH_COMMIT_MESSAGE := "Releasing chart $(shell helm inspect chart hack/k8s/helm/nuclio | yq r - version)")
@echo Fetching branch
@rm -rf /tmp/nuclio-helm
@git clone -b gh-pages --single-branch [email protected]:nuclio/nuclio.git /tmp/nuclio-helm
@echo Creating package and updating index
@helm package -d /tmp/nuclio-helm/charts hack/k8s/helm/nuclio
@cd /tmp/nuclio-helm/charts && helm repo index --merge index.yaml --url https://nuclio.github.io/nuclio/charts/ .
@echo Publishing
@cd /tmp/nuclio-helm/charts && git add --all && git commit -m $(HELM_PUBLISH_COMMIT_MESSAGE) && git push origin
@echo Done
#
# Build helpers
#
# tools get built with the specified OS/arch and inject version
GO_BUILD_TOOL_WORKDIR = /go/src/github.com/nuclio/nuclio
GO_BUILD_TOOL_DOCKER = docker build -f hack/docker/tool-builder/Dockerfile -t nuclio-tool-builder:$(NUCLIO_LABEL) .
GO_BUILD_NUCTL = docker run \
--volume $(GOPATH)/bin:/go/bin \
--env GOOS=$(NUCLIO_OS) \
--env GOARCH=$(NUCLIO_ARCH) \
nuclio-tool-builder:$(NUCLIO_LABEL) \
go build -a \
-installsuffix cgo \
-ldflags="$(GO_LINK_FLAGS_INJECT_VERSION)"
#
# Rules
#
build: docker-images tools
@echo Done.
DOCKER_IMAGES_RULES = \
controller \
dashboard \
processor \
autoscaler \
dlx \
handler-builder-golang-onbuild \
handler-builder-java-onbuild \
handler-builder-ruby-onbuild \
handler-builder-python-onbuild \
handler-builder-dotnetcore-onbuild \
handler-builder-nodejs-onbuild
docker-images: ensure-gopath $(DOCKER_IMAGES_RULES)
@echo Done.
tools: ensure-gopath nuctl
@echo Done.
push-docker-images:
for image in $(IMAGES_TO_PUSH); do \
docker push $$image ; \
done
@echo Done.
print-docker-images:
for image in $(IMAGES_TO_PUSH); do \
echo $$image ; \
done
#
# Tools
#
NUCTL_BIN_NAME = nuctl-$(NUCLIO_LABEL)-$(NUCLIO_OS)-$(NUCLIO_ARCH)
NUCTL_TARGET = $(GOPATH)/bin/nuctl
nuctl: ensure-gopath
$(GO_BUILD_TOOL_DOCKER)
$(GO_BUILD_NUCTL) -o /go/bin/$(NUCTL_BIN_NAME) cmd/nuctl/main.go
@rm -f $(NUCTL_TARGET)
@ln -sF $(GOPATH)/bin/$(NUCTL_BIN_NAME) $(NUCTL_TARGET)
processor: ensure-gopath
docker build --file cmd/processor/Dockerfile --tag $(NUCLIO_DOCKER_REPO)/processor:$(NUCLIO_DOCKER_IMAGE_TAG) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_REPO)/processor:$(NUCLIO_DOCKER_IMAGE_TAG)
#
# Dockerized services
#
# Controller
NUCLIO_DOCKER_CONTROLLER_IMAGE_NAME=$(NUCLIO_DOCKER_REPO)/controller:$(NUCLIO_DOCKER_IMAGE_TAG)
controller: ensure-gopath
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file cmd/controller/Dockerfile \
--tag $(NUCLIO_DOCKER_CONTROLLER_IMAGE_NAME) \
$(NUCLIO_DOCKER_LABELS) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_CONTROLLER_IMAGE_NAME)
# Dashboard
NUCLIO_DOCKER_DASHBOARD_IMAGE_NAME=$(NUCLIO_DOCKER_REPO)/dashboard:$(NUCLIO_DOCKER_IMAGE_TAG)
dashboard: ensure-gopath
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--build-arg DOCKER_CLI_VERSION=$(DOCKER_CLI_VERSION) \
--file cmd/dashboard/docker/Dockerfile \
--tag $(NUCLIO_DOCKER_DASHBOARD_IMAGE_NAME) \
$(NUCLIO_DOCKER_LABELS) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_DASHBOARD_IMAGE_NAME)
# Scaler
NUCLIO_DOCKER_SCALER_IMAGE_NAME=$(NUCLIO_DOCKER_REPO)/autoscaler:$(NUCLIO_DOCKER_IMAGE_TAG)
autoscaler: ensure-gopath
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file cmd/autoscaler/Dockerfile \
--tag $(NUCLIO_DOCKER_SCALER_IMAGE_NAME) \
$(NUCLIO_DOCKER_LABELS) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_SCALER_IMAGE_NAME)
# Dlx
NUCLIO_DOCKER_DLX_IMAGE_NAME=$(NUCLIO_DOCKER_REPO)/dlx:$(NUCLIO_DOCKER_IMAGE_TAG)
dlx: ensure-gopath
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file cmd/dlx/Dockerfile \
--tag $(NUCLIO_DOCKER_DLX_IMAGE_NAME) \
$(NUCLIO_DOCKER_LABELS) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_DLX_IMAGE_NAME)
#
# Onbuild images
#
# Python
NUCLIO_DOCKER_HANDLER_BUILDER_PYTHON_ONBUILD_IMAGE_NAME=\
$(NUCLIO_DOCKER_REPO)/handler-builder-python-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG)
PIP_REQUIRE_VIRTUALENV=false
handler-builder-python-onbuild:
# `--exists-action i` means to ignore and skip download if whl already exists
pip download --no-binary msgpack -d pkg/processor/runtime/python/py/whl --exists-action i -r pkg/processor/runtime/python/py/requirements.txt
docker build --build-arg NUCLIO_ARCH=$(NUCLIO_ARCH) --build-arg NUCLIO_LABEL=$(NUCLIO_LABEL) \
--file pkg/processor/build/runtime/python/docker/onbuild/Dockerfile \
--tag $(NUCLIO_DOCKER_HANDLER_BUILDER_PYTHON_ONBUILD_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_BUILDER_PYTHON_ONBUILD_IMAGE_NAME)
# Go
NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_IMAGE_NAME=\
$(NUCLIO_DOCKER_REPO)/handler-builder-golang-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG)
NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_ALPINE_IMAGE_NAME=\
$(NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_IMAGE_NAME)-alpine
handler-builder-golang-onbuild:
docker build --build-arg NUCLIO_ARCH=$(NUCLIO_ARCH) --build-arg NUCLIO_LABEL=$(NUCLIO_LABEL) \
--file pkg/processor/build/runtime/golang/docker/onbuild/Dockerfile \
--tag $(NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_IMAGE_NAME) .
docker build --build-arg NUCLIO_ARCH=$(NUCLIO_ARCH) --build-arg NUCLIO_LABEL=$(NUCLIO_LABEL) \
--file pkg/processor/build/runtime/golang/docker/onbuild/Dockerfile.alpine \
--tag $(NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_ALPINE_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_IMAGE_NAME) \
$(NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_ALPINE_IMAGE_NAME)
# Pypy
NUCLIO_DOCKER_PROCESSOR_PYPY_JESSIE_IMAGE_NAME=$(NUCLIO_DOCKER_REPO)/processor-pypy2-5.9-jessie:$(NUCLIO_DOCKER_IMAGE_TAG)
processor-pypy:
docker build $(NUCLIO_BUILD_ARGS) \
--file pkg/processor/build/runtime/pypy/docker/Dockerfile.processor-pypy \
--build-arg NUCLIO_PYPY_VERSION=2-5.9 \
--build-arg NUCLIO_PYPY_OS=jessie \
--tag $(NUCLIO_DOCKER_PROCESSOR_PYPY_JESSIE_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_PROCESSOR_PYPY_JESSIE_IMAGE_NAME)
NUCLIO_DOCKER_HANDLER_BUILDER_PYPY_ONBUILD_IMAGE_NAME=$(NUCLIO_DOCKER_REPO)/handler-pypy2-5.9-jessie:$(NUCLIO_DOCKER_IMAGE_TAG)
handler-pypy:
docker build \
--file pkg/processor/build/runtime/pypy/docker/Dockerfile.handler-pypy \
--build-arg NUCLIO_DOCKER_IMAGE_TAG=$(NUCLIO_DOCKER_IMAGE_TAG) \
--tag $(NUCLIO_DOCKER_HANDLER_BUILDER_PYPY_ONBUILD_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_BUILDER_PYPY_ONBUILD_IMAGE_NAME)
# NodeJS
NUCLIO_DOCKER_HANDLER_BUILDER_NODEJS_ONBUILD_IMAGE_NAME=\
$(NUCLIO_DOCKER_REPO)/handler-builder-nodejs-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG)
handler-builder-nodejs-onbuild:
docker build --build-arg NUCLIO_ARCH=$(NUCLIO_ARCH) --build-arg NUCLIO_LABEL=$(NUCLIO_LABEL) \
--file pkg/processor/build/runtime/nodejs/docker/onbuild/Dockerfile \
--tag $(NUCLIO_DOCKER_HANDLER_BUILDER_NODEJS_ONBUILD_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_BUILDER_NODEJS_ONBUILD_IMAGE_NAME)
# Ruby
NUCLIO_DOCKER_HANDLER_BUILDER_RUBY_ONBUILD_IMAGE_NAME=\
$(NUCLIO_DOCKER_REPO)/handler-builder-ruby-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG)
handler-builder-ruby-onbuild:
docker build --build-arg NUCLIO_ARCH=$(NUCLIO_ARCH) --build-arg NUCLIO_LABEL=$(NUCLIO_LABEL) \
--file pkg/processor/build/runtime/ruby/docker/onbuild/Dockerfile \
--tag $(NUCLIO_DOCKER_HANDLER_BUILDER_RUBY_ONBUILD_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_BUILDER_RUBY_ONBUILD_IMAGE_NAME)
# dotnet core
NUCLIO_DOCKER_HANDLER_BUILDER_DOTNETCORE_ONBUILD_IMAGE_NAME=$(NUCLIO_DOCKER_REPO)/handler-builder-dotnetcore-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG)
NUCLIO_ONBUILD_DOTNETCORE_DOCKERFILE_PATH = pkg/processor/build/runtime/dotnetcore/docker/onbuild/Dockerfile
handler-builder-dotnetcore-onbuild: processor
docker build --build-arg NUCLIO_ARCH=$(NUCLIO_ARCH) --build-arg NUCLIO_LABEL=$(NUCLIO_LABEL) \
-f $(NUCLIO_ONBUILD_DOTNETCORE_DOCKERFILE_PATH) \
-t $(NUCLIO_DOCKER_HANDLER_BUILDER_DOTNETCORE_ONBUILD_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_BUILDER_DOTNETCORE_ONBUILD_IMAGE_NAME)
# java
NUCLIO_DOCKER_HANDLER_BUILDER_JAVA_ONBUILD_IMAGE_NAME=\
$(NUCLIO_DOCKER_REPO)/handler-builder-java-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG)
handler-builder-java-onbuild:
docker build --build-arg NUCLIO_ARCH=$(NUCLIO_ARCH) --build-arg NUCLIO_LABEL=$(NUCLIO_LABEL) \
--file pkg/processor/build/runtime/java/docker/onbuild/Dockerfile \
--tag $(NUCLIO_DOCKER_HANDLER_BUILDER_JAVA_ONBUILD_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_BUILDER_JAVA_ONBUILD_IMAGE_NAME)
#
# Testing
#
.PHONY: lint
lint: ensure-gopath
@echo Installing linters...
go get -u github.com/pavius/impi/cmd/impi
go get -u gopkg.in/alecthomas/gometalinter.v2
@$(GOPATH)/bin/gometalinter.v2 --install
@echo Verifying imports...
$(GOPATH)/bin/impi \
--local github.com/nuclio/nuclio/ \
--scheme stdLocalThirdParty \
--skip pkg/platform/kube/apis \
--skip pkg/platform/kube/client \
./cmd/... ./pkg/...
@echo Linting...
@$(GOPATH)/bin/gometalinter.v2 \
--deadline=500s \
--disable-all \
--enable-gc \
--enable=deadcode \
--enable=goconst \
--enable=gofmt \
--enable=golint \
--enable=gosimple \
--enable=ineffassign \
--enable=interfacer \
--enable=misspell \
--enable=staticcheck \
--enable=unconvert \
--enable=varcheck \
--enable=vet \
--enable=vetshadow \
--enable=errcheck \
--exclude="_test.go" \
--exclude="comment on" \
--exclude="error should be the last" \
--exclude="should have comment" \
--skip=pkg/platform/kube/apis \
--skip=pkg/platform/kube/client \
./cmd/... ./pkg/...
@echo Done.
.PHONY: test-undockerized
test-undockerized: ensure-gopath
go test -v ./cmd/... ./pkg/... -p 1
.PHONY: test
test: ensure-gopath
docker build \
--build-arg DOCKER_CLI_VERSION=$(DOCKER_CLI_VERSION) \
--file $(NUCLIO_DOCKER_TEST_DOCKERFILE_PATH) \
--tag $(NUCLIO_DOCKER_TEST_TAG) .
docker run --rm --volume /var/run/docker.sock:/var/run/docker.sock \
--volume $(shell pwd):$(GO_BUILD_TOOL_WORKDIR) \
--volume /tmp:/tmp \
--workdir /go/src/github.com/nuclio/nuclio \
--env NUCLIO_TEST_HOST=$(NUCLIO_TEST_HOST) \
$(NUCLIO_DOCKER_TEST_TAG) \
/bin/bash -c "make test-undockerized"
.PHONY: test-python
test-python:
docker build -f pkg/processor/runtime/python/test/Dockerfile.py3-test .
docker build -f pkg/processor/runtime/python/test/Dockerfile.py2-test .
.PHONY: test-short
test-short: ensure-gopath
go test -v ./cmd/... ./pkg/... -short
.PHONY: ensure-gopath
ensure-gopath:
ifndef GOPATH
$(error GOPATH must be set)
endif
.PHONY: targets
targets:
awk -F: '/^[^ \t="]+:/ && !/PHONY/ {print $$1}' Makefile | sort -u