This is an automated email from the ASF dual-hosted git repository. liuhongyu pushed a commit to branch feat/docker in repository https://gitbox.apache.org/repos/asf/hertzbeat-collector-go.git
commit 1692a69215092ac696d4698363bd156243ab899f Author: liuhy <[email protected]> AuthorDate: Sat Sep 6 22:21:14 2025 +0800 chore: update Dockerfile for multi-stage build and clean up README --- Dockerfile | 37 ++++++++++++++++++++++++++++++++++++- README.md | 2 -- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ef9b9ed..b0bd65c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,4 +15,39 @@ # specific language governing permissions and limitations # under the License. -From golang:1.24-alpine + +# syntax=docker/dockerfile:1 + +# Build stage +FROM golang:1.24-alpine AS builder + +WORKDIR /app + +# 安装 git 以支持 go mod 下载私有依赖(如有需要) +RUN apk add --no-cache git + +# 复制 go.mod 和 go.sum 并下载依赖 +COPY go.mod go.sum ./ +RUN go mod download + +# 复制源代码 +COPY . . + +# 构建二进制文件 +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o collector ./cmd/main.go + +# Production stage +FROM alpine:3.19 + +WORKDIR /app + +# 拷贝构建产物 +COPY --from=builder /app/collector /app/collector + +# 如有配置文件等需要一并拷贝 +# COPY --from=builder /app/etc /app/etc + +# 暴露端口(如有需要) +# EXPOSE 1158 + +ENTRYPOINT ["./collector"] diff --git a/README.md b/README.md index 9422898..1b46e6a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -go mod tidy - # HertzBeat Collector Go [](LICENSE) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
