gitlab-runner安装、升级

参考官网:
gitlab-runer装起来

Gitlab Runner可以安装在以下系统中:GNU/Linux,macOS,FreeBSD和Windows。此处介绍下linux三种安装方式:使用Docker安装,下载二进制运行文件手动安装,或者使用rpm/deb/apt之类的包管理工具。接下来我们将介绍其对应的安装方法,图示例运行在Ubuntu16.04

gitlab-runner安装、升级与配置

    • Docker容器运行GitLab Runner
            • GitLab Runner Docker模式常规用法
            • Docker镜像安装和配置
            • 升级
    • 手动方式GitLab Runner
            • 安装
            • 升级
    • apt-get方式GitLab Runner
            • 安装
            • 升级

Docker容器运行GitLab Runner


本章讲解如何在Docker容器中运行 GitLab Runner

  • GitLab Runner Docker模式常规用法

假设GitLab Runner Docker镜像已经启动。
通常情况下,所有GitLab Runner命令的执行方式如下:

gitlab-runner [Runner相关的指令或者选项参数]

在Docker模式的GitLab,执行方式如下

docker exec [选择指定docker镜像选项参数] [镜像名] gitlab-runner [Runner相关的指令或者选项参数]

例如,对于已经启动的GitLab Runner镜像,使用GitLab Runner指令,获取顶级帮助信息,执行方式如下:

sudo docker exec -it gitlab-runner gitlab-runner --help

NAME:
   gitlab-runner - a GitLab Runner

USAGE:
   gitlab-runner [global options] command [command options] [arguments...]

VERSION:
   11.5.1 (7f00c780)

(...)

简而言之,在gitlab-runner命令前面添加 docker run [docker options] gitlab-runner,即可生成Docker版本的命令,其中gitlab-runner为镜像名称。唯一的区别就是Docker版本的gitlab-runner指令是执行在Docker容器里的。

  • Docker镜像安装和配置
  1. 首先安装Docker:
 curl -sSL https://get.docker.com/ | sh

gitlab-runner安装、升级_第1张图片

  1. 您需要将配置和其他资源的volume挂载出来,启动Docker镜像:
 docker run -d --name gitlab-runner --restart always \
   -v /srv/gitlab-runner/config:/etc/gitlab-runner \
   -v /var/run/docker.sock:/var/run/docker.sock \
   gitlab/gitlab-runner:latest
  1. 注册Runner,绑定gitlab代码分支和gitlab-runner
  • 升级
  1. 拉取最新版本gitlab/gitlab-runner
docker pull gitlab/gitlab-runner:latest
  1. 停止并移除旧版本的容器
docker stop gitlab-runner && docker rm gitlab-runner
  1. 重新安装并启动gitlab-runner:latest
 docker run -d --name gitlab-runner --restart always \
   -v /srv/gitlab-runner/config:/etc/gitlab-runner \
   -v /var/run/docker.sock:/var/run/docker.sock \
   gitlab/gitlab-runner:latest

手动方式GitLab Runner


  • 安装
  1. 下载对应平台的二进制运行文件,并保存命名到/usr/local/bin/gitlab-runner:
 # Linux x86-64
 sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

 # Linux x86
 sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386

 # Linux arm
 sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm

gitlab-runner安装、升级_第2张图片

  1. 设置可执行权限:
 sudo chmod +x /usr/local/bin/gitlab-runner

Ubuntu16.04操作示例

  1. 可选,如果您想使用Docker Runner,则需要安装Docker
  2. 创建GitLab CI用户:
 sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

gitlab-runner安装、升级_第3张图片

  1. 安装并且启动服务:
 sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
 sudo gitlab-runner start

Ubuntu16.04操作示例
6. 注册Runner,绑定gitlab代码分支和gitlab-runner

  • 升级
  1. 停止gitlab-runner服务
  sudo gitlab-runner stop
  1. 下载二进制运行文件
 sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386
 sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
  1. 设置可执行权限
   sudo chmod +x /usr/local/bin/gitlab-runner
  1. 启动gitlab-runner服务
 sudo gitlab-runner start

apt-get方式GitLab Runner


  • 安装
  1. 添加GitLab官方仓库:
 # For Debian/Ubuntu/Mint
 curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash

 # For RHEL/CentOS/Fedora
 curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash

gitlab-runner安装、升级_第4张图片

  1. 安装最新版本的GitLab Runner,或者跳到下一步骤安装指定版本:
 # For Debian/Ubuntu/Mint
 sudo apt-get install gitlab-runner

 # For RHEL/CentOS/Fedora
 sudo yum install gitlab-runner

gitlab-runner安装、升级_第5张图片

  1. 安装指定版本的GitLabRunner(11.6.0)
 # for DEB based systems
 apt-cache madison gitlab-runner
 sudo apt-get install gitlab-runner=11.6.0

 # for RPM based systems
 yum list gitlab-runner --showduplicates | sort -r
 sudo yum install gitlab-runner-10.0.0-1
  1. 注册Runner,绑定gitlab代码分支和gitlab-runner
  • 升级

确保已经添加GitLab官方仓库,升级操作很简单:

# For Debian/Ubuntu/Mint
sudo apt-get update
sudo apt-get install gitlab-runner

# For RHEL/CentOS/Fedora
sudo yum update
sudo yum install gitlab-runner

你可能感兴趣的:(gitlab,gitlab-ci)