gpt4 book ai didi

docker - 无人机 CI 在克隆步骤上失败

转载 作者:行者123 更新时间:2023-12-02 20:11:48 27 4
gpt4 key购买 nike

我在一台机器上运行 docker-compose 以下内容:

  • gitlab
  • 无人机(服务器)
  • 无人机(代理)

当我触发构建(或由 git push 触发)时,无人机在这个问题上不断失败:

git init
Initialized empty Git repository in /drone/src/.git/
git remote add origin http://my-git/amaziagur/location-service.git
git fetch --no-tags origin +refs/heads/master:
fatal: unable to access 'http://my-git/amaziagur/location-service.git/': Couldn't resolve host 'my-git'
exit status 128

这是 docker-compose.yml:

version: '2'
services:
#PROXY
gitlab:
image: 'gitlab/gitlab-ce:9.1.0-ce.0'
restart: always
hostname: 'my-git'
links:
- postgresql:postgresql
- redis:redis
environment:
GITLAB_OMNIBUS_CONFIG: |
postgresql['enable'] = false
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = "gitlab"
gitlab_rails['db_host'] = "postgresql"
gitlab_rails['db_port'] = "5432"
gitlab_rails['db_database'] = "gitlabhq_production"
gitlab_rails['db_adapter'] = 'postgresql'
gitlab_rails['db_encoding'] = 'utf8'
redis['enable'] = false
gitlab_rails['redis_host'] = 'redis'
gitlab_rails['redis_port'] = '6379'
external_url 'http://my-git'
gitlab_rails['gitlab_shell_ssh_port'] = 30022
ports:
# both ports must match the port from external_url above
- "80:80"
# the mapped port must match ssh_port specified above.
- "30022:22"
# the following are hints on what volumes to mount if you want to persist data
volumes:
- /data/gitlab/config:/etc/gitlab:rw
- /data/gitlab/logs:/var/log/gitlab:rw
- /data/gitlab/data:/var/opt/gitlab:rw

postgresql:
restart: always
image: postgres:9.6.2-alpine
environment:
- POSTGRES_USER=gitlab
- POSTGRES_PASSWORD=gitlab
- POSTGRES_DB=gitlabhq_production
# the following are hints on what volumes to mount if you want to persist data
volumes:
- /home/foresight/postgresql:/var/lib/postgresql:rw

redis:
restart: always
image: redis:3.0.7-alpine
# DRONE
drone-server:
image: drone/drone:0.7.3
ports:
- "8000:8000"
networks:
- drone
- gitlab
links:
- gitlab
volumes:
- /home/drone:/var/lib/drone/
environment:
#@@@@@
DRONE_OPEN: "true"
DRONE_HOST: "http://10.0.0.200:8000"
DRONE_ADMIN: amaziagur
DRONE_GITLAB: "true"
DRONE_GITLAB_URL: "http://10.0.0.200"
DRONE_GITLAB_CLIENT: "secret"
DRONE_GITLAB_SECRET: "secret"
DRONE_SECRET: "my_secret"
#@@@@@@@
drone-agent:
image: drone/drone:0.7.3
command: agent
depends_on:
- drone-server
networks:
- drone
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
DRONE_SERVER: ws://drone-server:8000/ws/broker
DRONE_DEBUG: "true"
DRONE_SECRET: "our_secret_4ever_and_ever"

networks:
drone:
driver: bridge
gitlab:
driver: bridge

两者都安装在同一台机器上,我想不通我做错了什么,无人机一直不识别git主机是什么原因。

我已经在我的本地/etc/hosts 和我在网络上找到的/etc/resolve.conf 提示中添加了映射。有人可以帮忙吗?

最佳答案

长话短说

主要原因是因为实际的克隆步骤是由一个临时的独立 docker 容器驱动的,它位于它自己的 docker 网络中。所以它无法解析名称 my-git,即使它能够解析它,也无法访问它。

预期的解决方法失败:

首先,您会注意到您的错误是关于解析 my-git。这个必须在实际执行克隆的 docker git 容器实例上解决,而不是在任何其他地方。意思是修改这个docker实例的/etc/hosts。这可以在您的 .drone.yml 中完成,方法是将克隆步骤替换为您的,并使用 docker-composeextra_hosts 功能(参见 docs)。这是如何完成的:

kind: pipeline
name: default

clone:
disable: true

steps:
- name: myclone
image: docker:git
## If you wanted to solve resolving part
extra_hosts:
- "my-git:10.0.0.200"
## Alas this will also be needed, and is NOT supported yet
# networks:
# - gitlab
commands:
## this will show you if ``my-git`` is resolved.
- ping -c 1 my-git
- git clone http://my-git/amaziagur/location-service.git/

##
## ... your normal steps follows ...
##

唉,如果你的容器现在能够将 my-git 解析为实际的 IP,它仍然无法访问它,因为它是在一个自定义网络中生成的,而不是连接到另一个。

为此,我们还需要能够指定 docker 实例应该连接到的网络,这通常是通过 docker- 中的 networks 键完成的撰写(您可以在 docker-compose reference about specifying custom networks 中查看)。

唉,这在 drone 目前不受支持,并且是目前通过 this issue 跟踪的错误.在撰写本文时,它甚至在 1.0.0-rc.5 中仍未解决。

请注意,如果 networks 键按预期工作,则 extra_hosts 将是多余的。

关于docker - 无人机 CI 在克隆步骤上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46277180/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com