【问题标题】:How to make my self hosted GitHub runner run jobs in a docker container instead of the native shell and OS?如何让我的自托管 GitHub runner 在 docker 容器而不是本机 shell 和操作系统中运行作业?
【发布时间】:2022-11-21 23:43:45
【问题描述】:

我将我的 Raspberry Pi 4 注册为 GitHub 的自托管运行器。它可以工作,但所有作业都在本机系统本身上运行。我怎样才能让 GitHub 也在运行器上创建一个 Docker 容器,以便底层系统保持干净?它是 GitLab 的默认行为,我很惊讶它不是 GiHub 的,或者我可能遗漏了什么请帮助我。

# This is a basic workflow to help you get started with Actions

name: CI Rasp

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: self-hosted

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3

      # Runs a single command using the runners shell
      - name: Run a one-line script
        run: echo Hello, world!

      # Runs a set of commands using the runners shell
      - name: Run blinky for 3 times
        run: /home/jbron/blinky.py

【问题讨论】:

    标签: docker github-actions github-actions-self-hosted-runners


    【解决方案1】:

    我正在尝试使用 container 上下文实现相同的目的。

    我相信它看起来像这样:

    # This is a basic workflow to help you get started with Actions
    
    name: CI Rasp
    
    # Controls when the workflow will run
    on:
      # Triggers the workflow on push or pull request events but only for the "main" branch
      push:
        branches: [ "main" ]
      pull_request:
        branches: [ "main" ]
    
      # Allows you to run this workflow manually from the Actions tab
      workflow_dispatch:
    
    # A workflow run is made up of one or more jobs that can run sequentially or in parallel
    jobs:
      # This workflow contains a single job called "build"
      build:
        # The type of runner that the job will run on
        runs-on: self-hosted
        container:
          # Runner docker image
          image: ubuntu:22.04
    
        # Steps represent a sequence of tasks that will be executed as part of the job
        steps:
          # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
          - uses: actions/checkout@v3
    
          # Runs a single command using the runners shell
          - name: Run a one-line script
            run: echo Hello, world!
    
          # Runs a set of commands using the runners shell
          - name: Run blinky for 3 times
            run: /home/jbron/blinky.py
    

    检查此链接以获取更多信息:

    https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontainer

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2021-02-04
      • 2023-02-10
      • 1970-01-01
      • 1970-01-01
      • 2022-08-13
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      相关资源
      最近更新 更多