您的位置:首页 > 其它

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

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

Requirements:

GitLab5.3+

Setup:

1.Packages/Dependencies

sudo
isnotinstalledonDebianbydefault.Makesureyoursystemisup-to-dateandinstallit.

sudoapt-getupdate
sudoapt-getupgrade

Note:Vimisaneditorthatisusedherewhenevertherearefilesthatneedtobeeditedbyhand.But,youcanuseanyeditoryoulikeinstead.

#Installvim
sudoapt-getinstall-yvim

Installtherequiredpackages:

sudoapt-getinstall-ywgetcurlgcccheckinstalllibxml2-devlibxslt-devlibcurl4-openssl-devlibreadline6-devlibc6-devlibssl-devlibmysql++-devmakebuild-essentialzlib1g-devopenssh-servergit-corelibyaml-devpostfixlibpq-devlibicu-dev
sudoapt-getinstallredis-server

2.Ruby

DownloadRubyandcompileit:

mkdir/tmp/ruby&&cd/tmp/ruby
curl--progresshttp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz|tarxz
cdruby-1.9.3-p392
./configure
make
sudomakeinstall

InstalltheBundlerGem:

sudogeminstallbundler--no-ri--no-rdoc

3.Preparethedatabase

YoucanuseeitherMySQLorPostgreSQL.

MySQL

#Installthedatabasepackages
sudoapt-getinstall-ymysql-servermysql-clientlibmysqlclient-dev

#LogintoMySQL
$mysql-uroot-p

#CreatetheGitLabCIdatabase
mysql>CREATEDATABASEIFNOTEXISTS`gitlab_ci_production`DEFAULTCHARACTERSET`utf8`COLLATE`utf8_unicode_ci`;

#CreatetheMySQLUserchange$passwordtoarealpassword这里的
$password密码需要替换为你希望的密码[/code]
mysql>CREATEUSER'gitlab_ci'@'localhost'IDENTIFIEDBY'$password';

#GrantproperpermissionstotheMySQLUser
mysql>GRANTSELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTERON`gitlab_ci_production`.*TO'gitlab_ci'@'localhost';

PostgreSQL

#Installthedatabasepackages
sudoapt-getinstall-ypostgresql-9.1libpq-dev

#LogintoPostgreSQL
sudo-upostgrespsql-dtemplate1

#CreateauserforGitLab.(change$passwordtoarealpassword)这里的
$password密码需要替换为你希望的密码

template1=#CREATEUSERgitlab_ciWITHPASSWORD'$password';
#CreatetheGitLabproductiondatabase&grantallprivilegesondatabase
template1=#CREATEDATABASEgitlab_ci_productionOWNERgitlab_ci;

#Quitthedatabasesession
template1=#\q

#Tryconnectingtothenewdatabasewiththenewuser
sudo-ugit-Hpsql-dgitlab_ci_production

4.GitLabCIuser:

sudoadduser--disabled-login--gecos'GitLabCI'gitlab_ci

5.Getcode

cd/home/gitlab_ci/

sudo-ugitlab_ci-Hgitclonehttps://github.com/gitlabhq/gitlab-ci.git
cdgitlab-ci

sudo-ugitlab_ci-Hgitcheckout3-0-stable

6.Setupapplication

#Editapplicationsettings
sudo-ugitlab_ci-Hcpconfig/application.yml.exampleconfig/application.yml
sudo-ugitlab_ci-Hvimconfig/application.yml
#下边是application.yml的例子
defaults:&defaults
[/code]

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的地址


#Createasocketsdirectory
sudo-ugitlab_ci-Hmkdir-ptmp/sockets/
sudochmod-Ru+rwXtmp/sockets/

Installgems

sudo-ugitlab_ci-Hbundle--withoutdevelopmenttestpostgres--deployment
sudo-ugitlab_ci-Hbundle--withoutdevelopmenttestpostgres--deployment

Setupdb

#mysql
sudo-ugitlab_ci-Hcpconfig/database.yml.mysqlconfig/database.yml

#postgres
sudo-ugitlab_ci-Hcpconfig/database.yml.postgresconfig/database.yml

#Edituser/password
sudo-ugitlab_ci-Hvimconfig/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

#
#Developmentspecific
#
development:
adapter:mysql2
encoding:utf8
reconnect:false
database:gitlab_ci_development
pool:5
username:debian-sys-maint
password:"r0VpzdDxG33ruj0m"
#socket:/tmp/mysql.sock

#Warning:Thedatabasedefinedas"test"willbeerasedand
#re-generatedfromyourdevelopmentdatabasewhenyourun"rake".
#Donotsetthisdbtothesameasdevelopmentorproduction.
test:&test
adapter:mysql2
encoding:utf8
reconnect:false
database:gitlab_ci_test
pool:5
username:debian-sys-maint
password:"r0VpzdDxG33ruj0m"
#socket:/tmp/mysql.sock




