持續整合環境Gitlab CI的官方安裝過程解析

來源:互聯網
上載者:User

持續整合環境是一個非常重要的工具,在分工合作的項目中有著舉足輕重的作用。公司最近要用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 updatesudo 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 vimsudo 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-devsudo apt-get install redis-server 
2. Ruby

Download Ruby and compile it:

mkdir /tmp/ruby && cd /tmp/rubycurl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xzcd ruby-1.9.3-p392./configuremakesudo 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 packagessudo apt-get install -y mysql-server mysql-client libmysqlclient-dev# Login to MySQL$ mysql -u root -p# Create the GitLab CI databasemysql> 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 Usermysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlab_ci_production`.* TO 'gitlab_ci'@'localhost';
PostgreSQL
# Install the database packagessudo apt-get install -y postgresql-9.1 libpq-dev# Login to PostgreSQLsudo -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 databasetemplate1=# CREATE DATABASE gitlab_ci_production OWNER gitlab_ci;# Quit the database sessiontemplate1=# \q# Try connecting to the new database with the new usersudo -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.gitcd gitlab-cisudo -u gitlab_ci -H git checkout 3-0-stable
6. Setup application
# Edit application settingssudo -u gitlab_ci -H cp config/application.yml.example config/application.ymlsudo -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: 800test:  <<: *defaults  #allowed_gitlab_urls:     #這個注釋掉  #  - 'http://demo.gitlab.com/'production:  <<: *defaultsallowed_gitlab_urls:   - 'http://earth.bao.ac.cn/gitlab/'#這是你的gitlab的地址
 

 

# Create a sockets directorysudo -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 --deploymentsudo -u gitlab_ci -H bundle --without development test postgres --deployment
Setup db
# mysqlsudo -u gitlab_ci -H cp config/database.yml.mysql config/database.yml# postgressudo -u gitlab_ci -H cp config/database.yml.postgres config/database.yml# Edit user/passwordsudo -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
 

 

 
# Setup tablessudo -u gitlab_ci -H bundle exec rake db:setup RAILS_ENV=production# Setup scedules #sudo -u gitlab_ci -H bundle exec whenever -w RAILS_ENV=production
7. Install Init Script

Download the init script (will be /etc/init.d/gitlab_ci):

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

Make GitLab start on boot:

sudo update-rc.d gitlab_ci defaults 21

Start your GitLab instance:

sudo service gitlab_ci start# orsudo /etc/init.d/gitlab_ci restart
8. NginxInstallation
sudo apt-get install nginx
Site Configuration

Download an example site config:

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

Make sure to edit the config file to match your setup:

# Change **YOUR_SERVER_IP** and **YOUR_SERVER_FQDN**# to the IP address and fully-qualified domain name# of your host serving GitLab CIsudo vim /etc/nginx/sites-enabled/gitlab_ci
#下面是gitlab_ci的例子
 
upstream gitlab_ci {
server unix:/home/gitlab_ci/gitlab-ci/tmp/sockets/gitlab-ci.socket;
}

server {
#設定訪問gitlab_ci的地址
listen 192.168.47.46:9292;
server_name 192.168.47.46;

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 Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Sendfile-Type X-Accel-Redirect;

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;
}
}
 
Restart
sudo /etc/init.d/nginx restart
9. Runners

 

Requirements

The project is designed for the Linux operating system.

We officially support (recent versions of) these Linux distributions:

  • Ubuntu Linux
  • Debian/GNU Linux
Installation
# Get codegit clone https://github.com/gitlabhq/gitlab-ci-runner.git# Enter code dircd gitlab-ci-runner# Install dependencies# a) Linuxsudo apt-get install libicu-dev# b) MacOSx (make sure you have brew installed)sudo brew install icu4cgem install bundlerbundle install# Install runner in interactive modebundle exec ./bin/install# SSH into your GitLab server and confirm to add host key to known_hostsssh git@<your gitlab url>
Run
bundle exec ./bin/runner
Autostart Runners

On linux machines you can have your runners operate like daemons with the following steps

# make sure you install any system dependancies firstadministrator@server:~$ sudo adduser --disabled-login --gecos 'GitLab CI Runner' gitlab_ci_runneradministrator@server:~$ sudo su gitlab_ci_runnergitlab_ci_runner@server:/home/administrator$ cd ~/# perform the setup abovegitlab_ci_runner@server:~$ exit;gitlab_ci_runner@server:/home/gitlab_ci_runner$ sudo cp ./gitlab-ci-runner/lib/support/init.d/gitlab_ci_runner /etc/init.d/gitlab-ci-runnergitlab_ci_runner@server:/home/gitlab_ci_runner$ cd ~administrator@server:~$ sudo chmod +x /etc/init.d/gitlab-ci-runneradministrator@server:~$ sudo update-rc.d gitlab-ci-runner defaults 21 administrator@server:~$ sudo service gitlab-ci-runner start
Done!#這個得注意,這條告訴你用gitlab的密碼來登入gitlab_ci 而不是 什麼admin@local.host

Visit YOUR_SERVER for your first GitLab CI login. You should use your GitLab credentials in orider to login

Enjoy! #說是enjoy,我一開始還是沒有明白。我搞了半天都沒發現如何啟動一次構建。後來發現你需要到gitlab中找到你要構建的項目,在其settings中的service中啟用你構建。這需要你填寫你的gitlab_ci的對應的項目中的integration的相關項目。 好吧現在你可以Enjoy 了如果你還是沒有Enjoy,請以Enjoy為主題評論

GitLab 的詳細介紹:請點這裡
GitLab 的:請點這裡

GitLab 5.3 升級注意事項

在 CentOS 上部署 GitLab (自託管的Git項目倉庫)

Gitlab在Ubuntu 12.04.2上面的安裝配置教程

Gitlab 6.3 社區版發布

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.