Monday, July 14, 2014

Installing GitLab on Odroid (ArchlinuxARM)

This post summarizes all steps necessary to install GitLab on odroid. The steps are basically the same as in the official guide.
Additionally I show my nginx and HA Proxy configuration for gitlab with changed docroot (relative url root) and explain how to successfully install bundle packages without libv8 dependency.

These steps are minimal requirement to install GitLab with mysql DB support:
useradd -d /home/git -m -s /bin/bash git
pacman -S git ruby patch (here you may need some additional dependencies, I didn't)
su - git
    gem install bundler --no-ri --no-rdoc
    vim .bashrc
        # add ruby binaries to PATH
        export PATH=$PATH:/home/git/.gem/ruby/2.1.0/bin
    . .bashrc
    mysql -u root -p
        CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
        SET storage_engine=INNODB;
        CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
        GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
        quit
    git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-1-stable gitlab
    cd gitlab
    cp config/gitlab.yml.example config/gitlab.yml
    vim config/gitlab.yml
        host: localhost
        port: 3002
    chown -R git log/ tmp/
    chmod -R u+rwX log/ tmp/
    mkdir /home/git/gitlab-satellites
    chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
    chmod -R u+rwX tmp/pids/ tmp/sockets/ public/uploads
    cp config/unicorn.rb.example config/unicorn.rb
    vim config/unicorn.rb
        listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64
        listen "localhost:3002", :tcp_nopush => true
    cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
    git config --global user.name "GitLab"
    git config --global user.email "mymail@gmail.com"
    git config --global core.autocrlf input
    cp config/database.yml.mysql config/database.yml
    vim config/database.yml
        ...set DB preferences here...
    bundle install --deployment --without development test postgres aws
    NOTE: here you need to start redis daemon
    bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production
    bundle exec rake gitlab:setup RAILS_ENV=production
        login.........admin@local.host
        password......5iveL!fe
    cp lib/support/init.d/gitlab ~/gitlab-start-stop (start as user git)
    bundle exec rake gitlab:env:info RAILS_ENV=production
    bundle exec rake assets:precompile RAILS_ENV=production
as root: cp /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/gitlab 

Updated manual for GitLab 7.9
useradd -d /home/git -m -s /bin/bash git  
pacman -S git ruby patch (here you may need some additional dependencies, I didn't)  
su - git  
    gem install bundler --no-ri --no-rdoc  
    vim .bashrc  
        # add ruby binaries to PATH  
        export PATH=$PATH:/home/git/.gem/ruby/2.2.0/bin  
    . .bashrc  
    mysql -u root -p  
        CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';  
        SET storage_engine=INNODB;  
        CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;  
        GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';  
        quit  
    git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-9-stable gitlab  
    cd gitlab  
    cp config/gitlab.yml.example config/gitlab.yml  
    vim config/gitlab.yml  
        host: localhost  
        port: 3002  
    chown -R git log/ tmp/  
    chmod -R u+rwX log/ tmp/  
    mkdir /home/git/gitlab-satellites  
    chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites  
    chmod -R u+rwX tmp/pids/ tmp/sockets/ public/uploads  
    cp config/unicorn.rb.example config/unicorn.rb  
    vim config/unicorn.rb  
        listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64  
        listen "localhost:3002", :tcp_nopush => true  
    cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb  
    git config --global user.name "GitLab"  
    git config --global user.email "mymail@gmail.com"  
    git config --global core.autocrlf input  
    cp config/resque.yml.example config/resque.yml
    vim config/resque.yml
    cp config/database.yml.mysql config/database.yml  
    vim config/database.yml  
        ...set DB preferences here...  
    bundle install -j4 --deployment --without development test postgres aws  
    NOTE: here you need to start redis daemon  
    bundle exec rake gitlab:shell:install[v2.6.0] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
    vim /home/git/gitlab-shell/config.yml
    bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword
    cp lib/support/init.d/gitlab ~/gitlab-start-stop (start as user git)  
    bundle exec rake gitlab:env:info RAILS_ENV=production  
    bundle exec rake assets:precompile RAILS_ENV=production  
as root: cp /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/gitlab   

check gitlab:
bundle exec rake gitlab:check RAILS_ENV=production
recreate satelites (in case of migration)
bundle exec rake gitlab:satellites:create RAILS_ENV=production

If you successfully finished the above list, you have installed GitLab, but most probably you have run into a problem during libv8 compilation, which could not be, at least in my case, cleanly compiled on arm.

PROBLEM:
linking shared-object v8/init.so
/usr/bin/ld: /home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/vendor/v8/out/arm.release/obj.target/tools/gyp/libv8_base.a(api.o): relocation R_ARM_MOVW_ABS_NC against `_ZN2v88internal7Isolate12isolate_key_E' can not be used when making a shared object; recompile with -fPIC
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/vendor/v8/out/arm.release/obj.target/tools/gyp/libv8_base.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:232: recipe for target 'init.so' failed
make: *** [init.so] Error 1

make failed, exit code 2

Gem files will remain installed in /home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/therubyracer-0.12.0 for inspection.
Results logged to /home/git/gitlab/vendor/bundle/ruby/2.1.0/extensions/armv7l-linux/2.1.0/therubyracer-0.12.0/gem_make.out
An error occurred while installing therubyracer (0.12.0), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.0'` succeeds before bundling.


REASON: libv8 could not be cleanly compiled on arm.

The solution I've found is described on this blog (in German). From this post, I've read the problem is with the Gem therubyracer, which has libv8 as a dependency. This dependency needed to be removed and therubyracer functionality had to be replaced with nodejs (simply by installing package nodejs).

SOLUTION: 
remove therubyracer from /home/git/gitlab/Gemfile and remove libv8 and therubyracer from /home/git/gitlab/Gemfile.lock (see bundler best practices for more details). Afterwards run:
cd /home/git/gitlab
bundle install --no-deployment --path vendor/bundle
and continue again with command
bundle install --deployment --without development test postgres aws

Changing Gitlab's working directory
Because I use HA Proxy with acl pattern matching, I needed to change gitlabs working directory from default (/) to custom (/gitlab).
This can be achieved by changing few files in gitlab as mentioned in config/application.rb:
    # 1) In your application.rb file: config.relative_url_root = "/gitlab"
    # 2) In your gitlab.yml file: relative_url_root: /gitlab
    # 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
    # 4) In ../gitlab-shell/config.yml: gitlab_url: "http://localhost:3002/gitlab"
    # 5) In lib/support/nginx/gitlab (sample nginx conf) : do not use asset gzipping, remove block starting with "location ~ ^/(assets)/"

HA Proxy and nginx configuration
Here's related configuration for HA Proxy:

# odroid frontend
frontend odroid
    bind 172.16.0.1:443 ssl crt /etc/haproxy/ssl/server.pem
    mode http

    acl url_gitlab        path_beg  /gitlab

    use_backend nginx-gitlab       if url_gitlab
    default_backend nginx-default

# backend for gitlab
backend nginx-gitlab
    mode    http
    #balance roundrobin
    option  httpclose
    option  forwardfor
    server  odroid 127.0.0.1:8380 check inter 5000 rise 2 fall 3
Note: I call gitlab with URL https://172.16.0.1/gitlab

nginx configuration (based on sample conf /home/git/gitlab/lib/support/nginx/gitlab)
upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
  listen localhost:8380 default_server;         # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  server_name 10.10.10.10;     # e.g., server_name source.example.com;
  server_tokens off;     # don't show the version number, a security best practice

  access_log  /var/log/nginx/access-gitlab.log remote;
  error_log  /var/log/nginx/error-gitlab.log;

  root /srv/http/gitlab;

  # Increase this if you want to upload large attachments
  # Or if you want to accept large git objects over http
  client_max_body_size 20m;

  location /gitlab {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    # If you use https make sure you disable gzip compression 
    # to be safe against BREACH attack
    # gzip off;

    proxy_read_timeout 300; # Some requests take more than 30 seconds.
    proxy_connect_timeout 300; # Some requests take more than 30 seconds.
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto https;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
    proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header   X-Frame-Options   SAMEORIGIN;

    proxy_pass http://localhost:3002;
  }

  error_page 502 /502.html;
}
NOTE: I use SSL termination on HA Proxy, so I've had to change X-Forwarded-Proto to https for gitlab to work properly.
NOTE:  /srv/http/gitlab is a symbolic link pointing to /home/git/gitlab/public

5 comments:

  1. Since GitLab 7.9 therubyracer is no longer a dependency. It should be sufficient to install nodejs and do the bundle install command.

    ReplyDelete
    Replies
    1. thanks for the info,
      indeed I didn't run into this issue when installing gitlab 7.9

      Delete
  2. There's an official Omnibus package for the RPi2, see 'Omnibus package for Raspberry Pi 2' on https://about.gitlab.com/installation/

    ReplyDelete
  3. Krisko'S Blog: Installing Gitlab On Odroid (Archlinuxarm) >>>>> Download Now

    >>>>> Download Full

    Krisko'S Blog: Installing Gitlab On Odroid (Archlinuxarm) >>>>> Download LINK

    >>>>> Download Now

    Krisko'S Blog: Installing Gitlab On Odroid (Archlinuxarm) >>>>> Download Full

    >>>>> Download LINK Wy

    ReplyDelete
  4. Krisko'S Blog: Installing Gitlab On Odroid (Archlinuxarm) >>>>> Download Now

    >>>>> Download Full

    Krisko'S Blog: Installing Gitlab On Odroid (Archlinuxarm) >>>>> Download LINK

    >>>>> Download Now

    Krisko'S Blog: Installing Gitlab On Odroid (Archlinuxarm) >>>>> Download Full

    >>>>> Download LINK hj

    ReplyDelete