尝试使用 git 子模块在 Docker Hub 上自动构建时出现身份验证问题

Authentication issues when trying to auto-build on Docker Hub using git submodule

我正在尝试 Docker Hub 的自动构建功能。 我的情况是:

我按照 Build repositories with linked private submodules 的说明进行操作,这似乎正是我的用例,但无法正常工作。

我有 link 我的 Docker Hub 存储库到我的 BitBucket 一个用于我的后端自动构建对特定分支的新提交。

Docker文件:

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

[...]

我使用 the method prescribed by Atlassian 从我的 Windows 计算机创建了一对私钥和 public 密钥,并将 public 密钥添加到我依赖项的 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 Hub 中定义的 build environment variablehook 必须是创建以覆盖 build 命令 (related doc section)。

所以解决方案是创建一个hooks目录和文件:

hooks/build

#!/bin/bash

docker build \
    --build-arg SSH_PRIVATE=$SSH_PRIVATE\
    -f $DOCKERFILE_PATH \
    -t $IMAGE_NAME .