安装 Gitlab CI runner

红薯 发布于 2015/01/03 12:40
阅读 10K+
收藏 3

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

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

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 解释器

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 安装

sudo gem install bundler

GitLab CI runner 用户创建

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

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

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 的权限:

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

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

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

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

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

docker commit b504ab6ba122 gitlab-runner

用来负责多个 runner:

$ 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 上安装很简单:

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
加载中
返回顶部
顶部