侧边栏壁纸
博主头像
AngusWong's博客 博主等级

行动起来,活在当下

  • 累计撰写 25 篇文章
  • 累计创建 26 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

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

Administrator
2021-04-09 / 0 评论 / 0 点赞 / 6 阅读 / 0 字
我的Gitlab是使用宝塔Linux面板进行安装的,宝塔面板版本7.5.1,系统版本CentOS 7.9.2009,本文章介绍需要自动部署到服务器的代码有Lumen的代码和iviewadmin后台管理程序的代码。 [h2title]一、安装Gitlab Runner[/h2title] 使用二进制文件安装,请选择自己系统架构:
# 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"
[h2title]二、添加执行权限[/h2title]
sudo chmod +x /usr/local/bin/gitlab-runner
[h2title]三、建立一个GitLab CI 用户[/h2title]
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
[h2title]四、注册Runner[/h2title]
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 [h2title]五、安装和运行Runner服务[/h2title]
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 [h2title]注意事项[/h2title] 当你运行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里面增加环境变量后就可以运行了
0

评论区