Skip to content

Instantly share code, notes, and snippets.

@ryosms
Created January 29, 2013 07:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryosms/4662565 to your computer and use it in GitHub Desktop.
Save ryosms/4662565 to your computer and use it in GitHub Desktop.
さくらのVPSにUbuntu12.04を突っ込んでGitLab 4.1を入れたサーバーでGitLab CI 2.0を同居させる手順

0. 前提条件

  • サーバー:Ubunt 12.04(on さくらのVPS)
  • GitLab 4.1インストール済み
    • Ruby、mySQL、Nginxはインストール済み
  • 詳しくは GitLab4.1のインストール手順 見れ

1. GitLab-CI用ユーザーの作成

$ sudo adduser --disabled-login --gecos 'GitLab CI' gitlab_ci

2. 必要なパッケージのインストール

※GitLab4.1インストール時にインストールしてないパッケージを入れる

$ sudo apt-get update  
$ sudo apt-get upgrade  
  
$ sudo apt-get install -y libc6-dev libmysql++-dev libpq-dev  

3. mySQLの設定

  • mySQLにログイン
$ mysql -u root -p
  • GitLab CI用のデータベース/ユーザーを作成し、権限を設定する
mysql> CREATE DATABASE IF NOT EXISTS `gitlab_ci_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;  
mysql> CREATE USER 'gitlab_ci'@'localhost' IDENTIFIED BY '$password';  
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlab_ci_production`.* TO 'gitlab_ci'@'localhost';  

4. GitLab CIのインストール

  • gitlab_ciのホームディレクトリで作業する
$ cd /home/gitlab_ci/
  • GitLab CIのソースクローンして2-0-stableをチェックアウトする
$ sudo -u gitlab_ci -H git clone https://github.com/gitlabhq/gitlab-ci.git  
$ cd gitlab_ci  
$ sudo -u gitlab_ci -H  git checkout 2-0-stable  
  • テンポラリディレクトリを作成する
$ sudo -u gitlab_ci -H mkdir -p tmp/pids
  • 依存ファイルをインストールする
$ bundle --without development test

installation.md の「2. Install Ruby (RVM) for gitlab_ci」でgitlab_ciユーザー用のRVMをセットアップしている場合はsudo -u gitlab_ci -H bundle … でOK

  • mySQLの設定ファイルをコピーして編集する
$ sudo -u gitlab_ci -H cp config/database.yml.mysql config/database.yml  
$ sudo -u gitlab_ci -H vi config/database.yml  

※ユーザー名、パスワードを変更する

  • DBをセットアップする
$ sudo -u gitlab_ci -H bundle exec rake db:setup RAILS_ENV=production
  • スケジュールをセットアップする
$ sudo -u gitlab_ci -H bundle exec whenever -w RAILS_ENV=production
  • Init用スクリプトの作成
$ sudo wget https://raw.github.com/gitlabhq/gitlab-ci/master/lib/support/init.d/gitlab_ci -P /etc/init.d/  
$ sudo chmod +x /etc/init.d/gitlab_ci  
$ sudo update-rc.d gitlab_ci defaults 21  
  • GitLab CIの起動
$ sudo service gitlab_ci start  

もしくは

$ sudo /etc/init.d/gitlab_ci restart  

5. Nginxの設定

  • 設定ファイルを作成する
$ sudo wget https://raw.github.com/gitlabhq/gitlab-ci/master/lib/support/nginx/gitlab_ci -P /etc/nginx/sites-available/  
$ sudo ln -s /etc/nginx/sites-available/gitlab_ci /etc/nginx/sites-enabled/gitlab_ci  
$ sudo vi /etc/nginx/sites-enabled/gitlab_ci
* サーバーのIP、ポート番号、サーバー名を変更する  
ー `listen 80 default_server;`  
+ `listen xxx.xxx.xxx.xxx:NNNN default_server;`  
ー `server_name ci.gitlab.org;`  
+ `server_name your.server.name:NNNN`  
※ GitLabとポート番号がバッティングしないようにNNNNにポート番号を指定する  
  • Nginxを再起動する
$ sudo /etc/init.d/nginx restart

6. 確認

  • ブラウザでアクセスしてみて表示されることを確認する。
  • 初期Adminのユーザー名/パスワードは(GitLabとも)共通なので、パスワードは変更すること!
  • もしくは、新規Adminユーザーを作成して、初期Adminは削除する

参考URL

GitLab-CI/doc/installation.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment