jenkins 在构建Docker映像时使用私有GitHub存储库中的pip安装python包?

kfgdxczn  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(199)

################################################################################ 

# Ubuntu 22.10

FROM ubuntu:22.10

################################################################################ 

# Install packages

RUN apt-get update && apt-get install --yes --no-install-recommends \
  build-essential \
  gfortran \
  meson \
  pkg-config \
  sox \
  git \
  cmake \
  openssh-client \
  python3 \
  python3-pip \
  python3-numpy 

################################################################################ 

# Create a Jenkins user with proper host group id and user id

ARG UNAME=jenkins

# Get group and user ids from outside "docker build" command line

ARG GID=
ARG UID=
RUN groupadd --gid $GID $UNAME && \
    useradd --gid $GID --uid $UID --home-dir /home/$UNAME --create-home $UNAME

################################################################################ 

# Add github.com to the list of known ssh hosts for user Jenkins

USER $UNAME
RUN mkdir /home/$UNAME/.ssh/ && \
    touch /home/$UNAME/.ssh/known_hosts && \
    ssh-keyscan github.com >> /home/$UNAME/.ssh/known_hosts

################################################################################ 

# Install myproj from myrepos:

RUN pip3 install --upgrade --user git+ssh://git@github.com/myrepos/myproj@master

################################################################################ 

我已经创建了Jenkins自动化服务器使用的上述Dockerfile。Dockerfile包含了一些SSH密钥,以使jenkins用户能够访问我的Git仓库。这使jenkins能够运行meson构建系统命令(meson需要访问GitHub)。所有工作正常。
但现在我需要从我的GitHub repo安装一个包,我通常这样安装:
pip3 install --upgrade --user git+ssh://git@github.com/myrepos/myproj@master
然而,当运行docker时,我在最后一个RUN行上得到错误:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

如何从Dockerfile访问存储库?

carvr3hs

carvr3hs1#

你的github存储库被添加到已知主机,但是你的存储库密钥呢?你通过这个Dockerfile构建的映像怎么知道它是什么?
假设您可以将密钥COPY到映像中,这样它就可以访问并从私有存储库中提取,但这是不安全的。如果您这样做,您将额外添加更多的私有凭据(来自您的github存储库)到映像中。
我会在本地克隆repo,并将所需的文件COPY在其中,或者作为卷安装。

相关问题