成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

在 Fedora CoreOS 上運行 GitHub Actions

系統 Linux
GitHub Actions 是一項為快速建立持續集成和交付(CI/CD)工作流程而提供的服務。這些工作流程在被稱為“運行器runner”的主機上運行。GitHub 提供的 托管運行器 的操作系統的選擇是有限的(Windows Server、Ubuntu、MacOS)。

GitHub Actions 是一項為快速建立持續集成和交付(CI/CD)工作流程而提供的服務。這些工作流程在被稱為“運行器runner”的主機上運行。GitHub 提供的 托管運行器 的操作系統的選擇是有限的(Windows Server、Ubuntu、MacOS)。

[[427064]]

另一個選擇是使用 自托管 的運行器,這讓倉庫管理員對運行器有更多控制。自托管的運行程序是專門為某個存儲庫或組織服務的。下面的文章介紹了使用 Fedora CoreOS 配置自托管運行程序的步驟。

入門

Fedora CoreOS 是一個精簡的操作系統,旨在便于大規模的部署和維護。該操作系統會自動更新,并默認提供運行容器所需的工具。由于這些原因,Fedora CoreOS 是運行 CI/CD 工作流程的一個極佳選擇。

配置和配備 Fedora CoreOS 機器的第一步是生成一個 Ignition 文件。Butane 允許你使用更友好的格式(YAML)生成 Ignition 文件。

配置一個 Fedora CoreOS 運行器

要在 Fedora CoreOS 上執行 GitHub Actions,托管主機需要用于注冊和運行該運行器的二進制文件和腳本。從 Actions 運行器項目 下載二進制文件和腳本,并部署在 /usr/local/sbin/actions-runner 下。

  1. version: "1.3.0" 
  2. variant: fcos 
  3. storage: 
  4.   directories: 
  5.     - path: /usr/local/sbin/actions-runner 
  6.       mode: 0755 
  7.       user
  8.         name: core 
  9.       group
  10.         name: core 
  11.   files: 
  12.     - path: /usr/local/sbin/actions-runner/actions-runner-linux.tar.gz 
  13.       overwrite: true 
  14.       contents: 
  15.         source: https://github.com/actions/runner/releases/download/v2.278.0/actions-runner-linux-x64-2.278.0.tar.gz 
  16.       mode: 0755 
  17.       user
  18.         name: core 
  19.       group
  20.         name: core 

注冊和刪除令牌

為一個項目配置運行器需要一個“令牌token”。這可以防止在沒有正確權限的情況下從項目中注冊或刪除自托管的運行器。GitHub 提供的令牌有一個小時的過期時間。如果運行器在這個時間之后重新啟動,它將需要一個新的注冊令牌。

該令牌可能出問題,特別是在 Fedora CoreOS 自動更新時。更新過程希望托管主機在收到新數據后至少每隔幾周重啟一次。

