Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab runner unable to clone repository via http

I have the latest docker image of GitLab running in a test environment and I'm running into an issue with the GitLab runner. It's unable to clone via the HTTP link, yielding the following message:

Running on runner-bd27e50b-project-1-concurrent-0 via machine...
Cloning repository...
Cloning into '/builds/my/awesome-project'...
fatal: unable to access 'http://gitlab-ci-token:[email protected]/my/awesome-project.git/': 
    Failed to connect to 127.0.0.1 port 80: Connection refused

ERROR: Build failed with: exit code 1

I ran gitlab-runner with the --debug flag and used the exact address it was trying (with the token in-tact) and I could clone the repository just fine. I'm at a loss as to why the service is unable to clone the repository. The runner executor is configured as 'docker' as well. Maybe there is some port mapping issue into that container?

like image 298
Anthony Avatar asked Nov 30 '15 16:11

Anthony


People also ask

Can run untagged jobs GitLab runner?

Set a runner to run untagged jobsGo to the project's Settings > CI/CD and expand the Runners section. Find the runner you want to pick untagged jobs and make sure it's enabled. Click the pencil button. Check the Run untagged jobs option.


2 Answers

I hypothesized the issue might have something to do with registering the runner as a docker container causing the localhost address not to resolve to the right machine (where I'm starting the runner); in this case it probably resolves to the container instead. Using the host's IP on the docker proxy interface (172.17.0.1 for me) or using the host's real address instead of "localhost" when registering the runner fixes the problem.

Edit: Here is a bit more detail on the problem as I understand it and a solution. The docker instance that's loaded up is like a (very) lightweight virtual machine. Docker configures a virtual network interface which you'll see if you run ifconfig from your host machine:

user@pc:~> ifconfig
docker0   Link encap:Ethernet  HWaddr XXXX
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          ...

This is the IP address of the host machine on that interface. So, if you want the runner to be able to connect to the service that's running on that host machine, you can't point it to localhost/127.0.0.1 because, coming from inside the runner's instance, that will route to the runner's "VM", but GitLab is not running inside that runner "VM", it's on the host, so the runner is unable to communicate with GitLab.

The solution is to register the runner to point to the host's virtual address on the docker interface (http://172.17.0.1/ci for me), or to use the host's public IP or a domain name if you have one and it's accessible publicly. Just don't send it to localhost or 127.0.0.1 because, to the runner, that points to its "VM", not your GitLab instance.

like image 139
Anthony Avatar answered Oct 15 '22 19:10

Anthony


I know this question is pretty old, but you can use slightly different approach (in case you are using docker runner with the same problem).

Run Gitlab under a domain name - it may be totally virtual, just make sure that all your VMs can resolve the domain name.

Then modify /etc/gitlab-runner/config.toml and add extra_hosts variable to the [runners.docker] section with value ["your_domain_name:ip_address"]. You can also add any other hosts you may need.

You can find more info on runner config at https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/configuration/advanced-configuration.md

like image 20
Bart Avatar answered Oct 15 '22 20:10

Bart