New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change CI worker CI_PROJECT_URL on GitLab runner with Nginx reverse proxy #1487

Closed
1am opened this Issue Jan 27, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@1am

1am commented Jan 27, 2018

Hello,

I'm working on a setup where docker-gitlab on port 10080 is exposed to the outside via nginx proxy with SSL on port 80. This works well, I've also got SSH set up for normal git and is also ok.

I've updated recently to GitLab 10.3.6 to test out all CI and runners + docker and after getting through the basics and testing locally I'm trying to build project on commit on a runner which is set up on my macbook. So far everything is working ok.

The problem starts at the point where GitLab triggers runner to build the project inside docker. Since GitLab is behind Nginx runner is getting the URL which is composed from my docker-compose GITLAB_HOST and internal port in docker instead of 80. Here docker inside docker fails to check out the sources and it's all over.

I've tried changing the .gitlab-ci.yml to include override to the situation

...
variables:
  DOCKER_DRIVER: overlay2
  CI_DEBUG_TRACE: "true"
  CI_PROJECT_URL: "https://addres-to-my-gitlab.com/gitlab-runner-test"
...

but it fails the same way:

...
Cloning into '/builds/me/gitlab-runner-test'...
fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@addres-to-my-gitlab.com:10080/gitlab-runner-test.git/': error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
ERROR: Job failed: exit code 1

Did anyone solve this before? I think that Nginx or other server to expose docker container is a pretty common setup for users of this project so someone possibly bumped into this.

@1am

This comment has been minimized.

Show comment
Hide comment
@1am

1am Jan 29, 2018

Ok, so it seems that I've found it thanks to good docs How clone_url works
The missing secret was --clone-url parameter for runner registration.

gitlab-runner register -n \
    --url https://addres-to-my-gitlab.com/gitlab-runner-test \
    --registration-token ${TOKEN} \
    --executor ${EXECUTOR} \
    --description "Test Docker Runner" \
    --docker-image "docker:latest" \
    --docker-privileged \
    --clone-url https://addres-to-my-gitlab.com/gitlab-runner-test

1am commented Jan 29, 2018

Ok, so it seems that I've found it thanks to good docs How clone_url works
The missing secret was --clone-url parameter for runner registration.

gitlab-runner register -n \
    --url https://addres-to-my-gitlab.com/gitlab-runner-test \
    --registration-token ${TOKEN} \
    --executor ${EXECUTOR} \
    --description "Test Docker Runner" \
    --docker-image "docker:latest" \
    --docker-privileged \
    --clone-url https://addres-to-my-gitlab.com/gitlab-runner-test

@1am 1am closed this Jan 29, 2018

@ChunAllen

This comment has been minimized.

Show comment
Hide comment
@ChunAllen

ChunAllen May 16, 2018

Hi @1am, I also encountered this issue. How did you resolved this? Did you change something in docker-compose.yml?

Currently I can access Gitlab using http://localhost:10080 but whenever I run the builds in gitlab I keep getting this.

How did you managed to run the script gitlab-runner register using docker?

Fetching changes...
HEAD is now at 0046c57 add US and india number for whitelisting
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@localhost:10080/projects/test_project.git/': Failed to connect to localhost port 10080: Connection refused
ERROR: Build failed: exit code 1

ChunAllen commented May 16, 2018

Hi @1am, I also encountered this issue. How did you resolved this? Did you change something in docker-compose.yml?

Currently I can access Gitlab using http://localhost:10080 but whenever I run the builds in gitlab I keep getting this.

How did you managed to run the script gitlab-runner register using docker?

Fetching changes...
HEAD is now at 0046c57 add US and india number for whitelisting
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@localhost:10080/projects/test_project.git/': Failed to connect to localhost port 10080: Connection refused
ERROR: Build failed: exit code 1
@1am

This comment has been minimized.

Show comment
Hide comment
@1am

1am May 16, 2018

Hi @ChunAllen It was quite some time ago but I think that the --clone-url parameter solved the issue for me.
If you still have issues see if you don't have multiple similar runners defined in ~/.gitlab-runner/config.toml. Every time you register a runner a new entry is added in the configuration so maybe wrong worker is picking the job in your case. But it's just a guess.

1am commented May 16, 2018

Hi @ChunAllen It was quite some time ago but I think that the --clone-url parameter solved the issue for me.
If you still have issues see if you don't have multiple similar runners defined in ~/.gitlab-runner/config.toml. Every time you register a runner a new entry is added in the configuration so maybe wrong worker is picking the job in your case. But it's just a guess.

@ChunAllen

This comment has been minimized.

Show comment
Hide comment
@ChunAllen

ChunAllen May 17, 2018

Thanks @1am, I figured it out. I was able to run the build by changing the the GITLAB_HOST url.

ChunAllen commented May 17, 2018

Thanks @1am, I figured it out. I was able to run the build by changing the the GITLAB_HOST url.

@PhillippOhlandt

This comment has been minimized.

Show comment
Hide comment
@PhillippOhlandt

PhillippOhlandt Jun 18, 2018

@ChunAllen Did you setup a local domain? I encounter the same error where the gitlab-runner wants to fetch from localhost:10080 which doesn't resolve to my MacBook.

PhillippOhlandt commented Jun 18, 2018

@ChunAllen Did you setup a local domain? I encounter the same error where the gitlab-runner wants to fetch from localhost:10080 which doesn't resolve to my MacBook.

@ChunAllen

This comment has been minimized.

Show comment
Hide comment
@ChunAllen

ChunAllen Jun 19, 2018

@PhillippOhlandt I'm using ngrok to host gitlab it on my local machine.

I setup ngrok to point to localhost:10080 and when I run ngrok it returns me a local url which I can use in GITLAB_HOST url

sample:
GITLAB_HOST=http://abcgitlab.ngrok.io

ChunAllen commented Jun 19, 2018

@PhillippOhlandt I'm using ngrok to host gitlab it on my local machine.

I setup ngrok to point to localhost:10080 and when I run ngrok it returns me a local url which I can use in GITLAB_HOST url

sample:
GITLAB_HOST=http://abcgitlab.ngrok.io

@PhillippOhlandt

This comment has been minimized.

Show comment
Hide comment
@PhillippOhlandt

PhillippOhlandt Jun 19, 2018

@ChunAllen Make sense, thanks. In the meantime, I found another solution that worked for me.

In the config file for the runner under the [runners.docker] section, I added extra_hosts = ["localhost:172.17.0.1"] to override localhost inside the container. It's quite hacky but works so far.

PhillippOhlandt commented Jun 19, 2018

@ChunAllen Make sense, thanks. In the meantime, I found another solution that worked for me.

In the config file for the runner under the [runners.docker] section, I added extra_hosts = ["localhost:172.17.0.1"] to override localhost inside the container. It's quite hacky but works so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment