Ubuntu下常用的Golang打包工具与方案
一 核心工具清单
二 选型建议
三 快速上手示例
BIN=myapp
GOOS?=linux
GOARCH?=amd64
build:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o bin/$(BIN) .
clean:
rm -rf bin/
FROM golang:1.21 AS builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o myapp .
FROM scratch
COPY --from=builder /app/myapp /myapp
ENTRYPOINT ["/myapp"]
四 常见注意事项