使用GitHub Actions的Self-hosted runner

  1. 登录github网站选择项目点击Settings按钮,进入设置页面
  2. 点击actions/runners进入Runners页面
  3. 点击New self-hosted runner按钮进入新增页面
  4. 选择相应配置,生成相应的命令,在内网机器上运行
  • 下载:

    # Create a folder
    $ mkdir actions-runner && cd actions-runner# Download the latest runner package
    $ curl -o actions-runner-linux-x64-2.319.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.319.1/actions-runner-linux-x64-2.319.1.tar.gz# Optional: Validate the hash
    $ echo "3f6efb7488a183e291fc2c62876e14c9ee732864173734facc85a1bfb1744464  actions-runner-linux-x64-2.319.1.tar.gz" | shasum -a 256 -c# Extract the installer
    $ tar xzf ./actions-runner-linux-x64-2.319.1.tar.gz
    Configure
    
  • 配置

    # Create the runner and start the configuration experience
    $ ./config.sh --url https://github.com/xxxx/deployWeb --token AGIAQ3S7N4IAHW7REWDQQP3GZAL7Y# Last step, run it!
    $ ./run.sh
    
    • 运行./config.sh --url https://github.com/xxxx/deployWeb --token AGIAQ3S7N4IAHW7REWDQQP3GZAL7Y输出:Must not run with sudo,改用RUNNER_ALLOW_RUNASROOT=true ./config.sh --url https://github.com/xxxx/deployWeb --token AGIAQ3S7N4IAHW7REWDQQP3GZAL7Y 参考链接
    • 运行RUNNER_ALLOW_RUNASROOT=true ./config.sh --url https://github.com/xxxx/deployWeb --token AGIAQ3S7N4IAHW7REWDQQP3GZAL7Y输出Http response code: NotFound from 'POST https://api.github.com/actions/runner-registration' (Request Id: 5EA2:282BC3:355B13:38E34C:66C8062C) {"message":"Not Found","documentation_url":"https://docs.github.com/rest","status":"404"} Response status code does not indicate success: 404 (Not Found). 查token不是静态的,它会很快过期,所以当不立即使用令牌时就会发生这种情况,刷新github页面重置token参数就可以了。参考链接
  • 成功
    ```bash
    RUNNER_ALLOW_RUNASROOT=true ./config.sh --url https://github.com/xxxx/deployWeb --token AGIAQ3TYM6U23HE23X2U3A3GZAKWK

      --------------------------------------------------------------------------------
      |        ____ _ _   _   _       _          _        _   _                      |
      |       / ___(_) |_| | | |_   _| |__      / \   ___| |_(_) ___  _ __  ___      |
      |      | |  _| | __| |_| | | | | '_ \    / _ \ / __| __| |/ _ \| '_ \/ __|     |
      |      | |_| | | |_|  _  | |_| | |_) |  / ___ \ (__| |_| | (_) | | | \__ \     |
      |       \____|_|\__|_| |_|\__,_|_.__/  /_/   \_\___|\__|_|\___/|_| |_|___/     |
      |                                                                              |
      |                       Self-hosted runner registration                        |
      |                                                                              |
      --------------------------------------------------------------------------------
      
      # Authentication
      
      
      √ Connected to GitHub
      
      # Runner Registration
      
      Enter the name of the runner group to add this runner to: [press Enter for Default] 
      
      Enter the name of runner: [press Enter for XXX-dev-test] my-action-runner
      
      This runner will have the following labels: 'self-hosted', 'Linux', 'X64' 
      Enter any additional labels (ex. label-1,label-2): [press Enter to skip] 
      
      √ Runner successfully added
      √ Runner connection is good
      
      # Runner settings
      
      Enter name of work folder: [press Enter for _work] /actions-runner
      
      √ Settings Saved.
      ```
    
  1. 在你的GitHub Actions workflow中,将 runs-on 指定为 self-hosted后推送项目,Runner运行输出如下:。
    Requested labels: self-hosted
    Job defined at: mingchangge/deployWeb/.github/workflows/deploy.yaml@refs/heads/master
    Waiting for a runner to pick up this job...
    

结束语

到这一步我就没有往下面进行了。因为我突发奇想的要在K8s上运行GitHub Actions的自托管运行器,所以本篇就这样结束了。或许等我把即定目标前端项目自动化部署实现【这个目标目前只完成了k8s的部署。私有docker镜像搭建、内网GitHub Actions的自托管运行器、项目CI构建均没有完成啊啊啊啊!!!】,会回头继续补充本篇内容。

删除Runner

删除Runner,我直接将actions-runner文件夹删除了。等回头重新搭建完成,再运行下面的命令吧。

./config.sh remove --token AGIAQ3TS4DIE57KTU7FYPZTGZQE5Q
  • 8
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值