Support #679
Updated by Daniel Curtis about 9 years ago
{{>toc}} This is a guide on installing GitLab 8 with continuous integration on FreeBSD 10. h2. Prepare the Environment * Make sure the system is up to date: <pre> pkg update && pkg upgrade </pre> * Install a few dependencies: <pre> pkg install sudo bash icu cmake pkgconf git node ruby ruby21-gems logrotate postfix krb5 go wget rubygem-bundler portmaster postgresql94-server redis gmake mercurial </pre> * Add the GitLab user <pre> pw add user -n git -m -s /usr/local/bin/bash -c "GitLab" </pre> * Add git to the redis group: <pre> pw usermod git -G redis </pre> * Install a couple gems: <pre> gem install whenever rubocop </pre> h3. Configure Postfix * Enable postfix as the mail delivery agent, and disable sendmail: <pre> echo 'postfix_enable="YES"' >> /etc/rc.conf echo 'sendmail_enable="NO"' >> /etc/rc.conf echo 'sendmail_submit_enable="NO"' >> /etc/rc.conf echo 'sendmail_outbound_enable="NO"' >> /etc/rc.conf echo 'sendmail_msp_queue_enable="NO"' >> /etc/rc.conf </pre> h3. Configure PostgreSQL * Start and enable postgresql at boot: <pre> echo 'postgresql_enable="YES"' >> /etc/rc.conf service postgresql start </pre> * Log in to postgresql user account <pre> su - pgsql </pre> * Initialise postgresql database <pre> initdb /usr/local/pgsql/data </pre> * Connect to postgresql database <pre> psql -d template1 </pre> #* Create a user for GitLab: <pre> CREATE USER git CREATEDB; </pre> #* Create the GitLab production database & grant all privileges on database <pre> CREATE DATABASE gitlabhq_production OWNER git encoding='UTF8'; </pre> #* Quit the database session <pre> \q </pre> h3. Configure Redis * Back up the original Redis config file: <pre> cp /usr/local/etc/redis.conf /usr/local/etc/redis.conf.orig </pre> * Disable Redis listening on TCP by setting 'port' to 0 <pre> sed -i '' -e 's/^port .*/port 0/' /usr/local/etc/redis.conf </pre> * Enable Redis socket <pre> echo 'unixsocket /usr/local/var/run/redis/redis.sock' >> /usr/local/etc/redis.conf </pre> * Grant permission to the socket to all members of the redis group <pre> echo 'unixsocketperm 770' >> /usr/local/etc/redis.conf </pre> * Create the directory which contains the socket <pre> mkdir -p /usr/local/var/run/redis chown redis:redis /usr/local/var/run/redis chmod 755 /usr/local/var/run/redis </pre> * Start and enable redis at boot: <pre> echo 'redis_enable="YES"' >> /etc/rc.conf service redis restart </pre> h2. Install GitLab 8 * Switch to the git user: <pre> su - git </pre> * Clone GitLab repository <pre> git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-1-stable gitlab </pre> * Switch to the GitLab installation folder <pre> cd /home/git/gitlab </pre> * Copy the example GitLab config <pre> cp config/gitlab.yml.example config/gitlab.yml </pre> * Update GitLab config file, follow the directions at top of file <pre> vi config/gitlab.yml </pre> * Copy the example secrets file <pre> cp config/secrets.yml.example config/secrets.yml chmod 0600 config/secrets.yml </pre> * Make sure GitLab can write to the @log/@ and @tmp/@ directories <pre> chown -R git log/ chown -R git tmp/ chmod -R u+rwX,go-w log/ chmod -R u+rwX tmp/ </pre> * Make sure GitLab can write to the @tmp/pids/@ and @tmp/sockets/@ directories <pre> chmod -R u+rwX tmp/pids/ chmod -R u+rwX tmp/sockets/ </pre> * Make sure GitLab can write to the @public/uploads/@ directory <pre> chmod -R u+rwX public/uploads </pre> * Change the permissions of the directory where CI build traces are stored <pre> chmod -R u+rwX builds/ </pre> * Copy the example Unicorn config <pre> cp config/unicorn.rb.example config/unicorn.rb </pre> * Copy the example Rack attack config <pre> cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb </pre> * Configure Git global settings for git user, used when editing via web editor <pre> git config --global core.autocrlf input </pre> * Configure Redis connection settings <pre> cp config/resque.yml.example config/resque.yml </pre> * Change the Redis socket path if you are not using the default Debian / Ubuntu configuration <pre> vi config/resque.yml </pre> #* And modify the following parameter: <pre> production: unix:/usr/local/var/run/redis/redis.sock </pre> * Configure GitLab DB Settings: <pre> cp config/database.yml.postgresql config/database.yml </pre> * Change the database credentials <pre> vi config/database.yml </pre> * Make config/database.yml readable to git only <pre> chmod o-rwx config/database.yml </pre> * Install the gems for PostgreSQL: <pre> bundle install --deployment --without development test mysql aws kerberos </pre> h3. Install GitLab Shell * Run the installation task for gitlab-shell: <pre> bundle exec rake gitlab:shell:install[v2.6.5] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production </pre> # By default, the gitlab-shell config is generated from your main GitLab config, double check the settings are correct: <pre> vi /home/git/gitlab-shell/config.yml </pre> h3. Install GitLab HTTP Server * Install the gitlab http server: <pre> cd /home/git git clone https://gitlab.com/gitlab-org/gitlab-git-http-server.git cd gitlab-git-http-server git checkout 0.3.0 make </pre> h3. Initialize Database * Initialize the database: <pre> bundle exec rake gitlab:setup RAILS_ENV=production </pre> h3. Install schedules * Install whenenver: <pre> cd /home/git/gitlab echo "gem 'whenever', '~> 0.9.3'" >> Gemfile bundle install --no-deployment --path vendor/bundle bundle install --deployment --without development test mysql aws kerberos </pre> * Setup schedules <pre> bundle exec whenever -w RAILS_ENV=production </pre> h3. Install Init Script * Exit out of the git user, back into root: <pre> exit </pre> * Download the init script: <pre> wget -O /usr/local/etc/rc.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/init/freebsd/gitlab-unicorn </pre> * Fix the shell environment for the init script: <pre> sed -i '' -e 's/\#\!\ \/bin\/sh/\#\!\ \/usr\/local\/bin\/bash' /usr/local/etc/rc.d/gitlab </pre> * Make the init script executable: <pre> chmod +x /usr/local/etc/rc.d/gitlab </pre> h3. Check Configuration and Compile Assets * Check the configuration: <pre> cd /home/git/gitlab bundle exec rake gitlab:env:info RAILS_ENV=production </pre> * Compile all of the assets for GitLab: <pre> bundle exec rake assets:precompile RAILS_ENV=production </pre> * Start and enable gitlab at boot: <pre> echo 'gitlab_enable="YES"' >> /etc/rc.conf service gitlab start </pre> h2. Install Nginx * Install nginx: <pre> portmaster www/nginx </pre> *NOTE*: Make sure to enable *[X]HTTP_GZIP_STATIC* during the nginx configuration * Start and enable nginx at boot: <pre> echo 'nginx_enable="YES"' >> /etc/rc.conf service nginx start </pre> * Create a configuration directory to make managing individual server blocks easier <pre> mkdir /usr/local/etc/nginx/conf.d </pre> * Edit the main nginx config file: <pre> vi /usr/local/etc/nginx/nginx.conf </pre> #* And strip down the config file and add the include statement at the end to make it easier to handle various server blocks: <pre> #user nobody; worker_processes 1; error_log /var/log/nginx-error.log; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # Load config files from the /etc/nginx/conf.d directory include /usr/local/etc/nginx/conf.d/*.conf; } </pre> * Create the gitlab nginx config: <pre> vi /usr/local/etc/nginx/conf.d/gitlab.conf </pre> #* And add the following: <pre> upstream gitlab { server unix:/home/git/gitlab/tmp/sockets/gitlab.socket fail_timeout=0; } upstream gitlab-git-http-server { server unix:/home/git/gitlab/tmp/sockets/gitlab-git-http-server.socket fail_timeout=0; } server { listen 0.0.0.0:80 default_server; server_name gitlab.example.com; server_tokens off; root /home/git/gitlab/public; client_max_body_size 20m; access_log /var/log/gitlab_access.log; error_log /var/log/gitlab_error.log; location / { try_files $uri $uri/index.html $uri.html @gitlab; } location /uploads/ { proxy_read_timeout 300; proxy_connect_timeout 300; proxy_redirect off; 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_set_header X-Frame-Options SAMEORIGIN; proxy_pass http://gitlab; } location @gitlab { proxy_read_timeout 300; proxy_connect_timeout 300; proxy_redirect off; 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_set_header X-Frame-Options SAMEORIGIN; proxy_pass http://gitlab; } location ~ ^/[\w\.-]+/[\w\.-]+/(info/refs|git-upload-pack|git-receive-pack)$ { error_page 418 = @gitlab-git-http-server; return 418; } location ~ ^/[\w\.-]+/[\w\.-]+/repository/archive { error_page 418 = @gitlab-git-http-server; return 418; } location ~ ^/api/v3/projects/.*/repository/archive { error_page 418 = @gitlab-git-http-server; return 418; } location @gitlab-git-http-server { proxy_read_timeout 300; proxy_connect_timeout 300; proxy_redirect off; proxy_buffering off; proxy_request_buffering 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-git-http-server; } location ~ ^/(assets)/ { root /home/git/gitlab/public; gzip_static on; expires max; add_header Cache-Control public; } error_page 502 /502.html; } </pre> h2. Install GitLab Runner * Add a go path to .profile: <pre> su - git echo 'export GOPATH=$HOME/Go' >> ~/.profile echo 'export PATH=$PATH:$GOPATH/bin:/usr/local/go/bin' >> ~/.profile exit su - git </pre> * Create new terminal session and create $GOPATH directory: <pre> mkdir -p $GOPATH </pre> * Download runner sources <pre> go get gitlab.com/gitlab-org/gitlab-ci-multi-runner cd $GOPATH/src/gitlab.com/gitlab-org/gitlab-ci-multi-runner/ </pre> * Install runner dependencies <pre> gmake deps </pre> * Run runner <pre> go run main.go </pre> * Compile and install runner binary <pre> go build go install </pre> * Open a web browser and go to http://gitlab.example.com, then log in as the admin user: #* Username *root*, password 5iveL!fe * Next navigate to http://gitlab.example.com/ci/admin/runners to get the token * Finally register: <pre> gitlab-ci-multi-runner register --non-interactive --url "http://gitlab.example.com/ci" --registration-token "5777041dc9651d08ff77" --description "gitlab-ce-ruby-2.1" --executor "shell" builds_dir = "" shell = "bash" </pre> h2. Resources * http://doc.gitlab.com/ce/install/installation.html * https://github.com/gitlabhq/gitlab-recipes/blob/master/install/freebsd/freebsd-10.md * https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/development/README.md