[英]Use Github secrets in Dockerfile does not work with Github Actions
[英]How to use github token in Dockerfile that is built in GitHub Actions and trying to clone private repository?
這是我的 GitHub 操作步驟。 PRIVATE_REQUIREMENT_OWNER_TOKEN
秘密已創建並包含具有完整repo
范圍的 GitHub 令牌:
- 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 映像時進行安裝:
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 Actions 中引發以下錯誤:
#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 Actions 中從 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.