持续集成环境Gitlab CI的官方安装过程解析

持续集成环境是一个非常重要的工具,在分工合作的项目中有着举足轻重的作用。公司最近要用Gitlab,需要配套的持续集成环境。研究了官方的文档,感觉官方的文档不是很明了。各种修改过后终于成功了。为了大家安装时不再重蹈覆辙,特写这篇博客。博客内容大部分都是官方文档的内容,我仅仅是在一些容易失误的地方做了写解释。官方文档可能会不时更新。但这些注意的点应该变化不是很大。官方安装文档网址:https://github.com/gitlabhq/gitlab-ci/wiki 进入后点击相应的版本。

Requirements:

GitLab 5.3+

Setup: 1. Packages / Dependencies

sudo is not installed on Debian by default. Make sure your system is up-to-date and install it.

sudo apt-get update sudo apt-get upgrade

Note: Vim is an editor that is used here whenever there are files that need to be edited by hand. But, you can use any editor you like instead.

# Install vim sudo apt-get install -y vim

Install the required packages:

sudo apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev openssh-server git-core libyaml-dev postfix libpq-dev libicu-dev sudo apt-get install redis-server 2. Ruby

Download Ruby and compile it:

mkdir /tmp/ruby && cd /tmp/ruby curl --progress | tar xz cd ruby-1.9.3-p392 ./configure make sudo make install

Install the Bundler Gem:

sudo gem install bundler --no-ri --no-rdoc 3. Prepare the database

You can use either MySQL or PostgreSQL.

MySQL # Install the database packages sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev # Login to MySQL $ mysql -u root -p # Create the GitLab CI database mysql> CREATE DATABASE IF NOT EXISTS `gitlab_ci_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; # Create the MySQL User change $password to a real password 这里的 $password密码需要替换为你希望的密码 mysql> CREATE USER 'gitlab_ci'@'localhost' IDENTIFIED BY '$password'; # Grant proper permissions to the MySQL User mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlab_ci_production`.* TO 'gitlab_ci'@'localhost'; PostgreSQL # Install the database packages sudo apt-get install -y postgresql-9.1 libpq-dev # Login to PostgreSQL sudo -u postgres psql -d template1 # Create a user for GitLab. (change $password to a real password) 这里的 $password密码需要替换为你希望的密码
template1=# CREATE USER gitlab_ci WITH PASSWORD '$password'; # Create the GitLab production database & grant all privileges on database template1=# CREATE DATABASE gitlab_ci_production OWNER gitlab_ci; # Quit the database session template1=# \q # Try connecting to the new database with the new user sudo -u git -H psql -d gitlab_ci_production 4. GitLab CI user: sudo adduser --disabled-login --gecos 'GitLab CI' gitlab_ci 5. Get code cd /home/gitlab_ci/ sudo -u gitlab_ci -H git clone https://github.com/gitlabhq/gitlab-ci.git cd gitlab-ci sudo -u gitlab_ci -H git checkout 3-0-stable 6. Setup application # Edit application settings sudo -u gitlab_ci -H cp config/application.yml.example config/application.yml sudo -u gitlab_ci -H vim config/application.yml #下边是application.yml的例子defaults: &defaults

 

allowed_gitlab_urls: - 'http://earth.bao.ac.cn/gitlab/' #这是你的gitlab的地址 #- 'https://dev.gitlab.org/' #这两个注释掉 #- 'https://staging.gitlab.org/' development: <<: *defaults neat_setting: 800 test: <<: *defaults #allowed_gitlab_urls: #这个注释掉 # - 'http://demo.gitlab.com/' production: <<: *defaults allowed_gitlab_urls: - 'http://earth.bao.ac.cn/gitlab/'#这是你的gitlab的地址

 

# Create a sockets directory sudo -u gitlab_ci -H mkdir -p tmp/sockets/ sudo chmod -R u+rwX tmp/sockets/ Install gems sudo -u gitlab_ci -H bundle --without development test postgres --deployment sudo -u gitlab_ci -H bundle --without development test postgres --deployment Setup db # mysql sudo -u gitlab_ci -H cp config/database.yml.mysql config/database.yml # postgres sudo -u gitlab_ci -H cp config/database.yml.postgres config/database.yml # Edit user/password sudo -u gitlab_ci -H vim config/database.yml 以下是database.yml例子

 

# # PRODUCTION # production: adapter: mysql2 encoding: utf8 reconnect: false database: gitlab_ci_production pool: 5 username: gitlab_ci password: "travelchallenge" #这里设置你的先前设置的gilab_ci的密码 # host: localhost # socket: /tmp/mysql.sock # # Development specific # development: adapter: mysql2 encoding: utf8 reconnect: false database: gitlab_ci_development pool: 5 username: debian-sys-maint password: "r0VpzdDxG33ruj0m" # socket: /tmp/mysql.sock # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: &test adapter: mysql2 encoding: utf8 reconnect: false database: gitlab_ci_test pool: 5 username: debian-sys-maint password: "r0VpzdDxG33ruj0m" # socket: /tmp/mysql.sock

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/18939.html