我在docker的机器上运行 - 组成以下内容:
当我触发构建(或由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中添加了我在网络上找到的提示。 有人可以帮忙吗?
答案 0 :(得分:0)
Brad Rydzewski's comment让我走上正轨。他说:
配置gitlab时,您需要使用IP地址或域名。您无法使用内部docker主机名(例如my-git),因为当无人机生成管道容器时,这些容器将位于不同的网络上,并且无法解析my-git
这是完全正确的。以下是对我有用的最终配置:
version: '2'
services:
web:
image: 'gitlab/gitlab-ce:latest'
restart: always
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url '<IP address or domain name>'
gitlab_rails['gitlab_shell_ssh_port'] = 22
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '80:80'
- '443:443'
- '22:22'
volumes:
- '/srv/gitlab/config:/etc/gitlab'
- '/srv/gitlab/logs:/var/log/gitlab'
- '/srv/gitlab/data:/var/opt/gitlab'
drone-server:
image: drone/drone:0.7.3
links:
- web
ports:
- "8000:8000"
volumes:
- /home/drone:/var/lib/drone/
environment:
DRONE_OPEN: "true"
DRONE_HOST: "<IP address or domain name> : <port>"
DRONE_ADMIN: <admin users - should be git user names>
DRONE_GITLAB: "true"
DRONE_GITLAB_URL: "<IP address or domain name>"
DRONE_GITLAB_CLIENT: "<Application Id in gitlab>"
DRONE_GITLAB_SECRET: "<Secret in gitlab>"
DRONE_SECRET: "<secret drone>"
drone-agent:
image: drone/drone:0.7.3
command: agent
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
DRONE_SERVER: ws://drone-server:8000/ws/broker
DRONE_DEBUG: "true"
DRONE_SECRET: "<secret drone>"
答案 1 :(得分:0)
TL; DR
主要原因是因为实际的克隆步骤是由特定的独立docker容器驱动的,该容器位于其自己的docker网络中。因此它无法解析名称my-git
,即使它能够解析它,也无法找到它。
预期的解决方法失败:
首先,您会注意到您的错误与解决 my-git
有关。 必须在实际进行克隆的docker git容器实例上解决,而不是在其他任何地方。这意味着修改此docker实例的/etc/hosts
。这可以在您的.drone.yml
中完成,方法是替换您的克隆步骤,并使用docker-compose
的{{1}}功能(参见docs)。就是这样的:
extra_hosts
A,如果您的容器现在能够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 ...
##
解析为实际IP,则它仍将无法访问,因为它是在未连接到另一个的自定义网络中生成的。
为此,我们还需要能够指定docker实例应该连接到的网络,通常通过my-git
中的networks
键(如您所可以签入docker-compose reference about specifying custom networks)。
A,目前docker-compose
不支持此功能,并且是this issue当前跟踪的错误。截至撰写本文时,即使在drone
中也没有解决该问题。
请注意,如果1.0.0-rc.5
键可以按预期工作,则networks
将是多余的。
答案 2 :(得分:0)
由于这是该问题排名最高的问题,我想对此进行总结。
previously mentioned issue拥有您需要的响应,但尚不明确,因为它在github mentions日志中,并且最初链接的问题已关闭而没有解决方案。
您可以将DRONE_RUNNER_NETWORKS =传递给代理(或 服务器(如果您不使用代理)。当无人机产生容器时 它将所有容器附加到指定的网络。
来源: https://discourse.drone.io/t/gitea-drone-traefik-agent-cannot-reach-git-repo/4170/2?u=bradrydzewski
请注意,您还希望在docker-compose https://docs.docker.com/compose/networking/#specify-custom-networks中将网络添加到运行程序中-否则初始ping操作将失败,并且不会产生更多运行程序。
一个完整的无人码头工人的例子:
drone-runner-docker:
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
environment:
- DRONE_RPC_PROTO=http
- DRONE_RPC_HOST=172.20.0.19
- DRONE_RPC_SECRET=SECRET
- DRONE_RUNNER_CAPACITY=2
- DRONE_RUNNER_NAME=drone-runner-docker
- DRONE_RUNNER_NETWORKS=droneio_network,another_network
networks:
droneio_network:
another_network:
ports:
- '3000'
restart: always
image: 'drone/drone-runner-docker:latest'
有关变量的解释,请参见drone docs。
确保您在环境中为DRONE_RUNNER_NETWORKS
提供的名称是来自docker network ls
的实际网络名称。 (如果是通过docker-compose生成的,它们通常具有infront的文件夹名称,例如foldername_default
)