Daily Archives: 5. november 2015

How to get Gitlab-CI to work with apache

After using some hours searching on google and asking on IRC, i found the solution on why Gitlab-CI didn’t work in my setup with a docker image.

The default installation of GitLab uses Nginx, however in my setup i have an Apache 2.4 as the primary webserver, because other services are also running on this particular virtual machine.

My installation is an upgrade from GitLab 7.x to 8.1 and perhaps it as also introduced some issues.

So, the main issue is that gitlab-git-http-server is running as a socket as default.

In your apache config you need something like this.

<VirtualHost *:80>
  ServerAdmin admin@domain.tld
  ServerName gitlab.domain.tld
  ServerAlias gitlab

  ProxyPreserveHost On
  <Location />
      Require all granted
      ProxyPassReverse http://localhost:8080

      #Allow forwarding to gitlab-git-http-server
      ProxyPassReverse http://127.0.0.1:8181
  </Location>

  RewriteEngine on

  #Forward these requests to gitlab-git-http-server
  RewriteCond %{REQUEST_URI} ^/[\w\.-]+/[\w\.-]+/repository/archive.* [OR]
  RewriteCond %{REQUEST_URI} ^/api/v3/projects/.*/repository/archive.* [OR]
  RewriteCond %{REQUEST_URI} ^/[\w\.-]+/[\w\.-]+/(info/refs|git-upload-pack|git-receive-pack)$
  RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA]

  #Forward any other requests to GitLab Rails app (Unicorn)
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
  RewriteCond %{REQUEST_URI} ^/uploads
  RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA,NE]

  DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public
  ErrorDocument 404 /404.html
  ErrorDocument 422 /422.html
  ErrorDocument 500 /500.html
  ErrorDocument 503 /deploy.html

  LogLevel warn
  ErrorLog /var/log/apache2/gitlab.domain.tld-error.log
  CustomLog /var/log/apache2/gitlab.domain.tld-access.log combined
</VirtualHost>

And add/change the /etc/gitlab/gitlab.rb

########################
# GitLab git http server #
##########################
# see https://gitlab.com/gitlab-org/gitlab-git-http-server/blob/master/README.md

gitlab_git_http_server['enable'] = true
# gitlab_git_http_server['ha'] = false
# gitlab_git_http_server['repo_root'] = "/var/opt/gitlab/git-data/repositories"
gitlab_git_http_server['listen_network'] = 'tcp'
gitlab_git_http_server['listen_umask'] = 0
gitlab_git_http_server['listen_addr'] = 'localhost:8181'
# gitlab_git_http_server['listen_addr'] = "/var/opt/gitlab/gitlab-git-http-server/socket"
# gitlab_git_http_server['auth_backend'] = "http://localhost:8080"
# gitlab_git_http_server['pprof_listen_addr'] = "''" # put an empty string on the command line
# gitlab_git_http_server['dir'] = "/var/opt/gitlab/gitlab-git-http-server"

Then restart you Apache and reconfigure gitlab

apachectl graceful
sudo gitlab-ctl reconfigure

Now when the GitLab-CI can fetch the git repository using HTTP with authentication. However, on my setup, it still seems much slower than using SSH/GIT, but it might has something to do with the size of my repository.

UPDATED 12/November/2015: Added the whole Apache VirtualHost config