美文网首页
Golang Dockerfile 多阶编译,并拉取私有库

Golang Dockerfile 多阶编译,并拉取私有库

作者: DukeAnn | 来源:发表于2020-03-10 15:14 被阅读0次

    Dockerfile

    FROM golang:latest as builder
    MAINTAINER DukeAnn <duke@ann.live>
    ARG VERSION=1.0.0
    WORKDIR $GOPATH/src/project
    # 当前目录拷贝进 Docker
    ADD . $GOPATH/src/project
    # 拷贝密钥,设置私有库拉取
    ADD ./.ssh/ /root/.ssh
    RUN git config --global http.extraheader "PRIVATE-TOKEN: TOKEN" \
        && git config --global url."git@gitlab.com:".insteadOf "http://git.gitlab.com/" \
        && git config --global user.name "dukeann" \
        && git config --global user.email  "duke@ann.live" \
        && chmod 600 /root/.ssh/id_rsa \
        && chmod 644 /root/.ssh/id_rsa.pub \
        && chmod 644 /root/.ssh/known_hosts
    # 交叉编译
    RUN CGO_ENABLED=0 GOOS=linux go build  -a -installsuffix cgo -o project .
    # 运行镜像
    FROM alpine:latest as prod
    RUN apk --no-cache add ca-certificates
    WORKDIR /root/
    EXPOSE 80
    COPY --from=0 /go/src/project/release ./project
    ENTRYPOINT ["/bin/sh", "./project/project", "start"]
    #ENTRYPOINT ["/bin/sh"]
    

    关于 PRIVATE-TOKEN: TOKEN 获取:https://www.jianshu.com/p/5831edfa6c78

    多阶编译详解:https://yeasy.gitbooks.io/docker_practice/content/image/multistage-builds/

    相关文章

      网友评论

          本文标题:Golang Dockerfile 多阶编译,并拉取私有库

          本文链接:https://www.haomeiwen.com/subject/qdiwdhtx.html