Last active
August 29, 2015 14:07
-
-
Save abn/9eee01775213340fbb3e to your computer and use it in GitHub Desktop.
GitLab CI on Fedora installation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # config | |
| GITLAB_USER=${GITLAB_USER:-gitlab_ci} | |
| GITLAB_HOME=${GITLAB_HOME:-/opt/${GITLAB_USER}} | |
| GITLAB_CODE=${GITLAB_COD:-${GITLAB_HOME}/gitlab-ci} | |
| GITLAB_DATABASE=${GITLAB_DATABASE:-gitlab_ci_production} | |
| GITLAB_REPO=${GITLAB_REPO:-"https://gitlab.com/gitlab-org/gitlab-ci.git"} | |
| GITLAB_BRANCH=${GITLAB_BRANCH:-"master"} | |
| RUNAS_CMD="runuser --login ${GITLAB_USER} --command" | |
| # install deps | |
| yum -y install ruby rubygem-bundler git | |
| adduser \ | |
| --create-home \ | |
| --home-dir ${GITLAB_HOME} \ | |
| --system \ | |
| --comment 'GitLab CI' ${GITLAB_USER} | |
| # fetch source | |
| ${RUNAS_CMD} "git clone ${GITLAB_REPO} ${GITLAB_CODE} \ | |
| && cd ${GITLAB_CODE} \ | |
| && git checkout ${GITLAB_BRANCH}" | |
| # setup application | |
| ${RUNAS_CMD} "cd ${GITLAB_CODE} \ | |
| && cp config/application.yml.example config/application.yml \ | |
| && cp config/unicorn.rb.example config/unicorn.rb \ | |
| && sed -i s='/home/gitlab_ci/gitlab-ci'=${GITLAB_CODE}=g config/unicorn.rb" | |
| ${RUNAS_CMD} "cd ${GITLAB_CODE} \ | |
| && mkdir -p tmp/sockets tmp/pids \ | |
| && find tmp/ -maxdepth 1 -type d -exec chmod -R u+rwX {} \;" | |
| # install gems | |
| yum -y install ruby-devel gcc make automake patch postgresql-devel gcc-c++ | |
| ${RUNAS_CMD} "cd ${GITLAB_CODE} \ | |
| && bundle install --without development test mysql --deployment" | |
| # database setup | |
| yum -y install postgresql-server | |
| postgresql-setup initdb | |
| systemctl enable postgresql | |
| systemctl start postgresql | |
| runuser --login postgres --command "createuser ${GITLAB_USER} \ | |
| && createdb --owner ${GITLAB_USER} gitlab_ci_production \"GitLab CI Database\"" | |
| ${RUNAS_CMD} "cd ${GITLAB_CODE} \ | |
| && cp config/database.yml.postgresql config/database.yml \ | |
| && bundle exec rake setup RAILS_ENV=production \ | |
| && bundle exec whenever -w RAILS_ENV=production" | |
| # setup redis | |
| yum -y install redis | |
| systemctl enable redis | |
| systemctl start redis | |
| # setup nginx | |
| NGINX_AVAILABLE=/etc/nginx/sites-available | |
| NGINX_ENABLED=/etc/nginx/sites-enabled | |
| NGINX_CONF=/etc/nginx/nginx.conf | |
| yum -y install nginx | |
| mkdir -p ${NGINX_AVAILABLE} ${NGINX_ENABLED} | |
| grep "include .*${NGINX_ENABLED}" ${NGINX_CONF} > /dev/null 2>&1 \ | |
| || sed -i s="http {"="http {\n include ${NGINX_ENABLED}/*;"= ${NGINX_CONF} | |
| cp ${GITLAB_CODE}/lib/support/nginx/gitlab_ci ${NGINX_AVAILABLE}/gitlab_ci | |
| ln -s ${NGINX_AVAILABLE}/gitlab_ci ${NGINX_ENABLED}/gitlab_ci | |
| systemctl enable nginx | |
| systemctl start nginx | |
| # init.d script | |
| # TODO: Add service file | |
| cp ${GITLAB_CODE}/lib/support/init.d/gitlab_ci /etc/init.d/gitlab_ci | |
| cat > /etc/default/gitlab-ci << EOF | |
| app_user="${GITLAB_USER}" | |
| app_root="${GITLAB_CODE}" | |
| pid_path="${GITLAB_CODE}/tmp/pids" | |
| socket_path="${GITLAB_CODE}/tmp/sockets" | |
| web_server_pid_path="\${pid_path}/unicorn.pid" | |
| sidekiq_pid_path="\${pid_path}/sidekiq.pid" | |
| EOF | |
| systemctl enable gitlab_ci | |
| # configure gitlab before starting the service | |
| # systemctl start gitlab_ci |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment