python - 在 Dockerfile 中的 Docker 镜像中复制 gitlab 项目
问题描述
我正在尝试将 gitlab 项目复制到我的 docker 映像中,以便可以在我的 python 脚本中使用它。我的 DockerFile 一直运行到这一行:
RUN \
### ssh configuration, see https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor
# run ssh-agent inside build environment
eval $(ssh-agent -s); \
# add ssh-key from GitLab variable to ssh agent store incl. fixing line endings
echo "${SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add -; \
# create the SSH directory and give it the right permissions
mkdir -p ~/.ssh; \
# Allow access to gitlab.your.lan
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config; \
chmod 700 ~/.ssh; \
\
git clone ${BACKEND_PATH}
错误代码:
+ echo
+ ssh-add -+
tr -d \r
Could not open a connection to your authentication agent.
+ mkdir -p /root/.ssh
+ echo -e Host *\n\tStrictHostKeyChecking no\n\n
+ chmod 700 /root/.ssh
+ git clone /backend
fatal: repository '/backend' does not exist
+ docker build . --force-rm --build-arg SSH_PRIVATE_KEY=config/backend_key.pem
/bin/sh: 1: docker: not found
ERROR: Service 'app' failed to build: The command '/bin/sh -c set -x eval $(ssh-agent -s); echo "${SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add -; mkdir -p ~/.ssh; echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config; chmod 700 ~/.ssh; git clone ${BACKEND_PATH}; docker build . --force-rm --build-arg SSH_PRIVATE_KEY=${SSH_PRIVATE_KEY_BACKEND};' returned a non-zero code: 127
完整的 Docker 文件:
FROM python:3.7-stretch
ARG CONFIG_ENV="development"
ARG BACKEND_PATH="git@gitlab.company.com:IT/mycompany-next-gen/backend.git"
ARG SSH_PRIVATE_KEY
ARG SSH_PRIVATE_KEY_BACKEND=config/backend_key.pem
RUN echo $SSH_PRIVATE_KEY
RUN if [ -z $CONFIG_ENV ]; then >&2 echo "Please pass the 'CONFIG_ENV' as a build argument"; exit 1; fi
# Copy the store handler code into the image
ARG AGGREGATION_PATH=/store-handler-project
WORKDIR ${AGGREGATION_PATH}
COPY store-handler store-handler
COPY store-handler .
# Copy the backend code into the image
ARG BACKEND_PATH=/backend
WORKDIR backend
RUN set -x \
### ssh configuration, see https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor
# run ssh-agent inside build environment
eval $(ssh-agent -s); \
echo "${SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add -; \
# create the SSH directory and give it the right permissions
mkdir -p ~/.ssh; \
# Allow access to gitlab.your.lan
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config; \
chmod 700 ~/.ssh; \
git clone ${BACKEND_PATH}; \
docker build . --force-rm --build-arg SSH_PRIVATE_KEY=${SSH_PRIVATE_KEY_BACKEND};
# Copy the config file and mongo certificate to the image
WORKDIR /etc/store-handler/
COPY config/${CONFIG_ENV}.pem mongo.pem
COPY requirements.txt .
COPY config/${CONFIG_ENV}.ini config.ini
COPY config/logging.conf .
# Install all of the python requirements in the image
RUN pip install -r requirements.txt
# Install systemd
RUN apt-get update; apt-get -y install systemd systemd-sysv
# Install docker-systemctl-replacement
# docker systemctl replacement - allows to deploy to systemd-controlled containers without starting an actual systemd daemon
RUN wget https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py -O /usr/local/bin/systemctl
RUN chmod +x /usr/local/bin/systemctl
# Set Python path correctly
RUN export PYTHONPATH=/store-handler-project
# Clean up the /tmp/
WORKDIR /root
RUN rm -rf /tmp/store-handler/
解决方案
推荐阅读
- sqlite - 删除 SQLite 中的重复组
- javascript - 为远程文件(视频、照片等)创建 blob url 下载链接
- rust - 为什么“rev”在 Cargo 中不起作用?
- django - Django 如何仅将 example.com 重定向到 https 并将 *.example.com 重定向到 http?
- java - 使用同步或不低于为所有线程生成相同哈希码的代码。如何?
- llvm - 如何链接 LLVM 库
- javascript - 在前端的 rails/javascript 中显示图像
- python - 使用 Pyperclip 复制和粘贴二维数组
- android - 使用 Android O 检测后台禁用的 wifi
- php - 如何在 Consul 中将 PHP 应用程序注册为服务