#Setuptables
sudo-ugitlab_ci-Hbundleexecrakedb:setupRAILS_ENV=production

#Setupscedules
#
sudo-ugitlab_ci-Hbundleexecwhenever-wRAILS_ENV=production

7.InstallInitScript

Downloadtheinitscript(willbe/etc/init.d/gitlab_ci):

sudowgethttps://raw.github.com/gitlabhq/gitlab-ci/master/lib/support/init.d/gitlab_ci-P/etc/init.d/
sudochmod+x/etc/init.d/gitlab_ci

MakeGitLabstartonboot:

sudoupdate-rc.dgitlab_cidefaults21

StartyourGitLabinstance:

sudoservicegitlab_cistart
#or
sudo/etc/init.d/gitlab_cirestart

8.Nginx

Installation

sudoapt-getinstallnginx

SiteConfiguration

Downloadanexamplesiteconfig:

sudowgethttps://raw.github.com/gitlabhq/gitlab-ci/master/lib/support/nginx/gitlab_ci-P/etc/nginx/sites-available/
sudoln-s/etc/nginx/sites-available/gitlab_ci/etc/nginx/sites-enabled/gitlab_ci

Makesuretoedittheconfigfiletomatchyoursetup:

#Change**YOUR_SERVER_IP**and**YOUR_SERVER_FQDN**
#totheIPaddressandfully-qualifieddomainname
#ofyourhostservingGitLabCI
sudovim/etc/nginx/sites-enabled/gitlab_ci

#下面是gitlab_ci的例子


upstreamgitlab_ci{
serverunix:/home/gitlab_ci/gitlab-ci/tmp/sockets/gitlab-ci.socket;
}

server{

#设置访问gitlab_ci的地址

listen192.168.47.46:9292;

server_name192.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_timeout300;

proxy_connect_timeout300;

proxy_redirectoff;

proxy_set_headerHost$host:$server_port;

proxy_set_headerX-Real-IP$remote_addr;

proxy_set_headerX-Sendfile-TypeX-Accel-Redirect;

proxy_set_headerX-Forwarded-Proto$scheme;

proxy_set_headerHost$http_host;

proxy_set_headerX-Real-IP$remote_addr;

proxy_passhttp://gitlab_ci;
}

}



Restart

sudo/etc/init.d/nginxrestart

9.Runners

Requirements

TheprojectisdesignedfortheLinuxoperatingsystem.

Weofficiallysupport(recentversionsof)theseLinuxdistributions:

UbuntuLinux

Debian/GNULinux

Installation

#Getcode
gitclonehttps://github.com/gitlabhq/gitlab-ci-runner.git
#Entercodedircdgitlab-ci-runner

#Installdependencies

#a)Linux
sudoapt-getinstalllibicu-dev

#b)MacOSx(makesureyouhavebrewinstalled)
sudobrewinstallicu4c

geminstallbundler
bundleinstall

#Installrunnerininteractivemode
bundleexec./bin/install

#SSHintoyourGitLabserverandconfirmtoaddhostkeytoknown_hosts
sshgit@<yourgitlaburl>


Run

bundleexec./bin/runner


AutostartRunners

Onlinuxmachinesyoucanhaveyourrunnersoperatelikedaemonswiththefollowingsteps

#makesureyouinstallanysystemdependanciesfirst

administrator@server:~$sudoadduser--disabled-login--gecos'GitLabCIRunner'gitlab_ci_runner
administrator@server:~$sudosugitlab_ci_runner
gitlab_ci_runner@server:/home/administrator$cd~/

#performthesetupabove

gitlab_ci_runner@server:~$exit;
gitlab_ci_runner@server:/home/gitlab_ci_runner$sudocp./gitlab-ci-runner/lib/support/init.d/gitlab_ci_runner/etc/init.d/gitlab-ci-runner
gitlab_ci_runner@server:/home/gitlab_ci_runner$cd~
administrator@server:~$sudochmod+x/etc/init.d/gitlab-ci-runner
administrator@server:~$sudoupdate-rc.dgitlab-ci-runnerdefaults21
administrator@server:~$sudoservicegitlab-ci-runnerstart

Done!

#这个得注意,这条告诉你用gitlab的密码来登录gitlab_ci而不是什么admin@local.host
VisitYOUR_SERVERforyourfirstGitLabCIlogin.YoushoulduseyourGitLabcredentialsinoridertologin

Enjoy!

#说是enjoy,我一开始还是没有明白。我搞了半天都没发现如何启动一次构建。后来发现你需要到gitlab中找到你要构建的项目,在其settings中的service中激活你构建。这需要你填写你的gitlab_ci的对应的项目中的integration的相关项。

好吧现在你可以Enjoy了
如果你还是没有Enjoy,请以Enjoy为主题评论
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: