如何让我的自托管GitHub runner在Docker容器中运行作业,而不是在本地shell和操作系统中运行?

wkyowqbh  于 2022-11-22  发布在  Docker
关注(0)|答案(1)|浏览(195)

我把我的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
bkkx9g8r

bkkx9g8r1#

我尝试使用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

相关问题