Mirror of Istio: Connect, secure, control, and observe services.
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.core.mk 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. ## Copyright 2017 Istio Authors
  2. ##
  3. ## Licensed under the Apache License, Version 2.0 (the "License");
  4. ## you may not use this file except in compliance with the License.
  5. ## You may obtain a copy of the License at
  6. ##
  7. ## http://www.apache.org/licenses/LICENSE-2.0
  8. ##
  9. ## Unless required by applicable law or agreed to in writing, software
  10. ## distributed under the License is distributed on an "AS IS" BASIS,
  11. ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ## See the License for the specific language governing permissions and
  13. ## limitations under the License.
  14. #-----------------------------------------------------------------------------
  15. # Global Variables
  16. #-----------------------------------------------------------------------------
  17. ISTIO_GO := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
  18. export ISTIO_GO
  19. SHELL := /bin/bash -o pipefail
  20. VERSION ?= 1.5-dev
  21. # Base version of Istio image to use
  22. BASE_VERSION ?= 1.4-dev.2
  23. export GO111MODULE ?= on
  24. export GOPROXY ?= https://proxy.golang.org
  25. export GOSUMDB ?= sum.golang.org
  26. # locations where artifacts are stored
  27. ISTIO_DOCKER_HUB ?= docker.io/istio
  28. export ISTIO_DOCKER_HUB
  29. ISTIO_GCS ?= istio-release/releases/$(VERSION)
  30. ISTIO_URL ?= https://storage.googleapis.com/$(ISTIO_GCS)
  31. ISTIO_CNI_HUB ?= gcr.io/istio-testing
  32. export ISTIO_CNI_HUB
  33. ISTIO_CNI_TAG ?= latest
  34. export ISTIO_CNI_TAG
  35. # cumulatively track the directories/files to delete after a clean
  36. DIRS_TO_CLEAN:=
  37. FILES_TO_CLEAN:=
  38. # If GOPATH is not set by the env, set it to a sane value
  39. GOPATH ?= $(shell cd ${ISTIO_GO}/../../..; pwd)
  40. export GOPATH
  41. # If GOPATH is made up of several paths, use the first one for our targets in this Makefile
  42. GO_TOP := $(shell echo ${GOPATH} | cut -d ':' -f1)
  43. export GO_TOP
  44. # Note that disabling cgo here adversely affects go get. Instead we'll rely on this
  45. # to be handled in common/scripts/gobuild.sh
  46. # export CGO_ENABLED=0
  47. # It's more concise to use GO?=$(shell which go)
  48. # but the following approach uses a more efficient "simply expanded" :=
  49. # variable instead of a "recursively expanded" =
  50. ifeq ($(origin GO), undefined)
  51. GO:=$(shell which go)
  52. endif
  53. ifeq ($(GO),)
  54. $(error Could not find 'go' in path. Please install go, or if already installed either add it to your path or set GO to point to its directory)
  55. endif
  56. LOCAL_ARCH := $(shell uname -m)
  57. ifeq ($(LOCAL_ARCH),x86_64)
  58. GOARCH_LOCAL := amd64
  59. else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
  60. GOARCH_LOCAL := arm64
  61. else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
  62. GOARCH_LOCAL := arm
  63. else
  64. GOARCH_LOCAL := $(LOCAL_ARCH)
  65. endif
  66. export GOARCH ?= $(GOARCH_LOCAL)
  67. LOCAL_OS := $(shell uname)
  68. ifeq ($(LOCAL_OS),Linux)
  69. export GOOS_LOCAL = linux
  70. else ifeq ($(LOCAL_OS),Darwin)
  71. export GOOS_LOCAL = darwin
  72. else
  73. $(error "This system's OS $(LOCAL_OS) isn't recognized/supported")
  74. # export GOOS_LOCAL ?= windows
  75. endif
  76. export GOOS ?= $(GOOS_LOCAL)
  77. export ENABLE_COREDUMP ?= false
  78. # Enable Istio CNI in helm template commands
  79. export ENABLE_ISTIO_CNI ?= false
  80. # NOTE: env var EXTRA_HELM_SETTINGS can contain helm chart override settings, example:
  81. # EXTRA_HELM_SETTINGS="--set istio-cni.excludeNamespaces={} --set-string istio-cni.tag=v0.1-dev-foo"
  82. #-----------------------------------------------------------------------------
  83. # Output control
  84. #-----------------------------------------------------------------------------
  85. # Invoke make VERBOSE=1 to enable echoing of the command being executed
  86. export VERBOSE ?= 0
  87. # Place the variable Q in front of a command to control echoing of the command being executed.
  88. Q = $(if $(filter 1,$VERBOSE),,@)
  89. # Use the variable H to add a header (equivalent to =>) to informational output
  90. H = $(shell printf "\033[34;1m=>\033[0m")
  91. # To build Pilot, Mixer and CA with debugger information, use DEBUG=1 when invoking make
  92. goVerStr := $(shell $(GO) version | awk '{split($$0,a," ")}; {print a[3]}')
  93. goVerNum := $(shell echo $(goVerStr) | awk '{split($$0,a,"go")}; {print a[2]}')
  94. goVerMajor := $(shell echo $(goVerNum) | awk '{split($$0, a, ".")}; {print a[1]}')
  95. goVerMinor := $(shell echo $(goVerNum) | awk '{split($$0, a, ".")}; {print a[2]}' | sed -e 's/\([0-9]\+\).*/\1/')
  96. gcflagsPattern := $(shell ( [ $(goVerMajor) -ge 1 ] && [ ${goVerMinor} -ge 10 ] ) && echo 'all=' || echo '')
  97. ifeq ($(origin DEBUG), undefined)
  98. BUILDTYPE_DIR:=release
  99. else ifeq ($(DEBUG),0)
  100. BUILDTYPE_DIR:=release
  101. else
  102. BUILDTYPE_DIR:=debug
  103. export GCFLAGS:=$(gcflagsPattern)-N -l
  104. $(info $(H) Build with debugger information)
  105. endif
  106. # Optional file including user-specific settings (HUB, TAG, etc)
  107. -include .istiorc.mk
  108. # @todo allow user to run for a single $PKG only?
  109. PACKAGES_CMD := GOPATH=$(GOPATH) $(GO) list ./...
  110. GO_EXCLUDE := /vendor/|.pb.go|.gen.go
  111. GO_FILES_CMD := find . -name '*.go' | grep -v -E '$(GO_EXCLUDE)'
  112. # Environment for tests, the directory containing istio and deps binaries.
  113. # Typically same as GOPATH/bin, so tests work seemlessly with IDEs.
  114. export ISTIO_BIN=$(GO_TOP)/bin
  115. # Using same package structure as pkg/
  116. export OUT_DIR=$(GO_TOP)/out
  117. export ISTIO_OUT:=$(OUT_DIR)/$(GOOS)_$(GOARCH)/$(BUILDTYPE_DIR)
  118. export ISTIO_OUT_LINUX:=$(OUT_DIR)/linux_amd64/$(BUILDTYPE_DIR)
  119. export HELM=$(ISTIO_OUT)/helm
  120. export ARTIFACTS ?= $(ISTIO_OUT)
  121. export REPO_ROOT := $(shell git rev-parse --show-toplevel)
  122. # scratch dir: this shouldn't be simply 'docker' since that's used for docker.save to store tar.gz files
  123. ISTIO_DOCKER:=${ISTIO_OUT_LINUX}/docker_temp
  124. # Config file used for building istio:proxy container.
  125. DOCKER_PROXY_CFG?=Dockerfile.proxy
  126. # scratch dir for building isolated images. Please don't remove it again - using
  127. # ISTIO_DOCKER results in slowdown, all files (including multiple copies of envoy) will be
  128. # copied to the docker temp container - even if you add only a tiny file, >1G of data will
  129. # be copied, for each docker image.
  130. DOCKER_BUILD_TOP:=${ISTIO_OUT_LINUX}/docker_build
  131. # dir where tar.gz files from docker.save are stored
  132. ISTIO_DOCKER_TAR:=${ISTIO_OUT_LINUX}/docker
  133. # Populate the git version for istio/proxy (i.e. Envoy)
  134. ifeq ($(PROXY_REPO_SHA),)
  135. export PROXY_REPO_SHA:=$(shell grep PROXY_REPO_SHA istio.deps -A 4 | grep lastStableSHA | cut -f 4 -d '"')
  136. endif
  137. # Envoy binary variables Keep the default URLs up-to-date with the latest push from istio/proxy.
  138. # OS-neutral vars. These currently only work for linux.
  139. export ISTIO_ENVOY_VERSION ?= ${PROXY_REPO_SHA}
  140. export ISTIO_ENVOY_DEBUG_URL ?= https://storage.googleapis.com/istio-build/proxy/envoy-debug-$(ISTIO_ENVOY_VERSION).tar.gz
  141. export ISTIO_ENVOY_RELEASE_URL ?= https://storage.googleapis.com/istio-build/proxy/envoy-alpha-$(ISTIO_ENVOY_VERSION).tar.gz
  142. # Envoy Linux vars.
  143. export ISTIO_ENVOY_LINUX_VERSION ?= ${ISTIO_ENVOY_VERSION}
  144. export ISTIO_ENVOY_LINUX_DEBUG_URL ?= ${ISTIO_ENVOY_DEBUG_URL}
  145. export ISTIO_ENVOY_LINUX_RELEASE_URL ?= ${ISTIO_ENVOY_RELEASE_URL}
  146. # Variables for the extracted debug/release Envoy artifacts.
  147. export ISTIO_ENVOY_LINUX_DEBUG_DIR ?= ${OUT_DIR}/linux_amd64/debug
  148. export ISTIO_ENVOY_LINUX_DEBUG_NAME ?= envoy-debug-${ISTIO_ENVOY_LINUX_VERSION}
  149. export ISTIO_ENVOY_LINUX_DEBUG_PATH ?= ${ISTIO_ENVOY_LINUX_DEBUG_DIR}/${ISTIO_ENVOY_LINUX_DEBUG_NAME}
  150. export ISTIO_ENVOY_LINUX_RELEASE_DIR ?= ${OUT_DIR}/linux_amd64/release
  151. export ISTIO_ENVOY_LINUX_RELEASE_NAME ?= envoy-${ISTIO_ENVOY_VERSION}
  152. export ISTIO_ENVOY_LINUX_RELEASE_PATH ?= ${ISTIO_ENVOY_LINUX_RELEASE_DIR}/${ISTIO_ENVOY_LINUX_RELEASE_NAME}
  153. # Envoy macOS vars.
  154. # TODO Change url when official envoy release for macOS is available
  155. export ISTIO_ENVOY_MACOS_VERSION ?= 1.0.2
  156. export ISTIO_ENVOY_MACOS_RELEASE_URL ?= https://github.com/istio/proxy/releases/download/${ISTIO_ENVOY_MACOS_VERSION}/istio-proxy-${ISTIO_ENVOY_MACOS_VERSION}-macos.tar.gz
  157. # Variables for the extracted debug/release Envoy artifacts.
  158. export ISTIO_ENVOY_MACOS_RELEASE_DIR ?= ${OUT_DIR}/darwin_amd64/release
  159. export ISTIO_ENVOY_MACOS_RELEASE_NAME ?= envoy-${ISTIO_ENVOY_MACOS_VERSION}
  160. export ISTIO_ENVOY_MACOS_RELEASE_PATH ?= ${ISTIO_ENVOY_MACOS_RELEASE_DIR}/${ISTIO_ENVOY_MACOS_RELEASE_NAME}
  161. # Allow user-override for a local Envoy build.
  162. export USE_LOCAL_PROXY ?= 0
  163. ifeq ($(USE_LOCAL_PROXY),1)
  164. export ISTIO_ENVOY_LOCAL ?= $(realpath ${ISTIO_GO}/../proxy/bazel-bin/src/envoy/envoy)
  165. # Point the native paths to the local envoy build.
  166. ifeq ($(GOOS_LOCAL), Darwin)
  167. export ISTIO_ENVOY_MACOS_RELEASE_DIR = $(dir ${ISTIO_ENVOY_LOCAL})
  168. export ISTIO_ENVOY_MACOS_RELEASE_PATH = ${ISTIO_ENVOY_LOCAL}
  169. else
  170. export ISTIO_ENVOY_LINUX_DEBUG_DIR = $(dir ${ISTIO_ENVOY_LOCAL})
  171. export ISTIO_ENVOY_LINUX_RELEASE_DIR = $(dir ${ISTIO_ENVOY_LOCAL})
  172. export ISTIO_ENVOY_LINUX_DEBUG_PATH = ${ISTIO_ENVOY_LOCAL}
  173. export ISTIO_ENVOY_LINUX_RELEASE_PATH = ${ISTIO_ENVOY_LOCAL}
  174. endif
  175. endif
  176. GO_VERSION_REQUIRED:=1.10
  177. HUB?=istio
  178. ifeq ($(HUB),)
  179. $(error "HUB cannot be empty")
  180. endif
  181. # If tag not explicitly set in users' .istiorc.mk or command line, default to the git sha.
  182. TAG ?= $(shell git rev-parse --verify HEAD)
  183. ifeq ($(TAG),)
  184. $(error "TAG cannot be empty")
  185. endif
  186. VARIANT :=
  187. ifeq ($(VARIANT),)
  188. TAG_VARIANT:=${TAG}
  189. else
  190. TAG_VARIANT:=${TAG}-${VARIANT}
  191. endif
  192. PULL_POLICY ?= IfNotPresent
  193. ifeq ($(TAG),latest)
  194. PULL_POLICY = Always
  195. endif
  196. ifeq ($(PULL_POLICY),)
  197. $(error "PULL_POLICY cannot be empty")
  198. endif
  199. GEN_CERT := ${ISTIO_BIN}/generate_cert
  200. # Set Google Storage bucket if not set
  201. GS_BUCKET ?= istio-artifacts
  202. .PHONY: default
  203. default: depend build test
  204. # The point of these is to allow scripts to query where artifacts
  205. # are stored so that tests and other consumers of the build don't
  206. # need to be updated to follow the changes in the Makefiles.
  207. # Note that the query needs to pass the same types of parameters
  208. # (e.g., DEBUG=0, GOOS=linux) as the actual build for the query
  209. # to provide an accurate result.
  210. .PHONY: where-is-out where-is-docker-temp where-is-docker-tar
  211. where-is-out:
  212. @echo ${ISTIO_OUT}
  213. where-is-docker-temp:
  214. @echo ${ISTIO_DOCKER}
  215. where-is-docker-tar:
  216. @echo ${ISTIO_DOCKER_TAR}
  217. #-----------------------------------------------------------------------------
  218. # Target: depend
  219. #-----------------------------------------------------------------------------
  220. .PHONY: depend init
  221. # Parse out the x.y or x.y.z version and output a single value x*10000+y*100+z (e.g., 1.9 is 10900)
  222. # that allows the three components to be checked in a single comparison.
  223. VER_TO_INT:=awk '{split(substr($$0, match ($$0, /[0-9\.]+/)), a, "."); print a[1]*10000+a[2]*100+a[3]}'
  224. # using a sentinel file so this check is only performed once per version. Performance is
  225. # being favored over the unlikely situation that go gets downgraded to an older version
  226. check-go-version: | $(ISTIO_BIN) ${ISTIO_BIN}/have_go_$(GO_VERSION_REQUIRED)
  227. ${ISTIO_BIN}/have_go_$(GO_VERSION_REQUIRED):
  228. @if test $(shell $(GO) version | $(VER_TO_INT) ) -lt \
  229. $(shell echo "$(GO_VERSION_REQUIRED)" | $(VER_TO_INT) ); \
  230. then printf "go version $(GO_VERSION_REQUIRED)+ required, found: "; $(GO) version; exit 1; fi
  231. @touch ${ISTIO_BIN}/have_go_$(GO_VERSION_REQUIRED)
  232. # Downloads envoy, based on the SHA defined in the base pilot Dockerfile
  233. init: check-go-version $(ISTIO_OUT)/istio_is_init
  234. mkdir -p ${OUT_DIR}/logs
  235. # Sync is the same as init in release branch. In master this pulls from master.
  236. sync: init
  237. # I tried to make this dependent on what I thought was the appropriate
  238. # lock file, but it caused the rule for that file to get run (which
  239. # seems to be about obtaining a new version of the 3rd party libraries).
  240. $(ISTIO_OUT)/istio_is_init: bin/init.sh istio.deps | $(ISTIO_OUT)
  241. ISTIO_OUT=$(ISTIO_OUT) bin/init.sh
  242. touch $(ISTIO_OUT)/istio_is_init
  243. # init.sh downloads envoy
  244. ${ISTIO_OUT}/envoy: init
  245. ${ISTIO_ENVOY_LINUX_DEBUG_PATH}: init
  246. ${ISTIO_ENVOY_LINUX_RELEASE_PATH}: init
  247. ${ISTIO_ENVOY_MACOS_RELEASE_PATH}: init
  248. # Pull dependencies, based on the checked in Gopkg.lock file.
  249. # Developers must manually run `dep ensure` if adding new deps
  250. depend: init | $(ISTIO_OUT)
  251. OUTPUT_DIRS = $(ISTIO_OUT) $(ISTIO_BIN)
  252. DIRS_TO_CLEAN+=${ISTIO_OUT}
  253. ifneq ($(ISTIO_OUT),$(ISTIO_OUT_LINUX))
  254. OUTPUT_DIRS += $(ISTIO_OUT_LINUX)
  255. DIRS_TO_CLEAN += $(ISTIO_OUT_LINUX)
  256. endif
  257. $(OUTPUT_DIRS):
  258. @mkdir -p $@
  259. .PHONY: ${GEN_CERT}
  260. ${GEN_CERT}:
  261. GOOS=$(GOOS_LOCAL) && GOARCH=$(GOARCH_LOCAL) && CGO_ENABLED=1 common/scripts/gobuild.sh $@ ./security/tools/generate_cert
  262. #-----------------------------------------------------------------------------
  263. # Target: precommit
  264. #-----------------------------------------------------------------------------
  265. .PHONY: precommit format format.gofmt format.goimports lint buildcache
  266. # Target run by the pre-commit script, to automate formatting and lint
  267. # If pre-commit script is not used, please run this manually.
  268. precommit: format lint
  269. format: fmt
  270. fmt: format-go format-python
  271. go mod tidy
  272. # Build with -i to store the build caches into $GOPATH/pkg
  273. buildcache:
  274. GOBUILDFLAGS=-i $(MAKE) -f Makefile.core.mk build
  275. # List of all binaries to build
  276. BINARIES:=./istioctl/cmd/istioctl \
  277. ./pilot/cmd/pilot-discovery \
  278. ./pilot/cmd/pilot-agent \
  279. ./sidecar-injector/cmd/sidecar-injector \
  280. ./mixer/cmd/mixs \
  281. ./mixer/cmd/mixc \
  282. ./mixer/tools/mixgen \
  283. ./galley/cmd/galley \
  284. ./security/cmd/node_agent \
  285. ./security/cmd/node_agent_k8s \
  286. ./security/cmd/istio_ca \
  287. ./security/tools/sdsclient \
  288. ./pkg/test/echo/cmd/client \
  289. ./pkg/test/echo/cmd/server \
  290. ./mixer/test/policybackend \
  291. ./tools/hyperistio \
  292. ./tools/istio-iptables \
  293. ./tools/istio-clean-iptables
  294. # List of binaries included in releases
  295. RELEASE_BINARIES:=pilot-discovery pilot-agent sidecar-injector mixc mixs mixgen node_agent node_agent_k8s istio_ca istioctl galley sdsclient
  296. .PHONY: build
  297. build: depend
  298. STATIC=0 GOOS=$(GOOS) GOARCH=$(GOARCH) LDFLAGS='-extldflags -static -s -w' common/scripts/gobuild.sh $(ISTIO_OUT)/ $(BINARIES)
  299. .PHONY: build-linux
  300. build-linux: depend
  301. STATIC=0 GOOS=linux GOARCH=amd64 LDFLAGS='-extldflags -static -s -w' common/scripts/gobuild.sh $(ISTIO_OUT_LINUX)/ $(BINARIES)
  302. # Create targets for ISTIO_OUT_LINUX/binary
  303. $(foreach bin,$(BINARIES),$(ISTIO_OUT_LINUX)/$(shell basename $(bin))): build-linux
  304. # Create helper targets for each binary, like "pilot-discovery"
  305. # As an optimization, these still build everything
  306. $(foreach bin,$(BINARIES),$(shell basename $(bin))): build
  307. MARKDOWN_LINT_WHITELIST=localhost:8080,storage.googleapis.com/istio-artifacts/pilot/,http://ratings.default.svc.cluster.local:9080/ratings
  308. lint: lint-python lint-copyright-banner lint-scripts lint-dockerfiles lint-markdown lint-yaml lint-licenses
  309. @bin/check_helm.sh
  310. @bin/check_samples.sh
  311. @bin/check_dashboards.sh
  312. @go run mixer/tools/adapterlinter/main.go ./mixer/adapter/...
  313. @golangci-lint run -c ./common/config/.golangci.yml ./galley/...
  314. @golangci-lint run -c ./common/config/.golangci.yml ./istioctl/...
  315. @golangci-lint run -c ./common/config/.golangci.yml ./mixer/...
  316. @golangci-lint run -c ./common/config/.golangci.yml ./pilot/...
  317. @golangci-lint run -c ./common/config/.golangci.yml ./pkg/...
  318. @golangci-lint run -c ./common/config/.golangci.yml ./samples/...
  319. @golangci-lint run -c ./common/config/.golangci.yml ./security/...
  320. @golangci-lint run -c ./common/config/.golangci.yml ./sidecar-injector/...
  321. @golangci-lint run -c ./common/config/.golangci.yml ./tests/...
  322. @golangci-lint run -c ./common/config/.golangci.yml ./tools/...
  323. @testlinter
  324. @envvarlinter galley istioctl mixer pilot security sidecar-injector
  325. gen:
  326. @mkdir -p /tmp/bin
  327. @go build -o /tmp/bin/mixgen "${REPO_ROOT}/mixer/tools/mixgen/main.go"
  328. @PATH=${PATH}:/tmp/bin go generate ./...
  329. gen-check: gen check-clean-repo
  330. #-----------------------------------------------------------------------------
  331. # Target: go build
  332. #-----------------------------------------------------------------------------
  333. # gobuild script uses custom linker flag to set the variables.
  334. # Params: OUT VERSION_PKG SRC
  335. RELEASE_LDFLAGS='-extldflags -static -s -w'
  336. DEBUG_LDFLAGS='-extldflags "-static"'
  337. # Non-static istioctl targets. These are typically a build artifact.
  338. ${ISTIO_OUT}/istioctl-linux: depend
  339. STATIC=0 GOOS=linux LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $@ ./istioctl/cmd/istioctl
  340. ${ISTIO_OUT}/istioctl-osx: depend
  341. STATIC=0 GOOS=darwin LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $@ ./istioctl/cmd/istioctl
  342. ${ISTIO_OUT}/istioctl-win.exe: depend
  343. STATIC=0 GOOS=windows LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $@ ./istioctl/cmd/istioctl
  344. # generate the istioctl completion files
  345. ${ISTIO_OUT}/istioctl.bash: istioctl
  346. ${ISTIO_OUT}/istioctl collateral --bash && \
  347. mv istioctl.bash ${ISTIO_OUT}/istioctl.bash
  348. ${ISTIO_OUT}/_istioctl: istioctl
  349. ${ISTIO_OUT}/istioctl collateral --zsh && \
  350. mv _istioctl ${ISTIO_OUT}/_istioctl
  351. .PHONY: binaries-test
  352. binaries-test:
  353. go test ./tests/binary/... -v --base-dir ${ISTIO_OUT} --binaries="$(RELEASE_BINARIES)"
  354. # istioctl-all makes all of the non-static istioctl executables for each supported OS
  355. .PHONY: istioctl-all
  356. istioctl-all: ${ISTIO_OUT}/istioctl-linux ${ISTIO_OUT}/istioctl-osx ${ISTIO_OUT}/istioctl-win.exe
  357. .PHONY: istioctl.completion
  358. istioctl.completion: ${ISTIO_OUT}/istioctl.bash ${ISTIO_OUT}/_istioctl
  359. .PHONY: istio-archive
  360. istio-archive: ${ISTIO_OUT}/archive
  361. # TBD: how to capture VERSION, ISTIO_DOCKER_HUB, ISTIO_URL as dependencies
  362. ${ISTIO_OUT}/archive: istioctl-all istioctl.completion LICENSE README.md install/updateVersion.sh release/create_release_archives.sh
  363. rm -rf ${ISTIO_OUT}/archive
  364. mkdir -p ${ISTIO_OUT}/archive/istioctl
  365. cp ${ISTIO_OUT}/istioctl-* ${ISTIO_OUT}/archive/istioctl/
  366. cp LICENSE ${ISTIO_OUT}/archive
  367. cp README.md ${ISTIO_OUT}/archive
  368. cp -r tools ${ISTIO_OUT}/archive
  369. cp ${ISTIO_OUT}/istioctl.bash ${ISTIO_OUT}/archive/tools/
  370. cp ${ISTIO_OUT}/_istioctl ${ISTIO_OUT}/archive/tools/
  371. ISTIO_RELEASE=1 install/updateVersion.sh -a "$(ISTIO_DOCKER_HUB),$(VERSION)" \
  372. -P "$(ISTIO_URL)/deb" \
  373. -d "${ISTIO_OUT}/archive"
  374. release/create_release_archives.sh -v "$(VERSION)" -o "${ISTIO_OUT}/archive"
  375. # istioctl-install builds then installs istioctl into $GOPATH/BIN
  376. # Used for debugging istioctl during dev work
  377. .PHONY: istioctl-install
  378. istioctl-install:
  379. go install istio.io/istio/istioctl/cmd/istioctl
  380. #-----------------------------------------------------------------------------
  381. # Target: test
  382. #-----------------------------------------------------------------------------
  383. .PHONY: test localTestEnv
  384. JUNIT_REPORT := $(shell which go-junit-report 2> /dev/null || echo "${ISTIO_BIN}/go-junit-report")
  385. ${ISTIO_BIN}/go-junit-report:
  386. @echo "go-junit-report not found. Installing it now..."
  387. unset GOOS && unset GOARCH && CGO_ENABLED=1 go get -u github.com/jstemmer/go-junit-report
  388. # Run coverage tests
  389. JUNIT_UNIT_TEST_XML ?= $(ARTIFACTS)/junit_unit-tests.xml
  390. ifeq ($(WHAT),)
  391. TEST_OBJ = common-test pilot-test mixer-test security-test galley-test istioctl-test
  392. else
  393. TEST_OBJ = selected-pkg-test
  394. endif
  395. test: | $(JUNIT_REPORT)
  396. mkdir -p $(dir $(JUNIT_UNIT_TEST_XML))
  397. KUBECONFIG="$${KUBECONFIG:-$${REPO_ROOT}/tests/util/kubeconfig}" \
  398. $(MAKE) -f Makefile.core.mk --keep-going $(TEST_OBJ) \
  399. 2>&1 | tee >($(JUNIT_REPORT) > $(JUNIT_UNIT_TEST_XML))
  400. GOTEST_PARALLEL ?= '-test.parallel=1'
  401. localTestEnv: build
  402. bin/testEnvLocalK8S.sh ensure
  403. localTestEnvCleanup: build
  404. bin/testEnvLocalK8S.sh stop
  405. .PHONY: pilot-test
  406. pilot-test:
  407. go test ${T} ./pilot/...
  408. .PHONY: istioctl-test
  409. istioctl-test:
  410. go test ${T} ./istioctl/...
  411. .PHONY: mixer-test
  412. MIXER_TEST_T ?= ${T} ${GOTEST_PARALLEL}
  413. mixer-test:
  414. # Some tests use relative path "testdata", must be run from mixer dir
  415. (cd mixer; go test ${MIXER_TEST_T} ./...)
  416. .PHONY: galley-test
  417. galley-test:
  418. go test ${T} ./galley/...
  419. .PHONY: security-test
  420. security-test:
  421. go test ${T} ./security/pkg/...
  422. go test ${T} ./security/cmd/...
  423. .PHONY: common-test
  424. common-test: build
  425. go test ${T} ./pkg/...
  426. go test ${T} ./tests/common/...
  427. # Execute bash shell unit tests scripts
  428. ./tests/scripts/scripts_test.sh
  429. ./tests/scripts/istio-iptables-test.sh
  430. .PHONY: selected-pkg-test
  431. selected-pkg-test:
  432. find ${WHAT} -name "*_test.go" | xargs -I {} dirname {} | uniq | xargs -I {} go test ${T} ./{}
  433. #-----------------------------------------------------------------------------
  434. # Target: coverage
  435. #-----------------------------------------------------------------------------
  436. .PHONY: coverage
  437. # Run coverage tests
  438. coverage: pilot-coverage mixer-coverage security-coverage galley-coverage common-coverage istioctl-coverage
  439. coverage-diff:
  440. ./bin/codecov_diff.sh
  441. .PHONY: pilot-coverage
  442. pilot-coverage:
  443. bin/codecov.sh pilot
  444. .PHONY: istioctl-coverage
  445. istioctl-coverage:
  446. bin/codecov.sh istioctl
  447. .PHONY: mixer-coverage
  448. mixer-coverage:
  449. bin/codecov.sh mixer
  450. .PHONY: galley-coverage
  451. galley-coverage:
  452. bin/codecov.sh galley
  453. .PHONY: security-coverage
  454. security-coverage:
  455. bin/codecov.sh security/pkg
  456. bin/codecov.sh security/cmd
  457. .PHONY: common-coverage
  458. common-coverage:
  459. bin/codecov.sh pkg
  460. #-----------------------------------------------------------------------------
  461. # Target: go test -race
  462. #-----------------------------------------------------------------------------
  463. .PHONY: racetest
  464. RACE_TESTS ?= pilot-racetest mixer-racetest security-racetest galley-test common-racetest istioctl-racetest
  465. racetest: $(JUNIT_REPORT)
  466. mkdir -p $(dir $(JUNIT_UNIT_TEST_XML))
  467. $(MAKE) -f Makefile.core.mk --keep-going $(RACE_TESTS) \
  468. 2>&1 | tee >($(JUNIT_REPORT) > $(JUNIT_UNIT_TEST_XML))
  469. .PHONY: pilot-racetest
  470. pilot-racetest:
  471. RACE_TEST=true go test ${T} -race ./pilot/...
  472. .PHONY: istioctl-racetest
  473. istioctl-racetest:
  474. RACE_TEST=true go test ${T} -race ./istioctl/...
  475. .PHONY: mixer-racetest
  476. mixer-racetest:
  477. # Some tests use relative path "testdata", must be run from mixer dir
  478. (cd mixer; RACE_TEST=true go test ${T} -race ./...)
  479. .PHONY: galley-racetest
  480. galley-racetest:
  481. RACE_TEST=true go test ${T} -race ./galley/...
  482. .PHONY: security-racetest
  483. security-racetest:
  484. RACE_TEST=true go test ${T} -race ./security/pkg/... ./security/cmd/...
  485. .PHONY: common-racetest
  486. common-racetest:
  487. RACE_TEST=true go test ${T} -race ./pkg/...
  488. #-----------------------------------------------------------------------------
  489. # Target: clean
  490. #-----------------------------------------------------------------------------
  491. .PHONY: clean clean.go
  492. clean: clean.go
  493. rm -rf $(DIRS_TO_CLEAN)
  494. rm -f $(FILES_TO_CLEAN)
  495. clean.go: ; $(info $(H) cleaning...)
  496. $(eval GO_CLEAN_FLAGS := -i -r)
  497. $(Q) $(GO) clean $(GO_CLEAN_FLAGS)
  498. #-----------------------------------------------------------------------------
  499. # Target: docker
  500. #-----------------------------------------------------------------------------
  501. .PHONY: push artifacts installgen
  502. # for now docker is limited to Linux compiles - why ?
  503. include tools/istio-docker.mk
  504. push: docker.push installgen
  505. # generate_yaml in tests/istio.mk can build without specifying a hub & tag
  506. installgen:
  507. install/updateVersion.sh -a ${HUB},${TAG}
  508. $(MAKE) -f Makefile.core.mk istio.yaml
  509. $(HELM): $(ISTIO_OUT)
  510. bin/init_helm.sh
  511. $(HOME)/.helm:
  512. $(HELM) init --client-only
  513. # create istio-init.yaml
  514. istio-init.yaml: $(HELM) $(HOME)/.helm
  515. cat install/kubernetes/namespace.yaml > install/kubernetes/$@
  516. cat install/kubernetes/helm/istio-init/files/crd-* >> install/kubernetes/$@
  517. $(HELM) template --name=istio --namespace=istio-system \
  518. --set-string global.tag=${TAG_VARIANT} \
  519. --set-string global.hub=${HUB} \
  520. install/kubernetes/helm/istio-init >> install/kubernetes/$@
  521. # creates istio-demo.yaml istio-remote.yaml
  522. # Ensure that values-$filename is present in install/kubernetes/helm/istio
  523. istio-demo.yaml istio-remote.yaml istio-minimal.yaml: $(HELM) $(HOME)/.helm
  524. cat install/kubernetes/namespace.yaml > install/kubernetes/$@
  525. cat install/kubernetes/helm/istio-init/files/crd-* >> install/kubernetes/$@
  526. $(HELM) template \
  527. --name=istio \
  528. --namespace=istio-system \
  529. --set-string global.tag=${TAG_VARIANT} \
  530. --set-string global.hub=${HUB} \
  531. --set-string global.imagePullPolicy=$(PULL_POLICY) \
  532. --set global.proxy.enableCoreDump=${ENABLE_COREDUMP} \
  533. --set istio_cni.enabled=${ENABLE_ISTIO_CNI} \
  534. ${EXTRA_HELM_SETTINGS} \
  535. --values install/kubernetes/helm/istio/values-$@ \
  536. install/kubernetes/helm/istio >> install/kubernetes/$@
  537. e2e_files = istio-auth-non-mcp.yaml \
  538. istio-auth-sds.yaml \
  539. istio-non-mcp.yaml \
  540. istio.yaml \
  541. istio-auth.yaml \
  542. istio-auth-mcp.yaml \
  543. istio-auth-multicluster.yaml \
  544. istio-mcp.yaml \
  545. istio-one-namespace.yaml \
  546. istio-one-namespace-auth.yaml \
  547. istio-one-namespace-trust-domain.yaml \
  548. istio-multicluster.yaml \
  549. istio-multicluster-split-horizon.yaml \
  550. .PHONY: generate_e2e_yaml generate_e2e_yaml_coredump
  551. generate_e2e_yaml: $(e2e_files)
  552. generate_e2e_yaml_coredump: export ENABLE_COREDUMP=true
  553. generate_e2e_yaml_coredump:
  554. $(MAKE) -f Makefile.core.mk generate_e2e_yaml
  555. # Create yaml files for e2e tests. Applies values-e2e.yaml, then values-$filename.yaml
  556. $(e2e_files): $(HELM) $(HOME)/.helm istio-init.yaml
  557. cat install/kubernetes/namespace.yaml > install/kubernetes/$@
  558. cat install/kubernetes/helm/istio-init/files/crd-* >> install/kubernetes/$@
  559. $(HELM) template \
  560. --name=istio \
  561. --namespace=istio-system \
  562. --set-string global.tag=${TAG_VARIANT} \
  563. --set-string global.hub=${HUB} \
  564. --set-string global.imagePullPolicy=$(PULL_POLICY) \
  565. --set global.proxy.enableCoreDump=${ENABLE_COREDUMP} \
  566. --set istio_cni.enabled=${ENABLE_ISTIO_CNI} \
  567. ${EXTRA_HELM_SETTINGS} \
  568. --values install/kubernetes/helm/istio/test-values/values-e2e.yaml \
  569. --values install/kubernetes/helm/istio/test-values/values-$@ \
  570. install/kubernetes/helm/istio >> install/kubernetes/$@
  571. # files generated by the default invocation of updateVersion.sh
  572. FILES_TO_CLEAN+=install/consul/istio.yaml \
  573. install/kubernetes/istio-auth.yaml \
  574. install/kubernetes/istio-citadel-plugin-certs.yaml \
  575. install/kubernetes/istio-citadel-with-health-check.yaml \
  576. install/kubernetes/istio-one-namespace-auth.yaml \
  577. install/kubernetes/istio-one-namespace-trust-domain.yaml \
  578. install/kubernetes/istio-one-namespace.yaml \
  579. install/kubernetes/istio.yaml \
  580. samples/bookinfo/platform/consul/bookinfo.sidecars.yaml \
  581. #-----------------------------------------------------------------------------
  582. # Target: environment and tools
  583. #-----------------------------------------------------------------------------
  584. .PHONY: show.env show.goenv
  585. show.env: ; $(info $(H) environment variables...)
  586. $(Q) printenv
  587. show.goenv: ; $(info $(H) go environment...)
  588. $(Q) $(GO) version
  589. $(Q) $(GO) env
  590. # tickle
  591. # show makefile variables. Usage: make show.<variable-name>
  592. show.%: ; $(info $* $(H) $($*))
  593. $(Q) true
  594. #-----------------------------------------------------------------------------
  595. # Target: artifacts and distribution
  596. #-----------------------------------------------------------------------------
  597. # deb, rpm, etc packages
  598. include tools/packaging/packaging.mk
  599. #-----------------------------------------------------------------------------
  600. # Target: e2e tests
  601. #-----------------------------------------------------------------------------
  602. include tests/istio.mk
  603. #-----------------------------------------------------------------------------
  604. # Target: integration tests
  605. #-----------------------------------------------------------------------------
  606. include tests/integration/tests.mk
  607. include common/Makefile.common.mk