git - 尝试使用 git 子模块在 Docker Hub 上自动构建时的身份验证问题
问题描述
我正在尝试Docker Hub的自动构建功能。我的情况是:
- 我的后端 Web 应用程序的私有 BitBucket 存储库
- 另一个私有 BitBucket 存储库,用于我的 Web 应用程序的依赖项之一
我按照使用链接的私有子模块构建存储库的说明进行操作,这似乎正是我的用例,但无法使其正常工作。
我已将我的 Docker Hub 存储库链接到我的 BitBucket 存储库,以便我的后端自动构建对特定分支的新提交。
Dockerfile:
FROM python:3.9.7-buster AS builder
RUN git clone \
--branch master \
--single-branch \
git@bitbucket.org:myorganisationname/dependency.git
RUN pip wheel --no-cache-dir --wheel-dir /usr/src/app/wheels --use-feature=in-tree-build ./dependency
[...]
我使用Atlassian 规定的方法从我的 Windows 计算机创建了一对私钥和公钥,并将公钥添加到我的依赖项的 repo 授权密钥中。
1.现在,如果我不添加 SSH_PRIVATE环境变量
我在构建过程中收到以下错误:
Cloning into '.'...
Warning: Permanently added the RSA host key for IP address '18.205.93.0' to the list of known hosts.
Switched to a new branch 'deploy'
KernelVersion: 4.4.0-1060-aws
[...]
#15 [builder 6/7] RUN git clone --branch master --single-branch
git@bitbucket.org:myorganisationname/dependency.git
#15 sha256:94b95bf83f7896175a6f81ce71694d3e98b14540dede62445c02e779def9c581
#15 0.646 Cloning into 'dependency'...
#15 0.751 Host key verification failed.
#15 0.752 fatal: Could not read from remote repository.
#15 0.752
#15 0.752 Please make sure you have the correct access rights
#15 0.752 and the repository exists.
#15 ERROR: executor failed running [/bin/sh -c git clone --branch master --single-branch
git@bitbucket.org:myorganisationname/dependency.git]: exit code: 128
------
> [builder 6/7] RUN git clone --branch master --single-branch
git@bitbucket.org:myorganisationname/dependency.git
------
error: failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c git clone --branch
master --single-branch git@bitbucket.org:myorganisationname/dependency.git]: exit code: 128
Build failed using Buildkit
这是预期的。
2.添加用于构建的 SSH_PRIVATE环境变量时
在我复制我的私钥的地方,我有这个错误:
Cloning into '.'...
Warning: Permanently added the RSA host key for IP address '18.205.93.2' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
please ensure the correct public key is added to the list of trusted keys for this repository (128)
Docker Hub无法再访问我的 BitBucket 存储库,这对我来说没有多大意义,为构建添加环境变量应该不会影响这一点。
我已经检查了后端的 BitBucket 存储库是否包含Docker Hub在其授权密钥中自动添加的密钥(我还添加了我生成的密钥,以防万一)。
你能看出哪里出了问题吗?
谢谢你。
解决方案
这是我错过的:为了使用Docker Hubbuild environment variable
中定义的内容,必须创建一个来覆盖命令(相关文档部分)。hook
build
所以解决方案是创建一个hooks
目录和文件:
挂钩/构建
#!/bin/bash
docker build \
--build-arg SSH_PRIVATE=$SSH_PRIVATE\
-f $DOCKERFILE_PATH \
-t $IMAGE_NAME .
推荐阅读
- javascript - 将EventListener 添加到innerHTML
- javascript - 我在我的 html 页面上得到了这个 [object HTMLSpanElement]
- entity-framework - EF(在 WPF 中)第一次使用时不创建数据库(CreateDatabaseIfNotExists 不起作用)
- asp.net-core - Identity Server 4 没有为 `.well-known/openid-configuration` 设置`Access-Control-Allow-Origin`
- r - 配置 Travis CI 运行与 check --as-cran 完全相同的检查?
- reactjs - 在这种情况下,如何使用 useEffect 避免无限循环?(反应)
- erlang - 从二进制安装 Erlang 和 epmd 具有循环依赖关系
- android - 如何获取片段内在firebase中注册的用户数?
- kotlin - Kotlin 使用流函数或其他方法为变量赋值的捷径
- amazon-web-services - 为什么我在 CloudWatch 和 lambda 函数的控制台中看不到我的日志?