Skip to content

Commit

Permalink
doc: describe the GOOS and GOARCH variables
Browse files Browse the repository at this point in the history
  • Loading branch information
linfan committed May 30, 2022
1 parent 71617db commit e2c1fdf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ check:

# build ktctl
ktctl:
go mod download
GOARCH=amd64 GOOS=linux go build -ldflags "-s -w -X main.version=${TAG}" -o artifacts/linux/ktctl ./cmd/ktctl
GOARCH=amd64 GOOS=darwin go build -ldflags "-s -w -X main.version=${TAG}" -o artifacts/macos/ktctl ./cmd/ktctl
GOARCH=amd64 GOOS=windows go build -ldflags "-s -w -X main.version=${TAG}" -o artifacts/windows/ktctl.exe ./cmd/ktctl
Expand Down
41 changes: 23 additions & 18 deletions docs/en-us/reference/customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,41 @@ This completes the built-in permissions and configuration customization. Next, y
Required tools: [go](https://go.dev/dl), [upx](https://github.com/upx/upx/releases/latest), [make](https://cmake.org/install/) (optional)
Under MacOS and Linux systems, it is recommended to use the Make toolkit, with following `make` command:
Under MacOS and Linux systems, you can simply use the Make toolkit, with following `make` command:
```bash
go mod download
TAG=0.3.5 make ktctl
make upx
````

After execution, binary files for MacOS/Linux/Windows systems will be generated in the `artifacts` directory at one time.

The Make toolkit in the Windows environment is relatively cumbersome to use. It is recommended to use the `go` and `upx` commands to complete packaging directly. For specific commands, please refer to the `ktctl` and `upx` tasks in [Makefile](https://github.com/alibaba/kt-connect/blob/master/Makefile).
The Make toolkit in the Windows environment is relatively cumbersome to use, it is recommended to use below raw commands to create the executable binary.

For more precise compilation control, you can also directly use the `go` and `upx` commands to complete the packaging. For more details, please refer to the `ktctl` and `upx` tasks in [Makefile](https://github.com/alibaba/kt-connect/blob/master/Makefile).

It contains three configurable variables:

- `TAG`: It is recommended to be consistent with the latest release version of kt-connect, unless you have customized both `global.image` and `mesh.router-image` configurations to the internal image address of the enterprise, otherwise using an unofficial version of the `TAG` value will cause `ktctl` fail to pull required image.
- `GOARCH`: The target processor type for compilation, common values are: `386` (32-bit CPU) / `amd64` (32-bit CPU) / `arm64` (64-bit ARM CPU), etc.
- `GOOS`: The target operating system for compilation, common values are: `darwin` (MacOS) / `linux` (Linux) / `windows` (Windows), etc.

For example, compile the binary execution file of Windows 64bit environment:

<!-- tabs:start -->

####**cmd**
#### ** MacOS Shell / Linux Shell / Windows MINGW **

```bash
export TAG=0.3.5
export GOARCH=amd64
export GOOS=windows
go mod download
go build -ldflags "-s -w -X main.version=${TAG}" -o artifacts/windows/ktctl.exe ./cmd/ktctl
upx -9 artifacts/windows/ktctl.exe
````
#### ** Windows CMD **
```bash
set TAG=0.3.5
Expand All @@ -71,7 +89,7 @@ go build -ldflags "-s -w -X main.version=%TAG%" -o artifacts\windows\ktctl.exe .
upx -9 artifacts\windows\ktctl.exe
````

#### **PowerShell**
#### ** Windows PowerShell **

```bash
$env:TAG="0.3.5"
Expand All @@ -82,21 +100,8 @@ go build -ldflags "-s -w -X main.version=$env:TAG" -o artifacts\windows\ktctl.ex
upx -9 artifacts\windows\ktctl.exe
````
####**MINGW**

```bash
export TAG=0.3.5
export GOARCH=amd64
export GOOS=windows
go mod download
go build -ldflags "-s -w -X main.version=${TAG}" -o artifacts/windows/ktctl.exe ./cmd/ktctl
upx -9 artifacts/windows/ktctl.exe
````
<!-- tabs:end -->
Note: The value of the `TAG` variable in the above command is recommended to be consistent with the latest release version of kt-connect, unless you have customized both `global.image` and `mesh.router-image` configurations to the internal image address of the enterprise, otherwise using an unofficial version of the `TAG` value will cause `ktctl` fail to pull required image.
After the generated binary file has been tested and verified, it can be directly distributed to the developer for use : )
> For Windows environment, the `ktctl` tool is relying on the `wintun.dll` library file to run normally. When packaged and distributed, it is recommended to extract the corresponding version of the `wintun.dll` file from the official release package of `kt-connect` and put it together with `ktctl` binary into a zip, so that developers can use the tool directly after unpacking.
43 changes: 24 additions & 19 deletions docs/zh-cn/reference/customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,41 @@ hack

所需工具:[go](https://go.dev/dl)[upx](https://github.com/upx/upx/releases/latest)[make](https://cmake.org/install/)(可选)

在MacOS和Linux系统下,推荐使用Make工具打包,执行以下`make`命令:
在MacOS和Linux系统下,可以使用Make工具打包,执行以下`make`命令:

```bash
go mod download
TAG=0.3.5 make ktctl
make upx
```

执行后将在`artifacts`目录下一次性生成MacOS/Linux/Windows系统所用的二进制文件。

Windows环境下的Make工具使用起来相对繁琐,建议直接使用`go``upx`命令来完成打包,具体命令可以参考[Makefile](https://github.com/alibaba/kt-connect/blob/master/Makefile)中的`ktctl``upx`任务。
Windows环境下的Make工具使用起来相对繁琐,建议采用下述原始命令方式打包。

如需进行更精细的编译控制,也可以直接使用`go``upx`命令来完成打包,具体命令可以参考[Makefile](https://github.com/alibaba/kt-connect/blob/master/Makefile)中的`ktctl``upx`任务。

其中包含三个配置变量:

- `TAG`:建议与kt-connect的最新发行版本保持一致,除非您已经将`global.image``mesh.router-image`配置都定制为了企业内部镜像地址,否则使用非正式版本的`TAG`值会导致运行时无法拉取所需的镜像。
- `GOARCH`:编译的目标处理器类型,常用值为:`386`(32位CPU) / `amd64`(32位CPU) / `arm64`(64位ARM CPU)等
- `GOOS`:编译包的目标系统,常用值为:`darwin`(MacOS) / `linux`(Linux) / `windows`(Windows)等

以打Windows环境的二进制包为例
以打64位Windows环境的二进制包为例

<!-- tabs:start -->

#### ** CMD **
#### ** MacOS Shell / Linux Shell / Windows MINGW **

```bash
export TAG=0.3.5
export GOARCH=amd64
export GOOS=windows
go mod download
go build -ldflags "-s -w -X main.version=${TAG}" -o artifacts/windows/ktctl.exe ./cmd/ktctl
upx -9 artifacts/windows/ktctl.exe
```

#### ** Windows CMD **

```bash
set TAG=0.3.5
Expand All @@ -71,7 +89,7 @@ go build -ldflags "-s -w -X main.version=%TAG%" -o artifacts\windows\ktctl.exe .
upx -9 artifacts\windows\ktctl.exe
```

#### ** PowerShell **
#### ** Windows PowerShell **

```bash
$env:TAG="0.3.5"
Expand All @@ -82,21 +100,8 @@ go build -ldflags "-s -w -X main.version=$env:TAG" -o artifacts\windows\ktctl.ex
upx -9 artifacts\windows\ktctl.exe
```

#### ** MINGW **

```bash
export TAG=0.3.5
export GOARCH=amd64
export GOOS=windows
go mod download
go build -ldflags "-s -w -X main.version=${TAG}" -o artifacts/windows/ktctl.exe ./cmd/ktctl
upx -9 artifacts/windows/ktctl.exe
```

<!-- tabs:end -->

注意:上述命令中的`TAG`变量值建议与kt-connect的最新发行版本保持一致,除非您已经将`global.image``mesh.router-image`配置都定制为了企业内部镜像地址,否则使用非正式版本的`TAG`值会导致运行时无法拉取所需的镜像。

生成二进制文件在经过测试验证无误后,就可以分发给开发同学使用啦 : )

> 对于Windows环境,`ktctl`工具需要依赖`wintun.dll`库文件才能正常运行,在打包分发时,建议从`kt-connect`的正式版发行包中提取匹配版本的`wintun.dll`文件并一起成zip打包,便于开发者解包后可以直接使用`ktctl`工具。

0 comments on commit e2c1fdf

Please sign in to comment.