AngusWong's 博客

  • 首页
  • Linux
  • Mac
  • PHP
  • 数据库
  • 路由相关
专注于计算机相关技术分享
  1. 首页
  2. Linux
  3. 正文

Gitlab13.* 最新社区版本使用GitLab Runner自动部署代码

2021年4月9日 3651点热度 0人点赞 0条评论

我的Gitlab是使用宝塔Linux面板进行安装的,宝塔面板版本7.5.1,系统版本CentOS 7.9.2009,本文章介绍需要自动部署到服务器的代码有Lumen的代码和iviewadmin后台管理程序的代码。

一、安装Gitlab Runner

使用二进制文件安装,请选择自己系统架构:

# Linux x86-64
sudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64"

# Linux x86
sudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386"

# Linux arm
sudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm"

# Linux arm64
sudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm64"

# Linux s390x
sudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-s390x"

二、添加执行权限

sudo chmod +x /usr/local/bin/gitlab-runner

三、建立一个GitLab CI 用户

sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

四、注册Runner

root@vm77649:~# sudo gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=15899 revision=54944146 version=13.10.0
Running in system-mode.                            
                                                   
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://gitlab.****.com/
Enter the registration token:
LFz*******
Enter a description for the runner:
[vm77649]: testRunner
Enter tags for the runner (comma-separated):
testRunner
Registering runner... succeeded                     runner=LFzEKTe4
Enter an executor: parallels, ssh, docker-ssh+machine, kubernetes, docker+machine, custom, docker, docker-ssh, shell, virtualbox:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 
root@vm77649:~#

其中url和token在安装好的gitlab管理员页面可以找到

注册好后可以在gitlab服务器上面看到新注册的Runner

五、安装和运行Runner服务

root@vm77649:~# sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
Runtime platform                                    arch=amd64 os=linux pid=16055 revision=54944146 version=13.10.0
root@vm77649:~# sudo gitlab-runner start
Runtime platform                                    arch=amd64 os=linux pid=16104 revision=54944146 version=13.10.0
root@vm77649:~# ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     16111  1.0  6.1 141784 30504 ?        Ssl  13:43   0:00 /usr/local/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --user gitlab-runner
root     16119  0.0  0.6  10920  3292 pts/0    R+   13:43   0:00 ps -aux
root@vm77649:~#

上面是使用新建立的用户gitbal-runner来运行服务的,你也可以使用其他用户来运行,但需要确保用户有权限操作working-directory

注意事项

当你运行Shell命令时,有时有些命令会提示找不到,比如npm命令,这时需要在.gitlab-ci.yml里面修改环境变量,以下是我yml文件示例

.gitlab-ci.yml

deploying:
  stage: deploy
  before_script:
    - export PATH=$PATH:/www/server/nvm/versions/node/v14.16.0/bin
  script:
    - echo "deploying"
    - npm install
    - npm run build
    - rsync -az --delete --exclude=404.html --exclude=.user.ini ./dist/* /www/wwwroot/manage.***.***/
  only:
    - tags
  tags:
    - testRunner

在beforce_script里面增加环境变量后就可以运行了

标签: gitlab runner
最后更新:2021年4月9日

Sean

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复
分类
  • Linux
  • Mac
  • PHP
  • 其他
  • 前端
  • 数据库
  • 路由相关
最新 热点 随机
最新 热点 随机
macOS Sonoma, macOS Sequoia删除Mac启动台里删不掉的图标 PVE8修改软件仓库源和 CT模板(LXC)源为国内源 Debian12更换国内源 构建宝塔面板Docker镜像 无需root!卸载小米电视/盒子内置应用 检查系统是否被入侵
重新编译PHP让宝塔面板curl支持http2 proxmox ve (PVE) 调整虚拟机(VM)的磁盘大小 Gitlab13.* 最新社区版本使用GitLab Runner自动部署代码 构建宝塔面板Docker镜像 使用宝塔面板安装的Gitlab更改配置 编译自己的路由器系统Openwrt

COPYRIGHT © 2021 huangyuqiang.cn. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang