我正在致力于将通用模块分离到我们 github 组织的专用存储库中。使用 git repo 中的 pip installDockerfile
安装组织内部开发的共享模块
RUN pip3 install -r requirements.txt
其中 git repo 依赖项引用如下
git+https://github.com/org/repo.git@master
面临的问题是我无法做到pip3 install
当作为 github 操作运行时,针对组织私有存储库进行身份验证pip3 install
inside Dockerfile
。我希望避免为其中一位开发人员创建私有访问令牌 (PAT),因为希望与用户无关,并且不维护离开团队成员的令牌。尝试使用${{ secrets.GITHUB_TOKEN }}
但通过更深入的阅读,我们意识到该令牌可以访问启动 github 操作的存储库(link https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret)
令牌的权限仅限于包含您的工作流程的存储库
有没有办法制作pip3 install
在没有 PAT 的情况下在 github actions 中工作?
在多次迭代之一中出错:
Collecting git+https://****@github.com/org/repo.git@master (from -r requirements.txt (line 17))
Cloning https://****@github.com/org/repo.git (to revision master) to /tmp/pip-req-build-mnge3zvd
Running command git clone -q 'https://****@github.com/org/repo.git' /tmp/pip-req-build-mnge3zvd
fatal: could not read Password for 'https://${GITHUB_TOKEN}@github.com': No such device or address
WARNING: Discarding git+https://****@github.com/org/repo.git@master. Command errored out with exit status 128: git clone -q 'https://****@github.com/org/repo.git' /tmp/pip-req-build-mnge3zvd Check the logs for full command output.
ERROR: Command errored out with exit status 128: git clone -q 'https://****@github.com/org/repo.git' /tmp/pip-req-build-mnge3zvd Check the logs for full command output.
我建议你像这样使用 ssh:
在你的 dockerfile 中:
RUN --mount=type=ssh,id=default pip install -r requirements.txt
在您的requirements.txt中,更改为
git+ssh://[email protected] /cdn-cgi/l/email-protection/org/repo.git@master
在存储库设置/操作/秘密中准备与您的 github 帐户关联的 ssh 私钥,名称为SSH_KEY
(最好使用专用的 ssh 密钥)
在定义 yaml 的操作中,创建一个步骤
- name: Prepare Key
uses: webfactory/ssh-a[email protected] /cdn-cgi/l/email-protection
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
这将导出一个环境变量SSH_AUTH_SOCK
供以后使用
下一步操作,使用SSH_AUTH_SOCK
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
ssh: |
default=${{ env.SSH_AUTH_SOCK }}
参考:https://github.com/webfactory/ssh-agent#using-the-docker build-push-action-action https://github.com/webfactory/ssh-agent#using-the-dockerbuild-push-action-action
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)