Support #596
Updated by Daniel Curtis over 9 years ago
This is a guide for installing GitLab CI on FreeBSD 9.3. h2. Setting up the Environment * Start by making sure everything is up to date: <pre> pkg update && pkg upgrade portsnap fetch extract </pre> * Install portmaster: <pre> cd /usr/ports/ports-mgmt/portmaster make install clean pkg2ng </pre> * Install a few dependencies: <pre> portmaster sysutils/rubygem-bundler ftp/wget ftp/curl textproc/libxml2 textproc/libxslt databases/redis devel/icu devel/readline devel/git textproc/libyaml </pre> * Install the libv8 gem system-wide: <pre> gem install libv8 </pre> * Add the GitLab CI user <pre> pw add user -n gitlab_ci -m -s /usr/local/bin/bash -c "GitLab CI" </pre> h2. Install MariaDB 5.5 * This environment will be setup with MariaDB 5.5 for its MySQL server: <pre> portmaster databases/mariadb55-server databases/mariadb55-client </pre> #* Ensure you have MySQL version 5.5.14 or later <pre> mysql --version </pre> * Start and enable MySQL at boot: <pre> echo 'mysql_enable="YES"' >> /etc/rc.conf service mysql-server start </pre> * Secure your installation: <pre> mysql_secure_installation </pre> * Login to MySQL <pre> mysql -u root -p </pre> #* Create a user for GitLab CI <pre> CREATE USER 'gitlab_ci'@'localhost' IDENTIFIED BY 'SuperSecretPassword'; </pre> *NOTE*: Change SuperSecretPassword to what ever password desired #* Ensure you can use the InnoDB engine which is necessary to support long indexes. <pre> SET storage_engine=INNODB; </pre> *NOTE*: If this fails, check your MySQL config files (e.g. `/etc/mysql/*.cnf`, `/etc/mysql/conf.d/*`) for the setting "innodb = off" #* Create the GitLab CI production database <pre> CREATE DATABASE IF NOT EXISTS `gitlab_ci_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; </pre> #* Grant the GitLab user necessary permissions on the table. <pre> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlab_ci_production`.* TO 'gitlab_ci'@'localhost'; </pre> #* Quit the database session <pre> quit </pre> * Try connecting to the new database with the new user <pre> mysql sudo -h localhost -u gitlab_ci -p -D gitlab_ci_production </pre> * You should now see a mysql> prompt, quit the database session: <pre> quit </pre> h2. Install GitLab CI * Switch to the GitLab CI user: <pre> su - gitlab_ci </pre> * Download GitLab CI: <pre> git clone https://github.com/gitlabhq/gitlab-ci.git </pre> * Checkout the latest stable 2.2 version <pre> cd gitlab-ci git checkout 2-2-stable </pre> * Create a tmp and sockets directory inside application <pre> mkdir -p tmp/pids mkdir tmp/sockets </pre> * Install dependencies <pre> bundle --without development test postgresql --path vendor/bundle </pre> #* *NOTE*: Installation with bundle will most likely fail the first time through,, just run the following to fix: <pre> bundle update </pre> * Create the mysql db config <pre> cp config/database.yml.mysql config/database.yml </pre> * Setup the database <pre> bundle exec rake db:setup RAILS_ENV=production </pre> * Setup scedules <pre> bundle exec whenever -w RAILS_ENV=production </pre> * Now exit from gitlab_ci user <pre> exit </pre> h3. GitLab CI rc.d script * Create the gitlab-ci rc script: <pre> vi /usr/local/etc/rc.d/gitlab-ci </pre> #* And add the following: <pre> #! /usr/local/bin/bash # GITLAB CI # Maintainer: @randx # App Version: 2.2 ### BEGIN INIT INFO # Provides: gitlab-ci # Required-Start: $local_fs $remote_fs $network $syslog redis-server # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: GitLab CI # Description: GitLab CI ### END INIT INFO APP_ROOT="/usr/home/gitlab_ci/gitlab-ci" DAEMON_OPTS="-C $APP_ROOT/config/puma.rb -e production" PID_PATH="$APP_ROOT/tmp/pids" WEB_SERVER_PID="$PID_PATH/puma.pid" SIDEKIQ_PID="$PID_PATH/sidekiq.pid" STOP_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:stop" START_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:start" NAME="GitLab CI" DESC="Gitlab CI service" check_pid(){ if [ -f $WEB_SERVER_PID ]; then PID=`cat $WEB_SERVER_PID` SPID=`cat $SIDEKIQ_PID` STATUS=`ps aux | grep $PID | grep -v grep | wc -l` else STATUS=0 PID=0 fi } start() { cd $APP_ROOT check_pid if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then # Program is running, exit with error code 1. echo "Error! $DESC is currently running!" exit 1 else if [ `whoami` = root ]; then sudo -u gitlab_ci -H bash -l -c "RAILS_ENV=production bundle exec puma $DAEMON_OPTS" sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &" echo "$DESC started" fi fi } stop() { cd $APP_ROOT check_pid if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then ## Program is running, stop it. kill -QUIT `cat $WEB_SERVER_PID` sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &" rm "$WEB_SERVER_PID" >> /dev/null echo "$DESC stopped" else ## Program is not running, exit with error. echo "Error! $DESC not started!" exit 1 fi } restart() { cd $APP_ROOT check_pid if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then echo "Restarting $DESC..." kill -USR2 `cat $WEB_SERVER_PID` sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &" if [ `whoami` = root ]; then sudo -u gitlab_ci -H bash -l -c "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &" fi echo "$DESC restarted." else echo "Error, $NAME not running!" exit 1 fi } status() { cd $APP_ROOT check_pid if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then echo "$DESC / Unicorn with PID $PID is running." echo "$DESC / Sidekiq with PID $SPID is running." else echo "$DESC is not running." exit 1 fi } ## Check to see if we are running as root first. ## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" exit 1 fi case "$1" in start) start ;; stop) stop ;; restart) restart ;; reload|force-reload) echo -n "Reloading $NAME configuration: " kill -HUP `cat $PID` echo "done." ;; status) status ;; *) echo "Usage: sudo service gitlab {start|stop|restart|reload}" >&2 exit 1 ;; esac exit 0 </pre> * Make the script executable: <pre> chmod +x /usr/local/etc/rc.d/gitlab-ci </pre> h2. Nginx * Install nginx: <pre> portmaster www/nginx </pre> * Start and enable nginx at boot: <pre> echo 'nginx_enable="YES"' >> /etc/rc.conf service nginx start </pre> * Edit the nginx configuration file: <pre> vi /usr/local/etc/nginx/nginx.conf </pre> #* And add the following inside the http block: <pre> upstream gitlab_ci { server unix:/home/gitlab_ci/gitlab-ci/tmp/sockets/gitlab-ci.socket; } server { listen 80 default_server; server_name ci.example.com; root /home/gitlab_ci/gitlab-ci/public; access_log /var/log/nginx/gitlab_ci_access.log; error_log /var/log/nginx/gitlab_ci_error.log; location / { try_files $uri $uri/index.html $uri.html @gitlab_ci; } location @gitlab_ci { proxy_read_timeout 300; proxy_connect_timeout 300; proxy_redirect off; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://gitlab_ci; } } </pre> h2. Login Visit http://ci.example.com for your first GitLab CI login. The setup has created an admin account for you. You can use it to log in: * admin@local.host * 5iveL!fe h2. Resources * https://github.com/Philzen/gitlab-ci-recipes/blob/master/freebsd/install.md * https://github.com/gitlabhq/gitlab-ci/blob/2-2-stable/doc/installation.md * https://raw.githubusercontent.com/gitlabhq/gitlab-ci/2-2-stable/lib/support/nginx/gitlab_ci * https://github.com/Philzen/gitlab-ci-recipes/blob/master/freebsd/rc.d-2.2.sh