Dockerfile:

################################################################################
##                              BUILD STAGE                                   ##
################################################################################
FROM golang:1.18beta2 as builder

ARG GIT_USR
ARG GIT_PWD

ENV GOPROXY=https://goproxy.cn,direct
ENV GOPRIVATE=git.my.com
ENV GOOS=linux
ENV GOARCH=amd64
ENV GIT_TERMINAL_PROMPT=1

WORKDIR /build
COPY . ./

RUN go env -w GOPRIVATE=git.sre.ink \
    && echo "machine ${GOPRIVATE}" > ~/.netrc \
    && echo "login ${GIT_USR}" >> ~/.netrc \
    && echo "password ${GIT_PWD}" >> ~/.netrc \
    && GO111MODULE=on CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOPROXY=${GOPROXY} go mod tidy \
    && GO111MODULE=on CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOPROXY=${GOPROXY} go build -v -a -o app.bin main.go routes.go

build:

GIT_USER=admin
GIT_PASSWORD=123456
docker build -t ttt.t/v1 --build-arg GIT_USR=$GIT_USER --build-arg GIT_PWD=$GIT_PASSWORD -f ./Dockerfile .

发表回复

您的电子邮箱地址不会被公开。

Captcha Code