From 80c3bf151f82e6d96578e66a9923cbdcd8fbd1d8 Mon Sep 17 00:00:00 2001 From: lab Date: Tue, 14 May 2024 13:36:40 +0800 Subject: [PATCH] fix: integrate docker file with go build --- Dockerfile | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5ea8244..858785f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,26 @@ -FROM alpine:latest as builder +FROM golang:1.22-alpine as builder + +ADD . ./src + +WORKDIR /go/src RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \ - && apk --no-cache add ca-certificates + && apk --no-cache add ca-certificates \ + && go env -w GOPROXY='https://goproxy.cn,direct' \ + && go mod tidy \ + && CGO_ENABLED=0 GOOS="linux" GOARCH="amd64" \ + go build \ + -ldflags="-s -w" \ + -tags timetzdata \ + -v \ + -o /app \ + ./cmd/cert-exporter FROM scratch as production ENV TZ="Asia/Shanghai" -COPY ./build/app / +COPY --from=builder /app / COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ CMD ["/app"] \ No newline at end of file