Skip to content

Commit

Permalink
feat: add reduce binary size doc
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Aug 20, 2024
1 parent 26965e2 commit b27deea
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/faq/deploy/binary-size.md
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
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
8 changes: 8 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,14 @@ module.exports = {
'faq/log/fileconsole',
],
},
{
type: 'category',
label: '部署',
collapsed: false,
items: [
'faq/deploy/binary-size',
],
},
],
contributing: [
'contributing',
Expand Down
Binary file added static/img/content/reduce-binary-size.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b27deea

Please sign in to comment.