[fix] git clone with custom extra_hosts

FIX

in my blog: use private dns to fix it

yum install dnsmasq -y
vim /etc/docker/daemon.json

{
    "dns": ["10.123.12.14"]
}

https://www.chenyudong.com/archives/docker-custom-hosts-network-via-dns.html


build error

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

I konw is network error. But I add config extra_hosts: - "mygit.com:10.123.123.130" in docker-compose.yml.

I want to into container, but

docker exec -it 18a5f77fcc44 /bin/bash
exec: "/bin/bash": stat /bin/bash: no such file or directory

docker exec -it 18a5f77fcc44 ping mygit.com
exec: "ping": executable file not found in $PATH

drone can get gogs git project, and can login into drone.

How should I do?


drone docker debug info

drone-server_1  | time="2017-01-30T06:46:55Z" level=debug msg="launchpad granted &{Pull:true Push:true Admin:true} permission to launchpad/test" 
drone-server_1  | time="2017-01-30T06:46:55Z" level=debug msg="cannot find build secrets for launchpad/test. 404 Not Found" 
drone-server_1  | time="2017-01-30T06:46:55Z" level=debug msg="cannot parse .drone.yml.sig file. square/go-jose: compact JWS format must have three parts" 
drone-server_1  | time="2017-01-30T06:46:55Z" level=debug msg=".drone.yml is signed=false and verified=false" 
drone-server_1  | time="2017-01-30T06:46:55Z" level=info ip=10.10.12.123 latency=77.780567ms method=POST path="/api/repos/launchpad/test/builds/2" status=202 time="2017-01-30T06:46:55Z" user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36" 
drone-agent_1   | time="2017-01-30T06:46:55Z" level=info msg="Starting build launchpad/test#2.1" 
drone-server_1  | time="2017-01-30T06:46:55Z" level=debug msg="launchpad granted &{Pull:true Push:true Admin:true} permission to launchpad/test" 
drone-server_1  | time="2017-01-30T06:46:55Z" level=debug msg="Successfull upgraded websocket" 
drone-agent_1   | 1:M 30 Jan 06:46:57.409 - stomp: send heart-beat.
drone-agent_1   | 1:M 30 Jan 06:46:57.509 - stomp: received heart-beat
drone-agent_1   | time="2017-01-30T06:46:58Z" level=info msg="Finished build launchpad/test#2.1" 
drone-server_1  | 1:M 30 Jan 06:46:58.809 * stomp: unsubscribe 2: successful: destination /topic/cancel
drone-server_1  | time="2017-01-30T06:46:58Z" level=info ip=10.10.12.123 latency=3.133522595s method=GET path="/ws/logs/launchpad/test/2/1" status=200 time="2017-01-30T06:46:58Z" user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36"

docker-compose

version: '2'

services:
  drone-server:
    image: drone/drone:latest
    ports:
      - 8100:8000
    extra_hosts:
      - "mygit.com:10.123.123.130"
    volumes:
      - ./drone:/var/lib/drone/
    restart: always
    environment:
      - DRONE_OPEN=true
      - DRONE_DEBUG=true
      - DRONE_GOGS=true
      - DRONE_GOGS_URL=http://${GOGS_IP}/
      - DRONE_GOGS_PRIVATE_MODE=true
      - DRONE_GOGS_SKIP_VERIFY=true
      - DRONE_SECRET=${DRONE_SECRET}
      - DRONE_ADMIN=drone_admin

  drone-agent:
    image: drone/drone:latest
    extra_hosts:
      - "mygit.com:10.123.123.130"
    command: agent
    restart: always
    depends_on: [ drone-server ]
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_SERVER=ws://drone-server:8000/ws/broker
      - DRONE_SECRET=${DRONE_SECRET}
      - DRONE_DEBUG=true

Drone does not run git clone inside the agent. Therefore customizing the agents extra_hosts will not have any impact on cloning your repository. The git clone is instead executed inside a separate container, using the git clone plugin.

Unfortunately it sounds like Drone will not work out-of-the-box with you network configuration. You can perhaps try to fork and customize the git clone plugin (at GitHub - drone-plugins/drone-git: Drone plugin for cloning Git repositories) to work with your internal network.

You could then reference the custom plugin in your pipeline:

pipeline:
  clone:
    image: daoiqu/drone-git
  build:
    ...

this is drone agent to launch container? then the git container has not the network configure?