網頁

2016年11月30日 星期三

Install GitLab on FreeBSD 10

網路上比較多看到的文章大概是:
Installing GitLab on FreeBSD 10
不過他是手動用 gem 裝,個人不是很喜歡這種方式,想到之前看 2016 June Status Report 好像依稀有看到 Bringing GitLab into the Ports Collection 就翻了一下,所以照著 pkg-message 裡面的指示文件設定,不過會卡一些小地方,記錄下來避免以後需要重新查。


首先,更新你的 ports tree
sudo portsnap fetch update
然後,進場安裝 gitlab
cd /usr/ports/www/gitlab
然後照著 文件 一步一步設定,大致上就能跑起來。 當中遇到幾個小問題: 現存 nginx 已經設定過,所以要自己生一組 vhost 設定檔,姑且叫他 gitlab.conf:
upstream gitlab-workhorse {
  server unix:/usr/local/www/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0;
}

server {
        listen       80;
        server_name  你的DOMAIN;
        rewrite      ^ https://$server_name$request_uri? permanent;
}

server {
        listen       443;
        server_name  你的DOMAIN;
        server_tokens off;
        charset utf-8;

        error_log   /PATH_TO/nginx-error.log  info;
        access_log  /PATH_TO/nginx-access.log combined;

        ssl                  on;
        ssl_certificate      /PATH_TO/ssl.pem;
        ssl_certificate_key  /PATH_TO/ssl.key;

        location / {
          client_max_body_size 0;
          gzip off;

          ## https://github.com/gitlabhq/gitlabhq/issues/694
          ## Some requests take more than 30 seconds.
          proxy_read_timeout      300;
          proxy_connect_timeout   300;
          proxy_redirect          off;

          proxy_http_version 1.1;

          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-Forwarded-Proto   $scheme;

          proxy_pass http://gitlab-workhorse;
        }

        error_page 404 /404.html;
        error_page 422 /422.html;
        error_page 500 /500.html;
        error_page 502 /502.html;
        error_page 503 /503.html;
        location ~ ^/(404|422|500|502|503)\.html$ {
          root /usr/local/www/gitlab/public;
          internal;
        }

}


然後把 nginx 重跑,記得先把 gitlab 跑起來
service gitlab start
然後可以注意一下 gitlab:check 裡面的問題,一一把它修復:
cd  /usr/local/www/gitlab
rake gitlab:check RAILS_ENV=production
當中我一直遇到 gitlab-shell 的問題
cd /usr/local/share/gitlab-shell/
./bin/check
發現說我 url 改錯了,所以,所以編輯一下
#不是 FQDN
gitlab_url: "http://localhost:8080"
http_settings:
  self_signed_cert: false
auth_file: "/PATH_TO_UR_SSH_AUTH_FILE/authorized_keys"
# File that contains the secret key for verifying access to GitLab.
# Default is .gitlab_shell_secret in the root directory.
# secret_file: "/home/git/gitlab-shell/.gitlab_shell_secret"
# Redis settings used for pushing commit notices to gitlab
redis:
  bin: /usr/bin/redis-cli
  database: 0
  socket: /var/run/redis/redis.sock # Comment out this line if you want to use TCP or Sentinel
  namespace: resque:gitlab
log_file: "/var/log/gitlab-shell/gitlab-shell.log"
log_level: INFO
audit_usernames: false
git_annex_enabled: false
要注意的是這個檔案的空白、tab 會影響 parse 正確性,不要亂加空白。 然後還是跑不起來,發現 /usr/local/share/gitlab-shell/lib 少了 gitlab_reference_counter.rb 補給他:
cd /usr/local/share/gitlab-shell/lib
fetch https://raw.githubusercontent.com/gitlabhq/gitlab-shell/master/lib/gitlab_reference_counter.rb
重啟一次 service ,搞定。 Note1. 為什麼不用 pkg ?因為腦闆說 redmine 吃了很多要特別設定的 plugin ,ruby pkg 下去會爛光光。懶得確認狀況,不然我最近犯懶都習慣 pkg 到底了 XD