【问题标题】:Authentication issues when trying to auto-build on Docker Hub using git submodule尝试使用 git 子模块在 Docker Hub 上自动构建时的身份验证问题
【发布时间】:2021-10-26 00:41:31
【问题描述】:

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

  • 我的后端 Web 应用程序的私有 BitBucket 存储库
  • 另一个私有 BitBucket 存储库,用于我的 Web 应用程序的依赖项之一

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

我已将我的 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

[...]

我使用 the method prescribed by 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 在其授权密钥中自动添加的密钥(我还添加了我生成的密钥,以防万一)。


你能看出哪里出了问题吗?

谢谢。

【问题讨论】:

    标签: git dockerhub


    【解决方案1】:

    这是我错过的:为了使用在Docker Hub中定义的build environment variable,必须创建一个hook来覆盖build命令(related doc section) .

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

    钩子/构建

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 2012-03-13
      • 1970-01-01
      • 2015-09-03
      相关资源
      最近更新 更多