在 FreeBSD 上安装极狐GitLab Runner

noteFreeBSD 版本同样也是一次前沿发布。请阅读 FAQ,它介绍了您在使用极狐GitLab Runner 时最可能遇到的问题。
caution如果您正在使用或升级极狐GitLab Runner 10 之前的版本,请阅读如何升级到新版本

安装极狐GitLab Runner

以下是在 FreeBSD 下安装和配置极狐GitLab Runner 的步骤:

  1. 创建 gitlab-runner 用户和组:

    sudo pw group add -n gitlab-runner
    sudo pw user add -n gitlab-runner -g gitlab-runner -s /usr/local/bin/bash
    sudo mkdir /home/gitlab-runner
    sudo chown gitlab-runner:gitlab-runner /home/gitlab-runner
    
  2. 为您的系统下载二进制文件:

    # For amd64
    sudo fetch -o /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-freebsd-amd64
    
    # For i386
    sudo fetch -o /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-freebsd-386
    

    您可以为每个前沿-下载其他标签发布中描述的可用版本下载二进制文件。

  3. 授权执行:

    sudo chmod +x /usr/local/bin/gitlab-runner
    
  4. 使用正确权限创建空日志文件:

    sudo touch /var/log/gitlab_runner.log && sudo chown gitlab-runner:gitlab-runner /var/log/gitlab_runner.log
    
  5. 创建 rc.d 目录,以防其不存在:

    mkdir -p /usr/local/etc/rc.d
    
  6. rc.d 中创建 gitlab_runner 脚本:

Bash 用户可以进行如下操作:

   sudo bash -c 'cat > /usr/local/etc/rc.d/gitlab_runner' << "EOF"
   #!/bin/sh
   # PROVIDE: gitlab_runner
   # REQUIRE: DAEMON NETWORKING
   # BEFORE:
   # KEYWORD:

   . /etc/rc.subr

   name="gitlab_runner"
   rcvar="gitlab_runner_enable"

   user="gitlab-runner"
   user_home="/home/gitlab-runner"
   command="/usr/local/bin/gitlab-runner"
   command_args="run"
   pidfile="/var/run/${name}.pid"

   start_cmd="gitlab_runner_start"

   gitlab_runner_start()
   {
       export USER=${user}
       export HOME=${user_home}
       if checkyesno ${rcvar}; then
           cd ${user_home}
           /usr/sbin/daemon -u ${user} -p ${pidfile} ${command} ${command_args} > /var/log/gitlab_runner.log 2>&1
       fi
   }

   load_rc_config $name
   run_rc_command $1
   EOF

如果您未使用 Bash,创建一个名为 /usr/local/etc/rc.d/gitlab_runner 的文件并包含以下内容:

      #!/bin/sh
      # PROVIDE: gitlab_runner
      # REQUIRE: DAEMON NETWORKING
      # BEFORE:
      # KEYWORD:

      . /etc/rc.subr

      name="gitlab_runner"
      rcvar="gitlab_runner_enable"

      user="gitlab-runner"
      user_home="/home/gitlab-runner"
      command="/usr/local/bin/gitlab-runner"
      command_args="run"
      pidfile="/var/run/${name}.pid"

      start_cmd="gitlab_runner_start"

      gitlab_runner_start()
      {
         export USER=${user}
         export HOME=${user_home}
         if checkyesno ${rcvar}; then
            cd ${user_home}
            /usr/sbin/daemon -u ${user} -p ${pidfile} ${command} ${command_args} > /var/log/gitlab_runner.log 2>&1
         fi
      }

      load_rc_config $name
      run_rc_command $1
  1. 使 gitlab_runner 脚本可执行:

    sudo chmod +x /usr/local/etc/rc.d/gitlab_runner
    
  2. 注册 Runner
  3. 启用 gitlab-runner 服务并启动它:

    sudo sysrc gitlab_runner_enable=YES
    sudo service gitlab_runner start
    

    如果您不想在重启之后通过启用 gitlab-runner 服务进行启动,请使用:

    sudo service gitlab_runner onestart
    

升级到极狐GitLab Runner 10

升级到极狐GitLab Runner 10.0:

  1. 停止极狐GitLab Runner:

    sudo service gitlab_runner stop
    
  2. 可选。为以防万一,请保存之前版本的极狐GitLab Runner:

    sudo mv /usr/local/bin/gitlab-ci-multi-runner{,.$(/usr/local/bin/gitlab-ci-multi-runner --version| grep Version | cut -d ':' -f 2 | sed 's/ //g')}
    
  3. 下载新的极狐GitLab Runner 并使其可执行:

    # For amd64
    sudo fetch -o /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-freebsd-amd64
    
    # For i386
    sudo fetch -o /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-freebsd-386
    
    sudo chmod +x /usr/local/bin/gitlab-runner
    
  4. 编辑 /usr/local/etc/rc.d/gitlab_runner 并更改:

    command="/usr/local/bin/gitlab-ci-multi-runner run"
    

    成为:

    command="/usr/local/bin/gitlab-runner run"
    
  5. 启动极狐GitLab Runner:

    sudo service gitlab_runner start
    
  6. 确认一切运行正常后,您可以移除旧的二进制文件:

    sudo rm /usr/local/bin/gitlab-ci-multi-runner.*