Support #944
Updated by Daniel Curtis almost 6 years ago
{{>toc}} This is a guide on installing GitLab 11 from source with continuous integration on FreeBSD 11.2-RELEASE. 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 ruby24-gems logrotate postfix krb5 go wget rubygem-bundler rubygem-gpgme portmaster postgresql96-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> h3. Configure Postfix * Enable postfix as the mail delivery agent, and disable sendmail: <pre> sysrc postfix_enable="YES" sysrc sendmail_enable="NO" sysrc sendmail_submit_enable="NO" sysrc sendmail_outbound_enable="NO" sysrc sendmail_msp_queue_enable="NO" </pre> h3. Configure PostgreSQL * Initialize, start, and enable postgresql at boot: <pre> sysrc postgresql_enable="YES" service postgresql initdb service postgresql start </pre> * Log in to postgresql user account <pre> su - postgres </pre> * Connect to postgresql database <pre> psql -d template1 </pre> #* Create a user for GitLab: <pre> CREATE USER git WITH PASSWORD 'SuperSecretPassword' 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 exit </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 /var/run/redis </pre> * Start and enable redis at boot: <pre> sysrc redis_enable="YES" service redis start </pre> h2. Install GitLab 11.5 * Switch to the git user: <pre> su - git </pre> * Clone GitLab repository: <pre> git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 11-5-stable gitlab cd 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> #* And modify at least the following parameters: gitlab: host: gitlab.example.com email_from: gitlab@example.com git: bin_path: /usr/local/bin/git * 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> mkdir public/uploads/ chmod 0700 public/uploads </pre> * Change the permissions of the directory where CI build traces are stored: <pre> chmod -R u+rwX builds/ </pre> * Change the permissions of the directory where CI artifacts are stored: <pre> chmod -R u+rwX shared/artifacts/ </pre> # Change the permissions of the directory where GitLab Pages are stored: <pre> chmod -R ug+rwX shared/pages/ </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> * Disable 'git gc --auto' because GitLab already runs 'git gc' when needed: <pre> git config --global gc.auto 0 </pre> * Enable packfile bitmaps: <pre> git config --global repack.writeBitmaps true </pre> * Enable push options: <pre> git config --global receive.advertisePushOptions true </pre> * Configure resque connection settings <pre> cp config/resque.yml.example config/resque.yml </pre> * Change the resque 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 if necessary: <pre> vi config/database.yml </pre> * Make config/database.yml readable to git only <pre> chmod o-rwx config/database.yml </pre> * Configure the gpgme rubygem to use the installed library (to prevent hanging up during install): <pre> bundle config build.gpgme "--use-system-libraries" </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 REDIS_URL=unix:/usr/local/var/run/redis/redis.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true </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 Workhorse * Install the gitlab workhorse: <pre> bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]" RAILS_ENV=production </pre> h3. Install gitlab-pages * This step is optional and only needed if you wish to host static sites from within GitLab: <pre> cd /home/git git clone https://gitlab.com/gitlab-org/gitlab-pages.git cd gitlab-pages git checkout v$(</home/git/gitlab/GITLAB_PAGES_VERSION) gmake </pre> h3. Install Gitaly * Fetch Gitaly source with Git and compile with Go <pre> bundle exec rake "gitlab:gitaly:install[/home/git/gitaly,/home/git/repositories]" RAILS_ENV=production </pre> Next, make sure gitaly configured: * Restrict Gitaly socket access <pre> sudo chmod 0700 /home/git/gitlab/tmp/sockets/private sudo chown git /home/git/gitlab/tmp/sockets/private </pre> * If you are using non-default settings you need to update config.toml: <pre> cd /home/git/gitaly vi config.toml </pre> h3. Initialize Database * Initialize the database: <pre> cd /home/git/gitlab bundle exec rake gitlab:setup RAILS_ENV=production </pre> * Exit out of the git user, back into root: <pre> exit </pre> h3. Install Init Script * 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> pkg install nginx </pre> * 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> 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; keepalive_timeout 65; # 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.example.com.conf </pre> #* And add the following: <pre> upstream gitlab-workhorse { server unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0; } server { listen 80; server_name gitlab.example.com; server_tokens off; root /home/git/gitlab/public; access_log /var/log/gitlab.example.com-access.log; error_log /var/log/gitlab.example.com-error.log; location / { client_max_body_size 0; gzip off; 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; } } </pre> h2. Install GitLab Runner * Download the binary for 64-bit systems: <pre> wget -O /usr/local/bin/gitlab-ci-multi-runner https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-freebsd-amd64 </pre> #* *NOTE*: If the host architecture is 32-bit download the 386 version of the gitlab runner: <pre> wget -O /usr/local/bin/gitlab-ci-multi-runner https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-freebsd-386 </pre> * Give it permissions to execute: <pre> chmod +x /usr/local/bin/gitlab-ci-multi-runner </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 * Then switch to the git user * Finally register the gitlab runner instance: <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