bananarlily / IT / 安装 Gitlab CI runner

分享

   

安装 Gitlab CI runner

2016-11-04  bananarli...

前面我们已经安装好 Gitlab CI 了。接下来安装 Gitlab CI runner。

Gitlab CI runner 安装指南 适配 Ubuntu 14.04 版本,用于连接到 GitLab CI 并在提交推送到分支时自动运行构建任务。推荐的包基于 ruby 2.0 ,除了 postfix 以外。

1
2
3
4
5
6
sudo apt-get update -y
sudo apt-get install -y wget curl gcc libxml2-dev libxslt-dev \
   libcurl4-openssl-dev libreadline6-dev libc6-dev \
   libssl-dev make build-essential zlib1g-dev openssh-server \
   git-core libyaml-dev libpq-dev libicu-dev \
   ruby2.0 ruby2.0-dev

Ruby2.0 是 默认的 Ruby 解释器

1
2
3
4
5
6
7
8
sudo rm /usr/bin/ruby /usr/bin/gem /usr/bin/irb /usr/bin/rdoc /usr/bin/erb
sudo ln -s /usr/bin/ruby2.0 /usr/bin/ruby
sudo ln -s /usr/bin/gem2.0 /usr/bin/gem
sudo ln -s /usr/bin/irb2.0 /usr/bin/irb
sudo ln -s /usr/bin/rdoc2.0 /usr/bin/rdoc
sudo ln -s /usr/bin/erb2.0 /usr/bin/erb
sudo gem update --system
sudo gem pristine --all

bundler gem 安装

1
sudo gem install bundler

GitLab CI runner 用户创建

1
sudo adduser --disabled-login --gecos 'GitLab CI Runner' gitlab_ci_runner

GitLab CI runner 代码安装在对应用户的主目录:

1
2
3
4
5
sudo su gitlab_ci_runner
cd ~/
git clone https://gitlab.com/gitlab-org/gitlab-ci-runner.git
cd gitlab-ci-runner
bundle install --deployment

CI 令牌从 Gitlab CI 的面板中获取

用于访问 runner 的权限:

1
2
CI_SERVER_URL=http://workbench.dachary.org:8080 \
  REGISTRATION_TOKEN=778b1d4856f26da392a bundle exec ./bin/setup

使用 root 账号来启动守护进程:

1
su gitlab_ci_runner -c 'cd $HOME/gitlab-ci-runner ; bundle exec ./bin/runner'

GitLab CI 界面显示 runner 已经注册:

假设上述步骤已经在 Docker 容器中完成,可通过如下命令持久化到映像:

1
docker commit b504ab6ba122 gitlab-runner

用来负责多个 runner:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ docker run --rm -t gitlab-runner \
  su gitlab_ci_runner -c  'cd $HOME/gitlab-ci-runner ; \
  CI_SERVER_URL=http://workbench.dachary.org:8080 \
  REGISTRATION_TOKEN=b14852619da392a \
  bundle exec ./bin/setup ; bundle exec ./bin/runner'
Registering runner with registration token: 2619da3, url: http://workbench.dachary.org:8080.
Runner token: 35f9d40f2e072487870f987
Runner registered successfully. Feel free to start it!
* Gitlab CI Runner started
* Waiting for builds
2014-12-06 17:18:26 +0000 | Checking for builds...nothing
2014-12-06 17:20:27 +0000 | Checking for builds...received
2014-12-06 17:20:27 +0000 | Starting new build 6...
2014-12-06 17:20:27 +0000 | Build 6 started.
2014-12-06 17:20:32 +0000 | Submitting build 6 to coordinator...ok
2014-12-06 17:20:33 +0000 | Completed build 6, success.
2014-12-06 17:20:33 +0000 | Submitting build 6 to coordinator...aborted
2014-12-06 17:20:38 +0000 | Checking for builds...nothing
...

当容器停止时,runner 必须手工从 Gitlab CI 中移除。Gitlab CI 中的项目会因为在 runner 中消失而冲突,因此必须移除并重新添加,否则就没有作业被重新调度。

在 Fedora 20 上安装很简单:

1
2
3
4
5
6
7
8
9
10
sudo gem install bundler
sudo useradd -c 'GitLab CI Runner' gitlab_ci_runner
export PATH=/usr/local/bin:$PATH
cd ~/
git clone https://gitlab.com/gitlab-org/gitlab-ci-runner.git
cd gitlab-ci-runner
bundle install --deployment
CI_SERVER_URL=http://workbench.dachary.org:8080 \
  REGISTRATION_TOKEN=XXXXX bundle exec ./bin/setup
via dachary

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多
    喜欢该文的人也喜欢 更多

    ×
    ×

    ¥.00

    微信或支付宝扫码支付:

    开通即同意《个图VIP服务协议》

    全部>>