使用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环境变量h1> 在构建过程中获得以下错误:
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 repo包含由Docker Hub在其授权密钥中自动添加的密钥(我还添加了我生成的密钥,以防万一)。


你能发现哪里出了问题吗?

谢谢。

这是我错过的:为了使用Docker Hub中定义的build environment variable,必须创建一个hook来覆盖build命令(相关文档部分)。

因此,解决方案是创建一个hooks目录和文件:

钩/构建

#!/bin/bash
docker build 
--build-arg SSH_PRIVATE=$SSH_PRIVATE
-f $DOCKERFILE_PATH 
-t $IMAGE_NAME .

最新更新