我正在尝试在 docker 文件上构建我的 go 应用程序。在我的go.mod中,有一个需要身份验证/ ssh的私有包。这个问题类似于在Docker中使用私有模块构建Go应用程序,但在我的情况下,我必须从中提取包而不是从中提取包。这是我的 dockerfile:gitlabgithub
# builder image
FROM golang:1.14.11-alpine AS builder
# specific directory for build process
WORKDIR /usr/src/build
# copying the source code
# to the current working directory
COPY . .
RUN apk add --no-cache openssh-client
RUN apk add --no-cache git
# create ssh directory
RUN mkdir ~/.ssh
RUN touch ~/.ssh/known_hosts
RUN ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts
# allow private repo pull
RUN git config --global url."https://my-personal-access-token:token@gitlab.com/".insteadOf "https://gitlab.com/"
ADD . /go/src/gitlab.com/my-repo/backends/backend-structs
CMD cd /go/src/gitlab.com/my-repo/backends/backend-structs; go get /go/src/gitlab.com/my-repo/backends/backend-structs && go build -o /go/bin/backend-structs
# executing build process
RUN GOOS=linux go build -ldflags="-s -w" -o app
# runtime image
FROM golang:1.14.11-alpine AS runtime
# create and use non-root user
# to increase container security
# ref https://pythonspeed.com/articles/root-capabilities-docker-security/
RUN adduser myuser --disabled-password
USER myuser
WORKDIR /home/myuser
# copy the executable binary file from builder directory
# to the current working directory
COPY --from=builder /usr/src/build/app .
# exposing port
EXPOSE 8080
# run the application
CMD ["./app"]
我试图按照本教程 https://divan.dev/posts/go_get_private/,通过更改为仍然失败。github.comgitlab.com
以下是错误详细信息:
#17 5.830 remote: HTTP Basic: Access denied
#17 5.830 fatal: Authentication failed for 'https://gitlab.com/my-repo/backends.git/'
------
executor failed running [/bin/sh -c GOOS=linux go build -ldflags="-s -w" -o app]: exit code: 1
这里有人知道如何用golang私有包创建dockerfile(repo托管在 gitlab.com 中)?
慕婉清6462132
慕妹3242003
相关分类