-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 减小部署文件大小 | ||
|
||
## 如何减小 go-zero 编译后二进制文件的大小? | ||
|
||
如果未使用 `Kubernetes` 的服务发现,可以在编译的时候使用 `-tags no_k8s` 来排除 `k8s` 相关的依赖包。 | ||
|
||
具体做法如下: | ||
|
||
`GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -tags no_k8s demo.go` | ||
|
||
可以减少超过 20MB 的体积,如下图所示: | ||
|
||
![binary-size](/img/content/reduce-binary-size.jpg) | ||
|
||
> go-zero 版本:>= v1.7.1 |
17 changes: 17 additions & 0 deletions
17
i18n/en/docusaurus-plugin-content-docs/current/faq/deploy/reduce-binary-size.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Reducing Binary File Size | ||
|
||
## How to reduce the size of go-zero compiled binary files? | ||
|
||
If you are not using `Kubernetes` for service discovery, you can exclude the `k8s` related dependency packages during compilation by using the `-tags no_k8s` flag. | ||
|
||
The specific method is as follows: | ||
|
||
```bash | ||
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -tags no_k8s demo.go | ||
``` | ||
|
||
This can reduce the size by more than 20MB, as shown in the image below: | ||
|
||
![binary-size](/img/content/reduce-binary-size.jpg) | ||
|
||
> go-zero version: >= v1.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.