Golang 发布Docker 编译镜像,防止源码泄露

Dockerfile

# stage1 build source
FROM golang:latest AS builder
COPY ./ht-project /codes/ht-project
COPY ./termites /codes/termites
WORKDIR /codes/ht-project

## install packages
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod tidy

## build docker file
RUN cd ./services/run-spider && go build -ldflags="-s -w" -o app

# pack a new imgge
FROM alpine:latest
LABEL maintianer="[email protected]"

RUN apk --no-cache add ca-certificates
WORKDIR /server/
COPY --from=builder /codes/ht-project/services/run-spider/app ./

ENTRYPOINT ["./app"]

你可能感兴趣的:(笔记)