幸運的是,可以使用 GitHub REST API 來獲取這些令牌,并在托管主機每次重啟時自動配置運行器。下面的 manage-runner.sh 腳本使用 API 來獲取令牌,刪除任何已經配置好的運行器,并用新的令牌注冊運行器。

  1. #!/bin/bash 
  2. # Handles the Github Action runner configuration. 
  3. # Remove and Registration token expires after 1 hour, if we want our runner 
  4. to work after a reboot (auto update) we need to refresh the tokens. 
  5. First remove the runner with a fresh remove token 
  6. REMOVE_TOKEN=$(curl -u ${GITHUB_USER}:${GITHUB_TOKEN} -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${GITHUB_USER}/${GITHUB_REPO}/actions/runners/remove-token | jq -r '.token'
  7. /usr/local/sbin/actions-runner/config.sh remove --token ${REMOVE_TOKEN} 
  8. Then register the runner with a fresh registration token 
  9. REGISTRATION_TOKEN=$(curl -u ${GITHUB_USER}:${GITHUB_TOKEN} -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${GITHUB_USER}/${GITHUB_REPO}/actions/runners/registration-token | jq -r '.token'
  10. /usr/local/sbin/actions-runner/config.sh --url https://github.com/cverna/fcos-actions-runner --token ${REGISTRATION_TOKEN} --labels fcos --unattended 

上面的腳本使用了一些環境變量,包含 GitHub 用戶名和用于驗證 REST API 請求的 個人訪問令牌Personal Access Token。個人訪問令牌需要存儲庫權限,以便成功檢索運行器的注冊和移除令牌。該令牌是安全敏感信息,所以最好將其存儲在一個具有更嚴格權限的不同文件中。在這個例子中,這個文件是 actions-runner。

  1. GITHUB_USER=<user
  2. GITHUB_REPO=<repo> 
  3. GITHUB_TOKEN=<personal_access_token> 

以下是創建這兩個文件 manage-runner.sh 和 actions-runner 的 Butane 片段。

  1. - path: /usr/local/sbin/actions-runner/manage-runner.sh 
  2.       contents: 
  3.         local: manage-runner.sh 
  4.       mode: 0755 
  5.       user
  6.         name: core 
  7.       group
  8.         name: core 
  9.     - path: /etc/actions-runner 
  10.       contents: 
  11.         local: actions-runner 
  12.       mode: 0700 
  13.       user
  14.         name: core 
  15.       group
  16.         name: core 

在 Fedora CoreOS 上運行 Actions

最后,創建用于配置和啟動運行器的 systemd 服務。在 Butane 配置文件中定義這些服務。

  1. systemd: 
  2.   units: 
  3.     - name: github-runner-configure.service 
  4.       enabled: true 
  5.       contents: | 
  6.         [Unit] 
  7.         Description=Configure the github action runner for a repository 
  8.         After=network-online.target boot-complete.target 
  9.         Requires=boot-complete.target 
  10.         [Service] 
  11.         EnvironmentFile=/etc/actions-runner 
  12.         Type=oneshot 
  13.         RemainAfterExit=yes 
  14.         User=core 
  15.         WorkingDirectory=/usr/local/sbin/actions-runner 
  16.         ExecStartPre=tar xvf actions-runner-linux.tar.gz --no-same-owner 
  17.         ExecStart=/usr/local/sbin/actions-runner/manage-runner.sh 
  18.         [Install] 
  19.         WantedBy=multi-user.target 
  20.     - name: github-runner.service 
  21.       enabled: true 
  22.       contents: | 
  23.         [Unit] 
  24.         Description=Run the github action runner 
  25.         After=github-runner-configure.service 
  26.         [Service] 
  27.         WorkingDirectory=/usr/local/sbin/actions-runner 
  28.         User=core 
  29.         ExecStart=/usr/local/sbin/actions-runner/run.sh 
  30.         [Install] 
  31.         WantedBy=multi-user.target 

這將創建兩個服務:github-runner-configure.service(在主機啟動完成后運行一次)和 github-runner.service(運行 Actions 運行器二進制文件并等待新的 CI/CD 作業)。

現在 Butane 配置已經完成,從中生成一個 Ignition 文件并配備一個 Fedora CoreOS Actions 運行器。

  1. $ podman run -i --rm -v $PWD:/code:z --workdir /code quay.io/coreos/butane:release --pretty --strict --files-dir /code config.yaml -o config.ignition 

一旦 Ignition 文件生成,它就可以用來在 支持 Fedora CoreOS 的平臺上配備一個運行器。

配置一個 Action 來使用一個自托管的運行器

下面的測試 Action 工作流程將測試 FCOS 的自托管的運行器。在你的 git 存儲庫中創建以下文件 .github/workflows/main.yml。

  1. # This is a basic workflow to help you get started with Actions 
  2. name: CI 
  3. # Controls when the action will run. 
  4. on
  5.   # Triggers the workflow on push or pull request events but only for the main branch 
  6.   push: 
  7.     branches: [ main ] 
  8.   pull_request: 
  9.     branches: [ main ] 
  10.   # Allows you to run this workflow manually from the Actions tab 
  11.   workflow_dispatch: 
  12. # A workflow run is made up of one or more jobs that can run sequentially or in parallel 
  13. jobs: 
  14.   # This workflow contains a single job called "build" 
  15.   build: 
  16.     # The type of runner that the job will run on 
  17.     runs-on: fcos 
  18.     # Steps represent a sequence of tasks that will be executed as part of the job 
  19.     steps: 
  20.       # Runs a single command using the runners shell 
  21.       - name: Run a one-line script 
  22.         run: podman run --rm fedora-minimal:34 echo Hello World ! 

請注意,runs-on 的配置被設置為使用標簽為 fcos 的運行器。

本文介紹的代碼可以在 這里 中找到。

責任編輯:未麗燕 來源: Linux中國
相關推薦

2020-12-13 08:25:32

FedoraCoreOSLinux

2020-07-20 18:30:44

Fedora 32DockerLinux

2020-04-02 18:30:28

PythonGitHub編程語言

2020-04-02 16:02:44

PythonGithub博客

2022-12-21 08:20:01

2021-03-26 08:41:11

Go語言Docker

2020-12-04 10:42:54

GithubSSDNode.js

2021-05-13 21:21:50

React應用GitHub

2019-11-11 15:10:37

FedoraLinuxbash

2021-08-19 18:28:22

FedoraLinuxOpenCV

2019-10-29 16:30:10

FedoraSSH端口Linux

2020-08-16 09:00:15

樹莓派FedoraLinux

2022-12-03 16:02:51

2015-01-15 10:50:46

CoreOSUnitedStackDocker

2024-12-02 07:00:00

特性標記軟件開發Action

2021-01-18 18:30:49

服務器開發工具

2024-02-20 08:08:43

2021-01-19 05:26:22

Github ActiJenkinsDevOps

2019-12-02 15:23:34

FedoraLinuxGIMP

2014-10-11 11:30:43

CentOSDocker
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品69毛片高清亚洲 | 久久婷婷国产 | 欧美成人一区二区三区 | 免费在线毛片 | 亚洲成人精品久久 | av看片网站 | 在线观看视频h | 中文字幕在线观看精品 | 国产精品视频播放 | 亚州一区二区三区 | 精品一二区 | 91久久 | 欧美jizzhd精品欧美巨大免费 | 中国毛片免费 | 欧美日韩高清在线一区 | 99爱视频| 99久久夜色精品国产亚洲96 | 一级黄色片美国 | 精品成人 | 日韩中文字幕在线观看 | 国产欧美一区二区三区国产幕精品 | 亚洲va欧美va天堂v国产综合 | 成人国产在线视频 | 国产在线中文字幕 | 免费黄色大片 | 国产精品久久久久久久久久免费看 | 精品国产18久久久久久二百 | 免费观看一级毛片 | 成人在线免费看 | 中文字幕在线观看一区 | 久久久久国产一区二区三区四区 | 欧美日韩三区 | 国产精品一区二区精品 | 日本午夜精品一区二区三区 | 男女网站在线观看 | 欧美二区在线 | 午夜电影一区二区 | 日本aaa视频 | 在线永久看片免费的视频 | 国产综合视频 | 在线中文字幕av |