首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在github操作中构建的Dockerfile中使用GitHub令牌,并尝试克隆私有存储库?

如何在github操作中构建的Dockerfile中使用GitHub令牌,并尝试克隆私有存储库?
EN

Stack Overflow用户
提问于 2021-07-07 01:54:55
回答 1查看 940关注 0票数 2

这是我的GitHub操作步骤。PRIVATE_REQUIREMENT_OWNER_TOKEN密码已创建,并且包含具有完整repo作用域的GitHub令牌:

代码语言:javascript
复制
  - name: Build docker image
    id: docker_build
    uses: docker/build-push-action@v2
    with:
      push: false
      context: .
      tags: 'username/image:latest'
      secrets: |
        "github_token=${{ secrets.PRIVATE_REQUIREMENT_OWNER_TOKEN }}"

以下是requirements.txt中的一行代码,其中包含一个指向私有存储库的链接,并在上面的步骤中尝试在从Dockerfile构建docker镜像时进行安装:

代码语言:javascript
复制
git+ssh://git@github.com/username/private-repository

该行已添加到Dockerfile

代码语言:javascript
复制
RUN --mount=type=secret,id=github_token pip install https://$(cat /run/secrets/github_token)@github.com/username/private-repository.git

这会在GitHub操作中抛出以下错误:

代码语言:javascript
复制
#11 [ 6/12] RUN --mount=type=secret,id=PRIVATE_REQUIREMENT_OWNER_TOKEN_SECRET pip install https://$(cat /run/secrets/PRIVATE_REQUIREMENT_OWNER_TOKEN_SECRET)@github.com/username/private-repository.git
#11 sha256:b3d88dd9813db3257b15f53f1eb5a4c593c69ff98ec03cc4d70d564df1a1f7f6
#11 0.697 Collecting https://****@github.com/vassilyvv/django-sinbad.git
#11 0.790   ERROR: HTTP error 404 while getting https://****@github.com/username/private-repository
.git
#11 0.791 ERROR: Could not install requirement https://****@github.com/username/private-repository
.git because of HTTP error 404 Client Error: Not Found for url: https://github.com/username/private-repository
 for URL https://****@github.com/username/private-repository.git

但是,当我尝试使用相同的令牌在本地机器上克隆存储库时,它运行得很好:

代码语言:javascript
复制
git clone https://<token>@github.com/username/private-repository.git

我完全不知道如何使用这个github_token来成功克隆上面提到的私有存储库。

我的目标是克隆私有GitHub存储库,同时在GitHub Actions中从docker文件构建docker镜像。我几乎可以肯定我已经执行了一些错误的步骤。请帮帮我!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-10 02:41:46

我认为这是提供给pip的git URL的问题。如果您需要从私有git存储库安装python包,您可以使用以下格式。

pip install git+https://<PERSONAL_ACCESS_TOKEN>@github.com/username/private-repo.git

因此,在您的情况下,它将是:

代码语言:javascript
复制
pip install git+https://$(cat /run/secrets/github_token)@github.com/username/private-repository.git

请参阅:https://pip.pypa.io/en/stable/cli/pip_install/#git

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68275321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档