如何編譯 Istio?

語言: CN / TW / HK

本文將指導你如何在 macOS 上編譯 Istio 二進位制檔案。

構建前的準備

在正式開始構建前, 參考這篇文件 ,以下是我的構建環境資訊:

  • macOS 12.3.1 Darwin AMD64
  • Docker Desktop 4.8.1(78998)
  • Docker Engine v20.10.14

開始構建

參考 這篇文件 編譯 Istio。

首先在 GitHub 上 下載 Istio 程式碼,將程式碼下載到 $GOPATH/src/istio.io/istio 目錄下,下文中的命令都在該根目錄下執行。

執行下面的命令下載 Istio 依賴的包,這些包將下載到 vendor 目錄下:

go mod vendor

然後執行下面的命令構建 Istio:

sudo make build

如果你沒有在命令前加 sudo ,你還是可能遇到下面的錯誤:

fatal: unsafe repository ('/work' is owned by someone else)
To add an exception for this directory, call:

	git config --global --add safe.directory /work
fatal: unsafe repository ('/work' is owned by someone else)
To add an exception for this directory, call:

	git config --global --add safe.directory /work
Makefile.core.mk:170: *** "TAG cannot be empty".  Stop.
make: *** [build] Error 2

構建完的二進位制檔案將儲存在 out 目錄下,其目錄結構如下:

out
├── darwin_amd64
│   ├── bug-report
│   ├── client
│   ├── envoy
│   ├── extauthz
│   ├── install-cni
│   ├── istio-cni
│   ├── istio-cni-taint
│   ├── istio-iptables
│   ├── istio_is_init
│   ├── istioctl
│   ├── logs
│   ├── operator
│   ├── pilot-agent
│   ├── pilot-discovery
│   ├── release
│   └── server
└── linux_amd64
    ├── envoy
    ├── envoy-centos
    ├── logs
    └── release

同時構建出了 linux_amd64darwin_amd64 架構的二進位制檔案。

總結

以上就是在 macOS 上構建 Istio 的過程,如果你已經下載好了構建所需要的的 Docker 映象,那麼構建時間將不超過一分鐘。

參考