如何在 GitHub 操作中内置的 Dockerfile 中使用 github 令牌并尝试克隆私有存储库?
How to use github token in Dockerfile that is built in GitHub Actions and trying to clone private repository?
这是我的 GitHub 行动步骤。 PRIVATE_REQUIREMENT_OWNER_TOKEN
秘密已创建并包含 GitHub 具有完整 repo
范围的令牌:
- 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 中的一行,其中包含 link 到私有存储库,并在上述步骤中从 Dockerfile 构建 docker 图像时尝试安装:
git+ssh://git@github.com/username/private-repository
该行已添加到 Dockerfile
RUN --mount=type=secret,id=github_token pip install https://$(cat /run/secrets/github_token)@github.com/username/private-repository.git
在 GitHub 操作中引发以下错误:
#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
但是当我尝试使用相同的令牌在本地计算机上克隆存储库时,一切顺利:
git clone https://<token>@github.com/username/private-repository.git
我完全不知道如何使用这个github_token
成功克隆上面提到的私有仓库
我的目标是在 GitHub 操作中从 Dockerfile 构建 docker 图像时克隆私有 GitHub 存储库。而且我几乎可以肯定我已经执行了一些错误的步骤。请帮忙!
我认为这是提供给 pip
的 git URL 的问题。如果您需要从私有 git 存储库安装 python 软件包,您可以使用以下格式。
pip install git+https://<PERSONAL_ACCESS_TOKEN>@github.com/username/private-repo.git
所以在你的情况下,它将是:
pip install git+https://$(cat /run/secrets/github_token)@github.com/username/private-repository.git
这是我的 GitHub 行动步骤。 PRIVATE_REQUIREMENT_OWNER_TOKEN
秘密已创建并包含 GitHub 具有完整 repo
范围的令牌:
- 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 中的一行,其中包含 link 到私有存储库,并在上述步骤中从 Dockerfile 构建 docker 图像时尝试安装:
git+ssh://git@github.com/username/private-repository
该行已添加到 Dockerfile
RUN --mount=type=secret,id=github_token pip install https://$(cat /run/secrets/github_token)@github.com/username/private-repository.git
在 GitHub 操作中引发以下错误:
#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
但是当我尝试使用相同的令牌在本地计算机上克隆存储库时,一切顺利:
git clone https://<token>@github.com/username/private-repository.git
我完全不知道如何使用这个github_token
成功克隆上面提到的私有仓库
我的目标是在 GitHub 操作中从 Dockerfile 构建 docker 图像时克隆私有 GitHub 存储库。而且我几乎可以肯定我已经执行了一些错误的步骤。请帮忙!
我认为这是提供给 pip
的 git URL 的问题。如果您需要从私有 git 存储库安装 python 软件包,您可以使用以下格式。
pip install git+https://<PERSONAL_ACCESS_TOKEN>@github.com/username/private-repo.git
所以在你的情况下,它将是:
pip install git+https://$(cat /run/secrets/github_token)@github.com/username/private-repository.git