Mirror of an open source Kubernetes-native API gateway for microservices built on the Envoy Proxy https://www.getambassador.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. # file: Makefile
  2. # Copyright 2018 Datawire. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License
  15. CI_DEBUG_KAT_BRANCH=
  16. SHELL = bash
  17. # Welcome to the Ambassador Makefile...
  18. .PHONY: \
  19. clean version setup-develop print-vars \
  20. docker-push docker-images \
  21. teleproxy-restart teleproxy-stop
  22. .SECONDARY:
  23. # GIT_BRANCH on TravisCI needs to be set through some external custom logic. Default to a Git native mechanism or
  24. # use what is defined.
  25. #
  26. # read: https://graysonkoonce.com/getting-the-current-branch-name-during-a-pull-request-in-travis-ci/
  27. GIT_DIRTY ?= $(shell test -z "$(shell git status --porcelain)" || printf "dirty")
  28. GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
  29. GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
  30. # This commands prints the tag of this commit or "undefined". Later we use GIT_TAG_SANITIZED and set it to "" if this
  31. # string is "undefined" or blank.
  32. GIT_TAG ?= $(shell git name-rev --tags --name-only $(GIT_COMMIT))
  33. GIT_BRANCH_SANITIZED := $(shell printf $(GIT_BRANCH) | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-zA-Z0-9]/-/g' -e 's/-\{2,\}/-/g')
  34. GIT_TAG_SANITIZED := $(shell \
  35. if [ "$(GIT_TAG)" = "undefined" -o -z "$(GIT_TAG)" ]; then \
  36. printf ""; \
  37. else \
  38. printf "$(GIT_TAG)" | sed -e 's/\^.*//g'; \
  39. fi \
  40. )
  41. # Trees get dirty sometimes by choice and sometimes accidently. If we are in a dirty tree then append "-dirty" to the
  42. # GIT_COMMIT.
  43. ifeq ($(GIT_DIRTY),dirty)
  44. GIT_VERSION := $(GIT_BRANCH_SANITIZED)-$(GIT_COMMIT)-dirty
  45. else
  46. GIT_VERSION := $(GIT_BRANCH_SANITIZED)-$(GIT_COMMIT)
  47. endif
  48. # This gives the _previous_ tag, plus a git delta, like
  49. # 0.36.0-436-g8b8c5d3
  50. GIT_DESCRIPTION := $(shell git describe $(GIT_COMMIT))
  51. # IS_PRIVATE: empty=false, nonempty=true
  52. # Default is true if any of the git remotes have the string "private" in any of their URLs.
  53. _git_remote_urls := $(shell git remote | xargs -n1 git remote get-url --all)
  54. IS_PRIVATE ?= $(findstring private,$(_git_remote_urls))
  55. # Note that for everything except RC builds, VERSION will be set to the version
  56. # we'd use for a GA build. This is by design.
  57. #
  58. # Also note that we strip off the leading 'v' here -- that's just for the git tag.
  59. ifneq ($(GIT_TAG_SANITIZED),)
  60. VERSION = $(patsubst v%,%,$(firstword $(subst -, ,$(GIT_TAG_SANITIZED))))
  61. else
  62. VERSION = $(patsubst v%,%,$(firstword $(subst -, ,$(GIT_VERSION))))
  63. endif
  64. # We need this for tagging in some situations.
  65. LATEST_RC=$(VERSION)-rc-latest
  66. ifndef DOCKER_REGISTRY
  67. $(error DOCKER_REGISTRY must be set. Use make DOCKER_REGISTRY=- for a purely local build.)
  68. endif
  69. AMBASSADOR_DOCKER_REPO ?= $(if $(filter-out -,$(DOCKER_REGISTRY)),$(DOCKER_REGISTRY)/)ambassador$(if $(IS_PRIVATE),-private)
  70. ifneq ($(DOCKER_EXTERNAL_REGISTRY),)
  71. AMBASSADOR_EXTERNAL_DOCKER_REPO ?= $(DOCKER_EXTERNAL_REGISTRY)/ambassador
  72. else
  73. AMBASSADOR_EXTERNAL_DOCKER_REPO ?= $(AMBASSADOR_DOCKER_REPO)
  74. endif
  75. DOCKER_OPTS =
  76. # This is the branch from ambassador-docs to pull for "make pull-docs".
  77. # Override if you need to.
  78. PULL_BRANCH ?= master
  79. AMBASSADOR_DOCKER_TAG ?= $(GIT_VERSION)
  80. AMBASSADOR_DOCKER_IMAGE ?= $(AMBASSADOR_DOCKER_REPO):$(AMBASSADOR_DOCKER_TAG)
  81. AMBASSADOR_EXTERNAL_DOCKER_IMAGE ?= $(AMBASSADOR_EXTERNAL_DOCKER_REPO):$(AMBASSADOR_DOCKER_TAG)
  82. ENVOY_FILE ?= envoy-bin/envoy-static-stripped
  83. # IF YOU MESS WITH ANY OF THESE VALUES, YOU MUST RUN `make docker-update-base`.
  84. ENVOY_REPO ?= $(if $(IS_PRIVATE),git@github.com:datawire/envoy-private.git,git://github.com/datawire/envoy.git)
  85. ENVOY_COMMIT ?= 4616a0939972438ea47f0ac6657296fb836d1187
  86. ENVOY_COMPILATION_MODE ?= dbg
  87. # Increment BASE_ENVOY_RELVER on changes to `Dockerfile.base-envoy`, or Envoy recipes
  88. BASE_ENVOY_RELVER ?= 2
  89. # Increment BASE_GO_RELVER on changes to `Dockerfile.base-go`
  90. BASE_GO_RELVER ?= 15
  91. # Increment BASE_PY_RELVER on changes to `Dockerfile.base-py`, `releng/*`, `multi/requirements.txt`, `ambassador/requirements.txt`
  92. BASE_PY_RELVER ?= 15
  93. BASE_DOCKER_REPO ?= quay.io/datawire/ambassador-base$(if $(IS_PRIVATE),-private)
  94. BASE_ENVOY_IMAGE ?= $(BASE_DOCKER_REPO):envoy-$(BASE_ENVOY_RELVER).$(ENVOY_COMMIT).$(ENVOY_COMPILATION_MODE)
  95. BASE_GO_IMAGE ?= $(BASE_DOCKER_REPO):go-$(BASE_GO_RELVER)
  96. BASE_PY_IMAGE ?= $(BASE_DOCKER_REPO):py-$(BASE_PY_RELVER)
  97. # END LIST OF VARIABLES REQUIRING `make docker-update-base`.
  98. # Default to _NOT_ using Kubernaut. At Datawire, we can set this to true,
  99. # but outside, it works much better to assume that user has set up something
  100. # and not try to override it.
  101. USE_KUBERNAUT ?= false
  102. KUBERNAUT=venv/bin/kubernaut
  103. KUBERNAUT_VERSION=2018.10.24-d46c1f1
  104. KUBERNAUT_CLAIM=$(KUBERNAUT) claims create --name $(CLAIM_NAME) --cluster-group main
  105. KUBERNAUT_DISCARD=$(KUBERNAUT) claims delete $(CLAIM_NAME)
  106. # Only override KUBECONFIG if we're using Kubernaut
  107. ifeq ($(USE_KUBERNAUT), true)
  108. KUBECONFIG ?= $(shell pwd)/cluster.yaml
  109. endif
  110. SCOUT_APP_KEY=
  111. KAT_CLIENT_DOCKER_REPO ?= $(if $(filter-out -,$(DOCKER_REGISTRY)),$(DOCKER_REGISTRY)/)kat-client$(if $(IS_PRIVATE),-private)
  112. KAT_SERVER_DOCKER_REPO ?= $(if $(filter-out -,$(DOCKER_REGISTRY)),$(DOCKER_REGISTRY)/)kat-backend$(if $(IS_PRIVATE),-private)
  113. KAT_CLIENT_DOCKER_IMAGE ?= $(KAT_CLIENT_DOCKER_REPO):$(AMBASSADOR_DOCKER_TAG)
  114. KAT_SERVER_DOCKER_IMAGE ?= $(KAT_SERVER_DOCKER_REPO):$(AMBASSADOR_DOCKER_TAG)
  115. KAT_CLIENT ?= venv/bin/kat_client
  116. # Allow overriding which watt we use.
  117. WATT ?= watt
  118. WATT_VERSION ?= 0.6.0
  119. # Allow overriding which kubestatus we use.
  120. KUBESTATUS ?= kubestatus
  121. KUBESTATUS_VERSION ?= 0.7.2
  122. TELEPROXY ?= venv/bin/teleproxy
  123. TELEPROXY_VERSION ?= 0.4.11
  124. # This should maybe be replaced with a lighterweight dependency if we
  125. # don't currently depend on go
  126. GOOS=$(shell go env GOOS)
  127. GOARCH=$(shell go env GOARCH)
  128. CLAIM_FILE=kubernaut-claim.txt
  129. CLAIM_NAME=$(shell cat $(CLAIM_FILE))
  130. # "make" by itself doesn't make the website. It takes too long and it doesn't
  131. # belong in the inner dev loop.
  132. all:
  133. $(MAKE) setup-develop
  134. $(MAKE) docker-push
  135. $(MAKE) test
  136. include build-aux/prelude.mk
  137. include build-aux/var.mk
  138. clean: clean-test
  139. rm -rf docs/_book docs/_site docs/package-lock.json
  140. rm -rf helm/*.tgz
  141. rm -rf app.json
  142. rm -rf venv/bin/ambassador
  143. rm -rf ambassador/ambassador/VERSION.py*
  144. rm -f *.docker
  145. rm -rf ambassador/build ambassador/dist ambassador/ambassador.egg-info ambassador/__pycache__
  146. find . \( -name .coverage -o -name .cache -o -name __pycache__ \) -print0 | xargs -0 rm -rf
  147. find . \( -name *.log \) -print0 | xargs -0 rm -rf
  148. rm -rf log.txt
  149. find ambassador/tests \
  150. \( -name '*.out' -o -name 'envoy.json' -o -name 'intermediate.json' \) -print0 \
  151. | xargs -0 rm -f
  152. rm -f kat-client-docker-image/kat_client
  153. rm -f kat-server-docker-image/kat-server
  154. rm -f kat-sandbox/http_auth/docker-compose.yml
  155. rm -f kat-sandbox/grpc_auth/docker-compose.yml
  156. rm -f kat-sandbox/grpc_web/docker-compose.yaml kat-sandbox/grpc_web/*_pb.js
  157. rm -rf envoy-bin
  158. rm -f envoy-build-image.txt
  159. clobber: clean kill-docker-registry
  160. -rm -f kat-client-docker-image/teleproxy
  161. -rm -rf $(WATT) $(KUBESTATUS)
  162. -$(if $(filter-out -,$(ENVOY_COMMIT)),rm -rf envoy envoy-src)
  163. -rm -rf docs/node_modules
  164. -rm -rf venv && echo && echo "Deleted venv, run 'deactivate' command if your virtualenv is activated" || true
  165. print-%:
  166. @printf "$($*)"
  167. print-vars:
  168. @echo "AMBASSADOR_DOCKER_IMAGE = $(AMBASSADOR_DOCKER_IMAGE)"
  169. @echo "AMBASSADOR_DOCKER_REPO = $(AMBASSADOR_DOCKER_REPO)"
  170. @echo "AMBASSADOR_DOCKER_TAG = $(AMBASSADOR_DOCKER_TAG)"
  171. @echo "AMBASSADOR_EXTERNAL_DOCKER_IMAGE = $(AMBASSADOR_EXTERNAL_DOCKER_IMAGE)"
  172. @echo "AMBASSADOR_EXTERNAL_DOCKER_REPO = $(AMBASSADOR_EXTERNAL_DOCKER_REPO)"
  173. @echo "CI_DEBUG_KAT_BRANCH = $(CI_DEBUG_KAT_BRANCH)"
  174. @echo "DOCKER_EPHEMERAL_REGISTRY = $(DOCKER_EPHEMERAL_REGISTRY)"
  175. @echo "DOCKER_EXTERNAL_REGISTRY = $(DOCKER_EXTERNAL_REGISTRY)"
  176. @echo "DOCKER_OPTS = $(DOCKER_OPTS)"
  177. @echo "DOCKER_REGISTRY = $(DOCKER_REGISTRY)"
  178. @echo "BASE_DOCKER_REPO = $(BASE_DOCKER_REPO)"
  179. @echo "GIT_BRANCH = $(GIT_BRANCH)"
  180. @echo "GIT_BRANCH_SANITIZED = $(GIT_BRANCH_SANITIZED)"
  181. @echo "GIT_COMMIT = $(GIT_COMMIT)"
  182. @echo "GIT_DESCRIPTION = $(GIT_DESCRIPTION)"
  183. @echo "GIT_DIRTY = $(GIT_DIRTY)"
  184. @echo "GIT_TAG = $(GIT_TAG)"
  185. @echo "GIT_TAG_SANITIZED = $(GIT_TAG_SANITIZED)"
  186. @echo "GIT_VERSION = $(GIT_VERSION)"
  187. @echo "KAT_CLIENT_DOCKER_IMAGE = $(KAT_CLIENT_DOCKER_IMAGE)"
  188. @echo "KAT_SERVER_DOCKER_IMAGE = $(KAT_SERVER_DOCKER_IMAGE)"
  189. @echo "KUBECONFIG = $(KUBECONFIG)"
  190. @echo "LATEST_RC = $(LATEST_RC)"
  191. @echo "USE_KUBERNAUT = $(USE_KUBERNAUT)"
  192. @echo "VERSION = $(VERSION)"
  193. export-vars:
  194. @echo "export AMBASSADOR_DOCKER_IMAGE='$(AMBASSADOR_DOCKER_IMAGE)'"
  195. @echo "export AMBASSADOR_DOCKER_REPO='$(AMBASSADOR_DOCKER_REPO)'"
  196. @echo "export AMBASSADOR_DOCKER_TAG='$(AMBASSADOR_DOCKER_TAG)'"
  197. @echo "export AMBASSADOR_EXTERNAL_DOCKER_IMAGE='$(AMBASSADOR_EXTERNAL_DOCKER_IMAGE)'"
  198. @echo "export AMBASSADOR_EXTERNAL_DOCKER_REPO='$(AMBASSADOR_EXTERNAL_DOCKER_REPO)'"
  199. @echo "export CI_DEBUG_KAT_BRANCH='$(CI_DEBUG_KAT_BRANCH)'"
  200. @echo "export DOCKER_EPHEMERAL_REGISTRY='$(DOCKER_EPHEMERAL_REGISTRY)'"
  201. @echo "export DOCKER_EXTERNAL_REGISTRY='$(DOCKER_EXTERNAL_REGISTRY)'"
  202. @echo "export DOCKER_OPTS='$(DOCKER_OPTS)'"
  203. @echo "export DOCKER_REGISTRY='$(DOCKER_REGISTRY)'"
  204. @echo "export BASE_DOCKER_REPO='$(BASE_DOCKER_REPO)'"
  205. @echo "export GIT_BRANCH='$(GIT_BRANCH)'"
  206. @echo "export GIT_BRANCH_SANITIZED='$(GIT_BRANCH_SANITIZED)'"
  207. @echo "export GIT_COMMIT='$(GIT_COMMIT)'"
  208. @echo "export GIT_DESCRIPTION='$(GIT_DESCRIPTION)'"
  209. @echo "export GIT_DIRTY='$(GIT_DIRTY)'"
  210. @echo "export GIT_TAG='$(GIT_TAG)'"
  211. @echo "export GIT_TAG_SANITIZED='$(GIT_TAG_SANITIZED)'"
  212. @echo "export GIT_VERSION='$(GIT_VERSION)'"
  213. @echo "export KAT_CLIENT_DOCKER_IMAGE='$(KAT_CLIENT_DOCKER_IMAGE)'"
  214. @echo "export KAT_SERVER_DOCKER_IMAGE='$(KAT_SERVER_DOCKER_IMAGE)'"
  215. @echo "export KUBECONFIG='$(KUBECONFIG)'"
  216. @echo "export LATEST_RC='$(LATEST_RC)'"
  217. @echo "export USE_KUBERNAUT='$(USE_KUBERNAUT)'"
  218. @echo "export VERSION='$(VERSION)'"
  219. # All of this will likely fail horribly outside of CI, for the record.
  220. docker-registry: $(KUBECONFIG)
  221. ifneq ($(DOCKER_EPHEMERAL_REGISTRY),)
  222. @if [ "$(TRAVIS)" != "true" ]; then \
  223. echo "make docker-registry is only for CI" >&2 ;\
  224. exit 1 ;\
  225. fi
  226. @if [ -z "$(KUBECONFIG)" ]; then \
  227. echo "No KUBECONFIG" >&2 ;\
  228. exit 1 ;\
  229. fi
  230. @if [ ! -r .docker_port_forward ]; then \
  231. echo "Starting local Docker registry in Kubernetes" ;\
  232. kubectl apply -f releng/docker-registry.yaml ;\
  233. while [ -z "$$(kubectl get pods -n docker-registry -ojsonpath='{.items[0].status.containerStatuses[0].state.running}')" ]; do echo pod wait...; sleep 1; done ;\
  234. sh -c 'kubectl port-forward --namespace=docker-registry deployment/registry 31000:5000 > /tmp/port-forward-log & echo $$! > .docker_port_forward' ;\
  235. else \
  236. echo "Local Docker registry should be already running" ;\
  237. fi
  238. while ! curl -i http://localhost:31000/ 2>/dev/null; do echo curl wait...; sleep 1; done
  239. endif
  240. kill-docker-registry:
  241. @if [ -r .docker_port_forward ]; then \
  242. echo "Stopping local Docker registry" ;\
  243. kill $$(cat .docker_port_forward) ;\
  244. kubectl delete -f releng/docker-registry.yaml ;\
  245. rm -f .docker_port_forward ;\
  246. else \
  247. echo "Docker registry should not be running" ;\
  248. fi
  249. envoy-src: FORCE
  250. @echo "Getting Envoy sources..."
  251. @if test -d envoy && ! test -d envoy-src; then PS4=; set -x; mv envoy envoy-src; fi
  252. # Ensure that GIT_DIR and GIT_WORK_TREE are unset so that `git bisect`
  253. # and friends work properly.
  254. @PS4=; set -ex; { \
  255. unset GIT_DIR GIT_WORK_TREE; \
  256. git init $@; \
  257. cd $@; \
  258. if git remote get-url origin &>/dev/null; then \
  259. git remote set-url origin $(ENVOY_REPO); \
  260. else \
  261. git remote add origin $(ENVOY_REPO); \
  262. fi; \
  263. git fetch --tags origin; \
  264. if [ $(ENVOY_COMMIT) != '-' ]; then \
  265. git checkout $(ENVOY_COMMIT); \
  266. elif ! git rev-parse HEAD >/dev/null 2>&1; then \
  267. git checkout origin/master; \
  268. fi; \
  269. }
  270. envoy-build-image.txt: FORCE envoy-src
  271. @echo "Making $@..."
  272. set -e; \
  273. cd envoy-src; . ci/envoy_build_sha.sh; cd ..; \
  274. echo docker.io/envoyproxy/envoy-build-ubuntu:$$ENVOY_BUILD_SHA > .tmp.$@.tmp; \
  275. if cmp -s .tmp.$@.tmp $@; then \
  276. rm -f .tmp.$@.tmp; \
  277. else \
  278. mv .tmp.$@.tmp $@; \
  279. fi
  280. # We rsync to a persistent named-volume (instead of building directly
  281. # on the bind-mount volume) because Docker for Mac's osxfs is very
  282. # slow.
  283. ENVOY_SYNC_HOST_TO_DOCKER = docker run --rm --volume=$(CURDIR)/envoy-src:/xfer:ro --volume=envoy-build:/root:rw $$(cat envoy-build-image.txt) rsync -Pav --delete /xfer/ /root/envoy
  284. ENVOY_SYNC_DOCKER_TO_HOST = docker run --rm --volume=$(CURDIR)/envoy-src:/xfer:rw --volume=envoy-build:/root:ro $$(cat envoy-build-image.txt) rsync -Pav --delete /root/envoy/ /xfer
  285. envoy-bin:
  286. mkdir -p $@
  287. envoy-bin/envoy-static: envoy-build-image.txt FORCE | envoy-bin
  288. @PS4=; set -ex; if docker run --rm --entrypoint=true $(BASE_ENVOY_IMAGE); then \
  289. docker run --rm --volume=$(CURDIR)/$(@D):/xfer:rw --user=$$(id -u):$$(id -g) $(BASE_ENVOY_IMAGE) cp -a /usr/local/bin/envoy /xfer/$(@F); \
  290. else \
  291. if [ -n '$(CI)' ]; then \
  292. echo 'error: This should not happen in CI: should not try to compile Envoy'; \
  293. exit 1; \
  294. fi; \
  295. $(ENVOY_SYNC_HOST_TO_DOCKER); \
  296. ( \
  297. trap '$(ENVOY_SYNC_DOCKER_TO_HOST)' EXIT; \
  298. docker run --rm --volume=envoy-build:/root:rw --workdir=/root/envoy $$(cat envoy-build-image.txt) bazel build --verbose_failures -c $(ENVOY_COMPILATION_MODE) //source/exe:envoy-static; \
  299. docker run --rm --volume=envoy-build:/root:rw $$(cat envoy-build-image.txt) chmod 755 /root /root/.cache; \
  300. ); \
  301. docker run --rm --volume=envoy-build:/root:ro --volume=$(CURDIR)/envoy-bin:/xfer:rw --user=$$(id -u):$$(id -g) $$(cat envoy-build-image.txt) rsync -Pav --delete /root/envoy/bazel-bin/source/exe/envoy-static /xfer/envoy-static; \
  302. fi
  303. %-stripped: % envoy-build-image.txt
  304. docker run --rm --volume=$(abspath $(@D)):/xfer:rw $$(cat envoy-build-image.txt) strip /xfer/$(<F) -o /xfer/$(@F)
  305. check-envoy: envoy-bin/envoy-static envoy-build-image.txt
  306. $(ENVOY_SYNC_HOST_TO_DOCKER)
  307. @PS4=; set -ex; trap '$(ENVOY_SYNC_DOCKER_TO_HOST)' EXIT; { \
  308. docker run --rm --privileged --volume=envoy-build:/root:rw --workdir=/root/envoy $$(cat envoy-build-image.txt) bazel test --verbose_failures -c dbg --test_env=ENVOY_IP_TEST_VERSIONS=v4only //test/...; \
  309. }
  310. .PHONY: check-envoy
  311. envoy-shell: envoy-build-image.txt
  312. $(ENVOY_SYNC_HOST_TO_DOCKER)
  313. docker run --rm --privileged --volume=envoy-build:/root:rw --workdir=/root/envoy -it $$(cat envoy-build-image.txt) || true
  314. $(ENVOY_SYNC_DOCKER_TO_HOST)
  315. .PHONY: envoy-shell
  316. base-envoy.docker: Dockerfile.base-envoy envoy-bin/envoy-static $(var.)BASE_ENVOY_IMAGE $(WRITE_IFCHANGED)
  317. @if [ -n "$(AMBASSADOR_DEV)" ]; then echo "Do not run this from a dev shell" >&2; exit 1; fi
  318. docker build $(DOCKER_OPTS) -t $(BASE_ENVOY_IMAGE) -f $< .
  319. @docker image inspect $(BASE_ENVOY_IMAGE) --format='{{.Id}}' | $(WRITE_IFCHANGED) $@
  320. base-py.docker: Dockerfile.base-py $(var.)BASE_PY_IMAGE $(WRITE_IFCHANGED)
  321. @if [ -n "$(AMBASSADOR_DEV)" ]; then echo "Do not run this from a dev shell" >&2; exit 1; fi
  322. @if ! docker run --rm --entrypoint=true $(BASE_PY_IMAGE); then \
  323. echo "Building $(BASE_PY_IMAGE)" && \
  324. docker build $(DOCKER_OPTS) -t $(BASE_PY_IMAGE) -f $< .; \
  325. fi
  326. @docker image inspect $(BASE_PY_IMAGE) --format='{{.Id}}' | $(WRITE_IFCHANGED) $@
  327. base-go.docker: Dockerfile.base-go $(var.)BASE_GO_IMAGE $(WRITE_IFCHANGED)
  328. @if [ -n "$(AMBASSADOR_DEV)" ]; then echo "Do not run this from a dev shell" >&2; exit 1; fi
  329. @if ! docker run --rm --entrypoint=true $(BASE_GO_IMAGE); then \
  330. echo "Building $(BASE_GO_IMAGE)" && \
  331. docker build $(DOCKER_OPTS) -t $(BASE_GO_IMAGE) -f $< .; \
  332. fi
  333. @docker image inspect $(BASE_GO_IMAGE) --format='{{.Id}}' | $(WRITE_IFCHANGED) $@
  334. docker-base-images:
  335. @if [ -n "$(AMBASSADOR_DEV)" ]; then echo "Do not run this from a dev shell" >&2; exit 1; fi
  336. $(MAKE) base-envoy.docker base-go.docker base-py.docker
  337. @echo "RESTART ANY DEV SHELLS to make sure they use your new images."
  338. docker-push-base-images:
  339. @if [ -n "$(AMBASSADOR_DEV)" ]; then echo "Do not run this from a dev shell" >&2; exit 1; fi
  340. docker push $(BASE_ENVOY_IMAGE)
  341. docker push $(BASE_PY_IMAGE)
  342. docker push $(BASE_GO_IMAGE)
  343. @echo "RESTART ANY DEV SHELLS to make sure they use your new images."
  344. docker-update-base:
  345. $(MAKE) docker-base-images go/apis/envoy
  346. $(MAKE) docker-push-base-images
  347. ambassador-docker-image: ambassador.docker
  348. ambassador.docker: Dockerfile base-go.docker base-py.docker $(ENVOY_FILE) $(WATT) $(KUBESTATUS) $(WRITE_IFCHANGED) ambassador/ambassador/VERSION.py FORCE
  349. docker build --build-arg ENVOY_FILE=$(ENVOY_FILE) --build-arg BASE_GO_IMAGE=$(BASE_GO_IMAGE) --build-arg BASE_PY_IMAGE=$(BASE_PY_IMAGE) $(DOCKER_OPTS) -t $(AMBASSADOR_DOCKER_IMAGE) .
  350. @docker image inspect $(AMBASSADOR_DOCKER_IMAGE) --format='{{.Id}}' | $(WRITE_IFCHANGED) $@
  351. kat-client-docker-image: kat-client.docker
  352. .PHONY: kat-client-docker-image
  353. kat-client.docker: kat-client-docker-image/Dockerfile base-py.docker kat-client-docker-image/teleproxy kat-client-docker-image/kat_client $(WRITE_IFCHANGED) $(var.)KAT_CLIENT_DOCKER_IMAGE
  354. docker build --build-arg BASE_PY_IMAGE=$(BASE_PY_IMAGE) $(DOCKER_OPTS) -t $(KAT_CLIENT_DOCKER_IMAGE) kat-client-docker-image
  355. @docker image inspect $(KAT_CLIENT_DOCKER_IMAGE) --format='{{.Id}}' | $(WRITE_IFCHANGED) $@
  356. # kat-client-docker-image/teleproxy always uses the linux/amd64 architecture
  357. kat-client-docker-image/teleproxy: $(var.)TELEPROXY_VERSION
  358. curl --fail -o $@ https://s3.amazonaws.com/datawire-static-files/teleproxy/$(TELEPROXY_VERSION)/linux/amd64/teleproxy
  359. # kat-client-docker-image/kat_client always uses the linux/amd64 architecture
  360. kat-client-docker-image/kat_client: $(wildcard go/kat-client/*) go/apis/kat/echo.pb.go
  361. GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o $@ ./go/kat-client
  362. kat-server-docker-image: kat-server.docker
  363. .PHONY: kat-server-docker-image
  364. kat-server.docker: $(wildcard kat-server-docker-image/*) kat-server-docker-image/kat-server $(var.)KAT_SERVER_DOCKER_IMAGE
  365. docker build $(DOCKER_OPTS) -t $(KAT_SERVER_DOCKER_IMAGE) kat-server-docker-image
  366. @docker image inspect $(KAT_SERVER_DOCKER_IMAGE) --format='{{.Id}}' | $(WRITE_IFCHANGED) $@
  367. # kat-server-docker-image/kat-server always uses the linux/amd64 architecture
  368. kat-server-docker-image/kat-server: $(wildcard go/kat-server/* go/kat-server/*/*) go/apis/kat/echo.pb.go
  369. GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o $@ ./go/kat-server
  370. docker-images: mypy ambassador-docker-image
  371. docker-push: docker-images
  372. ifeq ($(DOCKER_REGISTRY),-)
  373. @echo "No DOCKER_REGISTRY set"
  374. else
  375. @echo 'PUSH $(AMBASSADOR_DOCKER_IMAGE)'
  376. @set -o pipefail; \
  377. docker push $(AMBASSADOR_DOCKER_IMAGE) | python releng/linify.py push.log
  378. endif
  379. docker-push-kat-client: kat-client-docker-image
  380. @echo 'PUSH $(KAT_CLIENT_DOCKER_IMAGE)'
  381. @set -o pipefail; \
  382. docker push $(KAT_CLIENT_DOCKER_IMAGE) | python releng/linify.py push.log
  383. docker-push-kat-server: kat-server-docker-image
  384. @echo 'PUSH $(KAT_SERVER_DOCKER_IMAGE)'
  385. @set -o pipefail; \
  386. docker push $(KAT_SERVER_DOCKER_IMAGE) | python releng/linify.py push.log
  387. # TODO: validate version is conformant to some set of rules might be a good idea to add here
  388. ambassador/ambassador/VERSION.py: FORCE $(WRITE_IFCHANGED)
  389. $(call check_defined, VERSION, VERSION is not set)
  390. $(call check_defined, GIT_BRANCH, GIT_BRANCH is not set)
  391. $(call check_defined, GIT_COMMIT, GIT_COMMIT is not set)
  392. $(call check_defined, GIT_DESCRIPTION, GIT_DESCRIPTION is not set)
  393. @echo "Generating and templating version information -> $(VERSION)"
  394. sed \
  395. -e 's!{{VERSION}}!$(VERSION)!g' \
  396. -e 's!{{GITBRANCH}}!$(GIT_BRANCH)!g' \
  397. -e 's!{{GITDIRTY}}!$(GIT_DIRTY)!g' \
  398. -e 's!{{GITCOMMIT}}!$(GIT_COMMIT)!g' \
  399. -e 's!{{GITDESCRIPTION}}!$(GIT_DESCRIPTION)!g' \
  400. < VERSION-template.py | $(WRITE_IFCHANGED) $@
  401. version: ambassador/ambassador/VERSION.py
  402. $(TELEPROXY): $(var.)TELEPROXY_VERSION $(var.)GOOS $(var.)GOARCH | venv/bin/activate
  403. curl -o $(TELEPROXY) https://s3.amazonaws.com/datawire-static-files/teleproxy/$(TELEPROXY_VERSION)/$(GOOS)/$(GOARCH)/teleproxy
  404. sudo chown 0:0 $(TELEPROXY) # setting group 0 is very important for SUID on MacOS!
  405. sudo chmod go-w,a+sx $(TELEPROXY)
  406. kill_teleproxy = curl -s --connect-timeout 5 127.254.254.254/api/shutdown || true
  407. run_teleproxy = $(TELEPROXY)
  408. # This is for the docker image, so we don't use the current arch, we hardcode to linux/amd64
  409. $(WATT): $(var.)WATT_VERSION
  410. curl -o $(WATT) https://s3.amazonaws.com/datawire-static-files/watt/$(WATT_VERSION)/linux/amd64/watt
  411. chmod go-w,a+x $(WATT)
  412. # This is for the docker image, so we don't use the current arch, we hardcode to linux/amd64
  413. $(KUBESTATUS): $(var.)KUBESTATUS_VERSION
  414. curl -o $(KUBESTATUS) https://s3.amazonaws.com/datawire-static-files/kubestatus/$(KUBESTATUS_VERSION)/linux/amd64/kubestatus
  415. chmod go-w,a+x $(KUBESTATUS)
  416. $(CLAIM_FILE):
  417. @if [ -z $${CI+x} ]; then \
  418. echo kat-$${USER} > $@; \
  419. else \
  420. echo kat-$${USER}-$(shell uuidgen) > $@; \
  421. fi
  422. $(KUBERNAUT): $(var.)KUBERNAUT_VERSION $(var.)GOOS $(var.)GOARCH | venv/bin/activate
  423. curl -o $(KUBERNAUT) http://releases.datawire.io/kubernaut/$(KUBERNAUT_VERSION)/$(GOOS)/$(GOARCH)/kubernaut
  424. chmod +x $(KUBERNAUT)
  425. $(KAT_CLIENT): $(wildcard go/kat-client/*) go/apis/kat/echo.pb.go
  426. go build -o $@ ./go/kat-client
  427. setup-develop: venv $(KAT_CLIENT) $(TELEPROXY) $(KUBERNAUT) $(WATT) $(KUBESTATUS) version
  428. cluster.yaml: $(CLAIM_FILE) $(KUBERNAUT)
  429. ifeq ($(USE_KUBERNAUT), true)
  430. $(KUBERNAUT_DISCARD)
  431. $(KUBERNAUT_CLAIM)
  432. cp ~/.kube/$(CLAIM_NAME).yaml cluster.yaml
  433. else
  434. ifneq ($(USE_KUBERNAUT),)
  435. ifneq ($(USE_KUBERNAUT),false)
  436. @echo "USE_KUBERNAUT must be true, false, or unset" >&2
  437. false
  438. endif
  439. endif
  440. endif
  441. # Make is too dumb to understand equivalence between absolute and
  442. # relative paths.
  443. $(CURDIR)/cluster.yaml: cluster.yaml
  444. setup-test: cluster-and-teleproxy
  445. cluster-and-teleproxy: cluster.yaml $(TELEPROXY)
  446. rm -rf /tmp/k8s-*.yaml /tmp/kat-*.yaml
  447. # $(MAKE) teleproxy-restart
  448. # @echo "Sleeping for Teleproxy cluster"
  449. # sleep 10
  450. teleproxy-restart: $(TELEPROXY)
  451. @echo "Killing teleproxy"
  452. $(kill_teleproxy)
  453. sleep 0.25 # wait for exit...
  454. $(run_teleproxy) -kubeconfig $(KUBECONFIG) 2> /tmp/teleproxy.log &
  455. sleep 0.5 # wait for start
  456. @if [ $$(ps -ef | grep venv/bin/teleproxy | grep -v grep | wc -l) -le 0 ]; then \
  457. echo "teleproxy did not start"; \
  458. cat /tmp/teleproxy.log; \
  459. exit 1; \
  460. fi
  461. @echo "Done"
  462. teleproxy-stop:
  463. $(kill_teleproxy)
  464. sleep 0.25 # wait for exit...
  465. @if [ $$(ps -ef | grep venv/bin/teleproxy | grep -v grep | wc -l) -gt 0 ]; then \
  466. echo "teleproxy still running" >&2; \
  467. ps -ef | grep venv/bin/teleproxy | grep -v grep >&2; \
  468. false; \
  469. else \
  470. echo "teleproxy stopped" >&2; \
  471. fi
  472. # "make shell" drops you into a dev shell, and tries to set variables, etc., as
  473. # needed:
  474. #
  475. # If USE_KUBERNAUT is true, we'll set up for Kubernaut, otherwise we'll assume
  476. # that the current KUBECONFIG is good.
  477. #
  478. # XXX KLF HACK: The dev shell used to include setting
  479. # AMBASSADOR_DEV=1 \
  480. # but I've ripped that out, since moving the KAT client into the cluster makes it
  481. # much complex for the AMBASSADOR_DEV stuff to work correctly. I'll open an
  482. # issue to finish sorting this out, but right now I want to get our CI builds
  483. # into better shape without waiting for that.
  484. shell: setup-develop
  485. AMBASSADOR_DOCKER_IMAGE="$(AMBASSADOR_DOCKER_IMAGE)" \
  486. BASE_PY_IMAGE="$(BASE_PY_IMAGE)" \
  487. BASE_GO_IMAGE="$(BASE_GO_IMAGE)" \
  488. MAKE_KUBECONFIG="$(KUBECONFIG)" \
  489. bash --init-file releng/init.sh -i
  490. clean-test:
  491. rm -f cluster.yaml
  492. test -x $(KUBERNAUT) && $(KUBERNAUT_DISCARD) || true
  493. rm -f $(CLAIM_FILE)
  494. $(call kill_teleproxy)
  495. test: setup-develop
  496. cd ambassador && \
  497. AMBASSADOR_DOCKER_IMAGE="$(AMBASSADOR_DOCKER_IMAGE)" \
  498. BASE_PY_IMAGE="$(BASE_PY_IMAGE)" \
  499. BASE_GO_IMAGE="$(BASE_GO_IMAGE)" \
  500. KUBECONFIG="$(KUBECONFIG)" \
  501. KAT_CLIENT_DOCKER_IMAGE="$(KAT_CLIENT_DOCKER_IMAGE)" \
  502. KAT_SERVER_DOCKER_IMAGE="$(KAT_SERVER_DOCKER_IMAGE)" \
  503. PATH="$(shell pwd)/venv/bin:$(PATH)" \
  504. bash ../releng/run-tests.sh
  505. test-list: setup-develop
  506. cd ambassador && PATH="$(shell pwd)/venv/bin":$(PATH) pytest --collect-only -q
  507. update-aws:
  508. ifeq ($(AWS_ACCESS_KEY_ID),)
  509. @echo 'AWS credentials not configured; not updating https://s3.amazonaws.com/datawire-static-files/ambassador/$(STABLE_TXT_KEY)'
  510. @echo 'AWS credentials not configured; not updating latest version in Scout'
  511. else
  512. @if [ -n "$(STABLE_TXT_KEY)" ]; then \
  513. printf "$(VERSION)" > stable.txt; \
  514. echo "updating $(STABLE_TXT_KEY) with $$(cat stable.txt)"; \
  515. aws s3api put-object \
  516. --bucket datawire-static-files \
  517. --key ambassador/$(STABLE_TXT_KEY) \
  518. --body stable.txt; \
  519. fi
  520. @if [ -n "$(SCOUT_APP_KEY)" ]; then \
  521. printf '{"application":"ambassador","latest_version":"$(VERSION)","notices":[]}' > app.json; \
  522. echo "updating $(SCOUT_APP_KEY) with $$(cat app.json)"; \
  523. aws s3api put-object \
  524. --bucket scout-datawire-io \
  525. --key ambassador/$(SCOUT_APP_KEY) \
  526. --body app.json; \
  527. fi
  528. endif
  529. release-prep:
  530. bash releng/release-prep.sh
  531. release:
  532. @if [ "$(VERSION)" = "$(GIT_VERSION)" ]; then \
  533. printf "'make release' can only be run for a GA commit when VERSION is not the same as GIT_COMMIT!\n"; \
  534. exit 1; \
  535. fi
  536. docker pull $(AMBASSADOR_DOCKER_REPO):$(LATEST_RC)
  537. docker tag $(AMBASSADOR_DOCKER_REPO):$(LATEST_RC) $(AMBASSADOR_DOCKER_REPO):$(VERSION)
  538. docker push $(AMBASSADOR_DOCKER_REPO):$(VERSION)
  539. $(MAKE) SCOUT_APP_KEY=app.json STABLE_TXT_KEY=stable.txt update-aws
  540. # ------------------------------------------------------------------------------
  541. # Go gRPC bindings (Envoy)
  542. # ------------------------------------------------------------------------------
  543. # The version numbers of `protoc` (in this Makefile),
  544. # `protoc-gen-gogofast` (in go.mod), and `protoc-gen-validate` (in
  545. # go.mod) are based on
  546. # https://github.com/envoyproxy/go-control-plane/blob/master/Dockerfile.ci
  547. PROTOC_VERSION = 3.5.1
  548. PROTOC_PLATFORM = $(patsubst darwin,osx,$(GOOS))-$(patsubst amd64,x86_64,$(patsubst 386,x86_32,$(GOARCH)))
  549. venv/protoc-$(PROTOC_VERSION)-$(PROTOC_PLATFORM).zip: $(var.)PROTOC_VERSION | venv/bin/activate
  550. curl -o $@ --fail -L https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/$(@F)
  551. venv/bin/protoc: venv/protoc-$(PROTOC_VERSION)-$(PROTOC_PLATFORM).zip
  552. bsdtar -xf $< -C venv bin/protoc
  553. venv/bin/protoc-gen-gogofast: go.mod $(FLOCK) | venv/bin/activate
  554. $(FLOCK) go.mod go build -o $@ github.com/gogo/protobuf/protoc-gen-gogofast
  555. venv/bin/protoc-gen-validate: go.mod $(FLOCK) | venv/bin/activate
  556. $(FLOCK) go.mod go build -o $@ github.com/envoyproxy/protoc-gen-validate
  557. # Search path for .proto files
  558. gomoddir = $(shell $(FLOCK) go.mod go list $1/... >/dev/null 2>/dev/null; $(FLOCK) go.mod go list -m -f='{{.Dir}}' $1)
  559. # This list is based 'imports=()' in https://github.com/envoyproxy/go-control-plane/blob/master/build/generate_protos.sh
  560. imports += $(CURDIR)/envoy-src/api
  561. imports += $(call gomoddir,github.com/envoyproxy/protoc-gen-validate)
  562. imports += $(call gomoddir,github.com/gogo/googleapis)
  563. imports += $(call gomoddir,github.com/gogo/protobuf)/protobuf
  564. imports += $(call gomoddir,istio.io/gogo-genproto)
  565. imports += $(call gomoddir,istio.io/gogo-genproto)/prometheus
  566. # Map from .proto files to Go package names
  567. # This list is based 'mappings=()' in https://github.com/envoyproxy/go-control-plane/blob/master/build/generate_protos.sh
  568. mappings += gogoproto/gogo.proto=github.com/gogo/protobuf/gogoproto
  569. mappings += google/api/annotations.proto=github.com/gogo/googleapis/google/api
  570. mappings += google/protobuf/any.proto=github.com/gogo/protobuf/types
  571. mappings += google/protobuf/duration.proto=github.com/gogo/protobuf/types
  572. mappings += google/protobuf/empty.proto=github.com/gogo/protobuf/types
  573. mappings += google/protobuf/struct.proto=github.com/gogo/protobuf/types
  574. mappings += google/protobuf/timestamp.proto=github.com/gogo/protobuf/types
  575. mappings += google/protobuf/wrappers.proto=github.com/gogo/protobuf/types
  576. mappings += google/rpc/status.proto=github.com/gogo/googleapis/google/rpc
  577. mappings += metrics.proto=istio.io/gogo-genproto/prometheus
  578. mappings += opencensus/proto/trace/v1/trace.proto=istio.io/gogo-genproto/opencensus/proto/trace/v1
  579. mappings += opencensus/proto/trace/v1/trace_config.proto=istio.io/gogo-genproto/opencensus/proto/trace/v1
  580. mappings += $(shell find $(CURDIR)/envoy-src/api/envoy -type f -name '*.proto' | sed -E 's,^$(CURDIR)/envoy-src/api/((.*)/[^/]*),\1=github.com/datawire/ambassador/go/apis/\2,')
  581. joinlist=$(if $(word 2,$2),$(firstword $2)$1$(call joinlist,$1,$(wordlist 2,$(words $2),$2)),$2)
  582. comma = ,
  583. _imports = $(call lazyonce,_imports,$(imports))
  584. _mappings = $(call lazyonce,_mappings,$(mappings))
  585. go/apis/envoy: envoy-src $(FLOCK) venv/bin/protoc venv/bin/protoc-gen-gogofast venv/bin/protoc-gen-validate $(var.)_imports $(var.)_mappings
  586. rm -rf $@ $(@D).envoy.tmp
  587. mkdir -p $(@D).envoy.tmp
  588. # go-control-plane `make generate`
  589. @set -e; find $(CURDIR)/envoy-src/api/envoy -type f -name '*.proto' | sed 's,/[^/]*$$,,' | uniq | while read -r dir; do \
  590. echo "Generating $$dir"; \
  591. ./venv/bin/protoc \
  592. $(addprefix --proto_path=,$(_imports)) \
  593. --plugin=$(CURDIR)/venv/bin/protoc-gen-gogofast --gogofast_out='$(call joinlist,$(comma),plugins=grpc $(addprefix M,$(_mappings))):$(@D).envoy.tmp' \
  594. --plugin=$(CURDIR)/venv/bin/protoc-gen-validate --validate_out='lang=gogo:$(@D).envoy.tmp' \
  595. "$$dir"/*.proto; \
  596. done
  597. # go-control-plane `make generate-patch`
  598. # https://github.com/envoyproxy/go-control-plane/issues/173
  599. find $(@D).envoy.tmp -name '*.validate.go' -exec sed -E -i.bak 's,"(envoy/.*)"$$,"github.com/datawire/ambassador/go/apis/\1",' {} +
  600. find $(@D).envoy.tmp -name '*.bak' -delete
  601. # move things in to place
  602. mkdir -p $(@D)
  603. mv $(@D).envoy.tmp/envoy $@
  604. rmdir $(@D).envoy.tmp
  605. # ------------------------------------------------------------------------------
  606. # gRPC bindings for KAT
  607. # ------------------------------------------------------------------------------
  608. GRPC_WEB_VERSION = 1.0.3
  609. GRPC_WEB_PLATFORM = $(GOOS)-x86_64
  610. venv/bin/protoc-gen-grpc-web: $(var.)GRPC_WEB_VERSION $(var.)GRPC_WEB_PLATFORM | venv/bin/activate
  611. curl -o $@ -L --fail https://github.com/grpc/grpc-web/releases/download/$(GRPC_WEB_VERSION)/protoc-gen-grpc-web-$(GRPC_WEB_VERSION)-$(GRPC_WEB_PLATFORM)
  612. chmod 755 $@
  613. go/apis/kat/echo.pb.go: kat-apis/echo.proto venv/bin/protoc venv/bin/protoc-gen-gogofast
  614. ./venv/bin/protoc \
  615. --proto_path=$(CURDIR)/kat-apis \
  616. --plugin=$(CURDIR)/venv/bin/protoc-gen-gogofast --gogofast_out=plugins=grpc:$(@D) \
  617. $(CURDIR)/$<
  618. kat-sandbox/grpc_web/echo_grpc_web_pb.js: kat-apis/echo.proto venv/bin/protoc venv/bin/protoc-gen-grpc-web
  619. ./venv/bin/protoc \
  620. --proto_path=$(CURDIR)/kat-apis \
  621. --plugin=$(CURDIR)/venv/bin/protoc-gen-grpc-web --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$(@D) \
  622. $(CURDIR)/$<
  623. kat-sandbox/grpc_web/echo_pb.js: kat-apis/echo.proto venv/bin/protoc
  624. ./venv/bin/protoc \
  625. --proto_path=$(CURDIR)/kat-apis \
  626. --js_out=import_style=commonjs:$(@D) \
  627. $(CURDIR)/$<
  628. # ------------------------------------------------------------------------------
  629. # KAT docker-compose sandbox
  630. # ------------------------------------------------------------------------------
  631. kat-sandbox/http_auth/docker-compose.yml kat-sandbox/grpc_auth/docker-compose.yml kat-sandbox/grpc_web/docker-compose.yaml: %: %.in kat-server.docker $(var.)KAT_SERVER_DOCKER_IMAGE
  632. sed 's,@KAT_SERVER_DOCKER_IMAGE@,$(KAT_SERVER_DOCKER_IMAGE),g' < $< > $@
  633. kat-sandbox.http-auth: ## In docker-compose: run Ambassador, an HTTP AuthService, an HTTP backend service, and a TracingService
  634. kat-sandbox.http-auth: kat-sandbox/http_auth/docker-compose.yml
  635. @echo " ---> cleaning HTTP auth kat-sandbox"
  636. @cd kat-sandbox/http_auth && docker-compose stop && docker-compose rm -f
  637. @echo " ---> starting HTTP auth kat-sandbox"
  638. @cd kat-sandbox/http_auth && docker-compose up --force-recreate --abort-on-container-exit --build
  639. .PHONY: kat-sandbox.http-auth
  640. kat-sandbox.grpc-auth: ## In docker-compose: run Ambassador, a gRPC AuthService, an HTTP backend service, and a TracingService
  641. kat-sandbox.grpc-auth: kat-sandbox/grpc_auth/docker-compose.yml
  642. @echo " ---> cleaning gRPC auth kat-sandbox"
  643. @cd kat-sandbox/grpc_auth && docker-compose stop && docker-compose rm -f
  644. @echo " ---> starting gRPC auth kat-sandbox"
  645. @cd kat-sandbox/grpc_auth && docker-compose up --force-recreate --abort-on-container-exit --build
  646. .PHONY: kat-sandbox.grpc-auth
  647. kat-sandbox.web: ## In docker-compose: run Ambassador with gRPC-web enabled, and a gRPC backend service
  648. kat-sandbox.web: kat-sandbox/grpc_web/docker-compose.yaml
  649. kat-sandbox.web: kat-sandbox/grpc_web/echo_grpc_web_pb.js kat-sandbox/grpc_web/echo_pb.js
  650. @echo " ---> cleaning gRPC web kat-sandbox"
  651. @cd kat-sandbox/grpc_web && npm install && npx webpack
  652. @cd kat-sandbox/grpc_web && docker-compose stop && docker-compose rm -f
  653. @echo " ---> starting gRPC web kat-sandbox"
  654. @cd kat-sandbox/grpc_web && docker-compose up --force-recreate --abort-on-container-exit --build
  655. .PHONY: kat-sandbox.web
  656. # ------------------------------------------------------------------------------
  657. # Virtualenv
  658. # ------------------------------------------------------------------------------
  659. venv: version venv/bin/ambassador
  660. venv/bin/ambassador: venv/bin/activate ambassador/requirements.txt
  661. @releng/install-py.sh dev requirements ambassador/requirements.txt
  662. @releng/install-py.sh dev install ambassador/requirements.txt
  663. @releng/fix_kube_client
  664. venv/bin/activate: dev-requirements.txt multi/requirements.txt kat/requirements.txt
  665. test -d venv || virtualenv venv --python python3
  666. @releng/install-py.sh dev requirements $^
  667. @releng/install-py.sh dev install $^
  668. touch venv/bin/activate
  669. @releng/fix_kube_client
  670. mypy-server-stop: venv
  671. venv/bin/dmypy stop
  672. mypy-server: venv
  673. @if ! venv/bin/dmypy status >/dev/null; then \
  674. venv/bin/dmypy start -- --use-fine-grained-cache --follow-imports=skip --ignore-missing-imports ;\
  675. echo "Started mypy server" ;\
  676. fi
  677. mypy: mypy-server
  678. time venv/bin/dmypy check ambassador
  679. # ------------------------------------------------------------------------------
  680. # Website
  681. # ------------------------------------------------------------------------------
  682. pull-docs:
  683. { \
  684. git fetch https://github.com/datawire/ambassador-docs $(PULL_BRANCH) && \
  685. docs_head=$$(git rev-parse FETCH_HEAD) && \
  686. git subtree merge --prefix=docs "$${docs_head}" && \
  687. git subtree split --prefix=docs --rejoin --onto="$${docs_head}"; \
  688. }
  689. push-docs:
  690. { \
  691. git fetch https://github.com/datawire/ambassador-docs master && \
  692. docs_old=$$(git rev-parse FETCH_HEAD) && \
  693. docs_new=$$(git subtree split --prefix=docs --rejoin --onto="$${docs_old}") && \
  694. git push $(if $(GH_TOKEN),https://d6e-automaton:${GH_TOKEN}@github.com/,git@github.com:)datawire/ambassador-docs.git "$${docs_new}:refs/heads/$(or $(PUSH_BRANCH),master)"; \
  695. }
  696. .PHONY: pull-docs push-docs
  697. # ------------------------------------------------------------------------------
  698. # Function Definitions
  699. # ------------------------------------------------------------------------------
  700. # Check that given variables are set and all have non-empty values,
  701. # die with an error otherwise.
  702. #
  703. # Params:
  704. # 1. Variable name(s) to test.
  705. # 2. (optional) Error message to print.
  706. check_defined = $(strip $(foreach 1,$1, $(call __check_defined,$1,$(strip $(value 2)))))
  707. __check_defined = $(if $(value $1),, $(error Undefined $1$(if $2, ($2))))