forked from nuclio/nuclio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
392 lines (315 loc) · 12.9 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
# 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)
# 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_TAG := $(if $(NUCLIO_TAG),$(NUCLIO_TAG),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_TAG)\", \
\"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_TAG)
NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH=$(NUCLIO_TAG)-$(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_TAG) \
-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)"
#
# 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 run \
--volume $(shell pwd):$(GO_BUILD_TOOL_WORKDIR) \
--volume $(shell pwd)/../nuclio-sdk-go:$(GO_BUILD_TOOL_WORKDIR)/../nuclio-sdk-go \
--volume $(shell pwd)/../logger:$(GO_BUILD_TOOL_WORKDIR)/../logger \
--volume $(GOPATH)/bin:/go/bin \
--workdir $(GO_BUILD_TOOL_WORKDIR) \
--env GOOS=$(NUCLIO_OS) \
--env GOARCH=$(NUCLIO_ARCH) \
golang:1.9.2 \
go build -a \
-installsuffix cgo \
-ldflags="$(GO_LINK_FLAGS_INJECT_VERSION)"
#
# Rules
#
build: docker-images tools
@echo Done.
DOCKER_IMAGES_RULES = \
controller \
handler-builder-golang-onbuild \
user-jar-builder-java-onbuild \
handler-java \
processor-pypy \
handler-pypy \
handler-builder-java-onbuild \
playground \
dashboard \
processor-py \
processor-shell \
processor-pypy \
handler-pypy \
handler-nodejs \
handler-builder-dotnetcore-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_TAG)-$(NUCLIO_OS)-$(NUCLIO_ARCH)
NUCTL_TARGET = $(GOPATH)/bin/nuctl
nuctl: ensure-gopath
$(GO_BUILD_TOOL) -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/processor .
#
# Dockerized services
#
# Controller
NUCLIO_DOCKER_CONTROLLER_IMAGE_NAME=nuclio/controller:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
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)
# Playground
NUCLIO_DOCKER_PLAYGROUND_IMAGE_NAME=nuclio/playground:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
playground: ensure-gopath
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file cmd/playground/Dockerfile \
--tag $(NUCLIO_DOCKER_PLAYGROUND_IMAGE_NAME) \
$(NUCLIO_DOCKER_LABELS) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_PLAYGROUND_IMAGE_NAME)
# Dashboard
NUCLIO_DOCKER_DASHBOARD_IMAGE_NAME=nuclio/dashboard:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
dashboard: ensure-gopath
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file cmd/dashboard/Dockerfile \
--tag $(NUCLIO_DOCKER_DASHBOARD_IMAGE_NAME) \
$(NUCLIO_DOCKER_LABELS) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_DASHBOARD_IMAGE_NAME)
# Python
NUCLIO_PROCESSOR_PY_DOCKERFILE_PATH = pkg/processor/build/runtime/python/docker/processor-py/Dockerfile
NUCLIO_DOCKER_PROCESSOR_PY2_ALPINE_IMAGE_NAME=nuclio/processor-py2.7-alpine:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
NUCLIO_DOCKER_PROCESSOR_PY3_ALPINE_IMAGE_NAME=nuclio/processor-py3.6-alpine:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
NUCLIO_DOCKER_PROCESSOR_PY2_JESSIE_IMAGE_NAME=nuclio/processor-py2.7-jessie:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
NUCLIO_DOCKER_PROCESSOR_PY3_JESSIE_IMAGE_NAME=nuclio/processor-py3.6-jessie:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
processor-py: processor
# build python 2.7/alpine
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file ${NUCLIO_PROCESSOR_PY_DOCKERFILE_PATH} \
--build-arg NUCLIO_PYTHON_VERSION=2.7 \
--build-arg NUCLIO_PYTHON_OS=alpine3.6 \
--tag $(NUCLIO_DOCKER_PROCESSOR_PY2_ALPINE_IMAGE_NAME) .
# build python 3/alpine
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file ${NUCLIO_PROCESSOR_PY_DOCKERFILE_PATH} \
--build-arg NUCLIO_PYTHON_VERSION=3.6 \
--build-arg NUCLIO_PYTHON_OS=alpine3.6 \
--tag $(NUCLIO_DOCKER_PROCESSOR_PY3_ALPINE_IMAGE_NAME) .
# build python 2/jesse
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file ${NUCLIO_PROCESSOR_PY_DOCKERFILE_PATH} \
--build-arg NUCLIO_PYTHON_VERSION=2.7 \
--build-arg NUCLIO_PYTHON_OS=slim-jessie \
--tag $(NUCLIO_DOCKER_PROCESSOR_PY2_JESSIE_IMAGE_NAME) .
# build python 3/jesse
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file ${NUCLIO_PROCESSOR_PY_DOCKERFILE_PATH} \
--build-arg NUCLIO_PYTHON_VERSION=3.6 \
--build-arg NUCLIO_PYTHON_OS=slim-jessie \
--tag $(NUCLIO_DOCKER_PROCESSOR_PY3_JESSIE_IMAGE_NAME) .
IMAGES_TO_PUSH += \
$(NUCLIO_DOCKER_PROCESSOR_PY2_ALPINE_IMAGE_NAME) \
$(NUCLIO_DOCKER_PROCESSOR_PY2_JESSIE_IMAGE_NAME) \
$(NUCLIO_DOCKER_PROCESSOR_PY3_ALPINE_IMAGE_NAME) \
$(NUCLIO_DOCKER_PROCESSOR_PY3_JESSIE_IMAGE_NAME)
# Go
NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_IMAGE_NAME=\
nuclio/handler-builder-golang-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
handler-builder-golang-onbuild: processor
docker build --build-arg NUCLIO_ARCH=$(NUCLIO_ARCH) \
--file pkg/processor/build/runtime/golang/docker/onbuild/Dockerfile \
--tag $(NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_BUILDER_GOLANG_ONBUILD_IMAGE_NAME)
# Pypy
NUCLIO_DOCKER_PROCESSOR_PYPY_JESSIE_IMAGE_NAME=nuclio/processor-pypy2-5.9-jessie:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
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/handler-pypy2-5.9-jessie:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
handler-pypy:
docker build \
--file pkg/processor/build/runtime/pypy/docker/Dockerfile.handler-pypy \
--build-arg NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH=$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH) \
--tag $(NUCLIO_DOCKER_HANDLER_BUILDER_PYPY_ONBUILD_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_BUILDER_PYPY_ONBUILD_IMAGE_NAME)
# Shell
NUCLIO_PROCESSOR_SHELL_DOCKERFILE_PATH = pkg/processor/build/runtime/shell/docker/processor-shell/Dockerfile
NUCLIO_DOCKER_PROCESSOR_SHELL_ALPINE_IMAGE_NAME=nuclio/processor-shell-alpine:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
processor-shell: processor
# build shell/alpine
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file $(NUCLIO_PROCESSOR_SHELL_DOCKERFILE_PATH) \
--tag $(NUCLIO_DOCKER_PROCESSOR_SHELL_ALPINE_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_PROCESSOR_SHELL_ALPINE_IMAGE_NAME)
# nodejs
NUCLIO_HANDLER_NODEJS_DOCKERFILE_PATH = pkg/processor/build/runtime/nodejs/docker/Dockerfile.handler-nodejs
NUCLIO_DOCKER_HANDLER_NODEJS_ALPINE_IMAGE_NAME=nuclio/handler-nodejs-alpine:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
handler-nodejs: processor
docker build $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file $(NUCLIO_HANDLER_NODEJS_DOCKERFILE_PATH) \
--tag $(NUCLIO_DOCKER_HANDLER_NODEJS_ALPINE_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_NODEJS_ALPINE_IMAGE_NAME)
# dotnet core
NUCLIO_DOCKER_HANDLER_BUILDER_DOTNETCORE_ONBUILD_IMAGE_NAME=nuclio/handler-builder-dotnetcore-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
NUCLIO_ONBUILD_DOTNETCORE_DOCKERFILE_PATH = pkg/processor/build/runtime/dotnetcore/docker/onbuild/Dockerfile
handler-builder-dotnetcore-onbuild: processor
docker build \
-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_HANDLER_JAVA_DOCKERFILE_PATH = pkg/processor/build/runtime/java/docker/Dockerfile.handler
NUCLIO_DOCKER_HANDLER_JAVA_ALPINE_IMAGE_NAME=nuclio/handler-java:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
handler-java: processor
docker build --no-cache $(NUCLIO_BUILD_ARGS_VERSION_INFO_FILE) \
--file $(NUCLIO_HANDLER_JAVA_DOCKERFILE_PATH) \
--tag $(NUCLIO_DOCKER_HANDLER_JAVA_ALPINE_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_DOCKER_HANDLER_JAVA_ALPINE_IMAGE_NAME)
NUCLIO_JAVA_BUILDER_IMAGE_NAME=nuclio/handler-builder-java-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
handler-builder-java-onbuild:
docker build \
--file pkg/processor/build/runtime/java/docker/Dockerfile.handler-builder \
--tag $(NUCLIO_JAVA_BUILDER_IMAGE_NAME) .
IMAGES_TO_PUSH += $(NUCLIO_JAVA_BUILDER_IMAGE_NAME)
NUCLIO_JAVA_USER_BUILDER_IMAGE_NAME=nuclio/user-builder-java-onbuild:$(NUCLIO_DOCKER_IMAGE_TAG_WITH_ARCH)
user-jar-builder-java-onbuild:
docker build \
--file pkg/processor/build/runtime/java/docker/Dockerfile.user-jar-builder \
--tag $(NUCLIO_JAVA_USER_BUILDER_IMAGE_NAME) \
.
IMAGES_TO_PUSH += $(NUCLIO_JAVA_USER_BUILDER_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=300s \
--disable-all \
--enable-gc \
--enable=deadcode \
--enable=goconst \
--enable=gofmt \
--enable=golint \
--enable=gosimple \
--enable=ineffassign \
--enable=interfacer \
--enable=misspell \
--enable=staticcheck \
--enable=staticcheck \
--enable=unconvert \
--enable=varcheck \
--enable=vet \
--enable=vetshadow \
--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 --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: ensure-gopath
pytest -v pkg/processor/runtime/python
.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