我有一个Go项目,它是GitHub上的一个私人仓库。我想从源代码构建这个项目。我尝试运行go get -d -v ./... && go install -v ./...
来安装所有依赖项,但这是我得到的fatal: could not read Username for 'https://github.com': terminal prompts disabled
的错误,这意味着它试图从GitHub克隆我的项目,而不是从源代码构建它。
在安装所有依赖项的情况下,我可以真正地从源代码正确地构建Go项目中使用一些帮助。我正在使用Docker,这就是我的Dockerfile
的样子:
#build stage
FROM golang:alpine AS builder
WORKDIR /go/src/app
COPY . .
RUN apk add --no-cache git
RUN go get -d -v ./...
RUN go install -v ./...
#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /go/bin/app /app
ENTRYPOINT ./app
EXPOSE 8080
只有我的项目代码是私有的,我拥有的所有其他依赖项都是公开可用的,例如mux
。如果Go从GitHub提取这些文件,我没有问题,但是我想从源代码编译项目代码。