Skip to content

Commit

Permalink
Feat/docs (#163)
Browse files Browse the repository at this point in the history
* feat(docs): add grpc faq

* feat(docs): add build-binary for deploy
  • Loading branch information
jaronnie authored Dec 27, 2024
1 parent 2770577 commit 916f6c0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions docs/src/guide/deploy/build-binary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: 编译二进制文件
icon: fa6-solid:square-binary
star: true
order: 1
category: 开发
tag:
- Guide
---

## 正常编译

```shell
GOOS=linux GOARCH=amd64 go build
```

## 优化二进制体积

```shell
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w"
```

## 继续优化

> 如果未使用 Kubernetes 的服务发现,可以在编译的时候使用 -tags no_k8s 来排除 k8s 相关的依赖包。
```shell
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -tags no_k8s
```

## 压缩二进制

[下载 upx](https://github.com/upx/upx/releases)

```shell
upx your_binary
```

实测从 go build 90MB 到最终使用 upx 压缩后, 二进制大小为 12MB.

0 comments on commit 916f6c0

Please sign in to comment.