自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在 GitLab 執(zhí)行器中使用 Podman

系統(tǒng) Linux
使用 Podman 啟動 GitLab 執(zhí)行器有多種方法,我在本文中概述了其中兩種。

GitLab 執(zhí)行器Runner 是一個與 GitLab CI/CD 配合使用的應用,可在 GitLab 基礎設施上的流水線中運行作業(yè)。它們通常用于在提交代碼后自動編譯應用或在代碼庫上運行測試。你可以將它們視為基于云的 Git 鉤子。

主要的公共 GitLab 實例 提供了許多易于訪問的共享執(zhí)行器,可供你在 CI 流水線中使用。你可以在 GitLab 上倉庫的 設置Settings -> CI/CD -> 執(zhí)行器Runners

Display available GitLab runners in your repository's settingsDisplay available GitLab runners in your repository's settings

你可能不想依賴共享執(zhí)行器,而是選擇自己的執(zhí)行器,原因有很多。例如,控制執(zhí)行器運行的基礎設施以實現(xiàn)額外的安全性和/或隱私、靈活的執(zhí)行器配置或分配給你的 GitLab 用戶帳戶的有限 CI 分鐘數(shù)。

GitLab 執(zhí)行器依賴于 執(zhí)行環(huán)境executor

那么,Podman 作為執(zhí)行環(huán)境呢?

自 v4.2.0 起,Podman 對 GitLab 執(zhí)行器提供了原生支持。以下是使用 Podman 作為 GitLab 執(zhí)行器的 執(zhí)行環(huán)境 的兩種方法的快速瀏覽。

Docker 執(zhí)行環(huán)境

你可以在 GitLab 執(zhí)行器中使用 Podman 作為 Docker 的直接替代品。就是這樣:

本示例使用 2023 年 2 月的 CentOS Stream 9 環(huán)境,使用 Podman v4.4.0。它應該可以在任何具有足夠新的 Podman 的 RHEL/CentOS Stream/Fedora 環(huán)境中正常工作。查看 GitLab 文檔 了解先決條件。

首先,安裝 Podman:

$ sudo dnf -y install podman

接下來安裝 gitlab-runner 包:

# 添加 GitLab 執(zhí)行器倉庫
$ curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
# 安裝 gitlab-runner 包
$ sudo dnf -y install gitlab-runner

最后,允許用戶在注銷后執(zhí)行任務:

$ sudo loginctl enable-linger gitlab-runner

配置并注冊執(zhí)行器

使用以下步驟配置 Docker 運行環(huán)境。

安裝 gitlab-runner 包會創(chuàng)建一個 gitlab-runner 用戶帳戶,但你需要 root 訪問權(quán)限才能操作該用戶帳戶。gitlab-runner 可以在用戶模式下運行,但需要一些手動干預來進行構(gòu)建處理。在此示例中,我使用 sudo 在系統(tǒng)模式下運行它。它看起來是這樣的:

$ sudo gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=7978 revision=d540b510 version=15.9.1
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.com
Enter the registration token:
xxxxxxxxxxxxxxxxx
Enter a description for the runner:
[lmandvek-c9s-gitlab-runner]:
Enter tags for the runner (comma-separated):
Enter optional maintenance note for the runner:
WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://gitlab.com/gitlab-org/gitlab/-/issues/380872
Registering runner... succeeded                     runner=GR13489419oEPYcJ8
Enter an executor: custom, docker, ssh, docker-ssh+machine, docker-ssh, parallels, shell, virtualbox, docker+machine, instance, kubernetes:
docker
Enter the default Docker image (for example, ruby:2.7):
registry.gitlab.com/rhcontainerbot/pkg-builder
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"

你將需要一些額外的配置才能使用 Podman。配置執(zhí)行器為每個作業(yè)創(chuàng)建一個網(wǎng)絡。有關(guān)更多信息,請參閱 GitLab 文檔

首先,啟用 Podman 系統(tǒng)服務并修改 /etc/gitlab-runner/config.toml 中的環(huán)境:

[[runners]]
    environment = ["FF_NETWORK_PER_BUILD=1"]
    [runners.docker]
        host = "unix:///run/user/1001/podman/podman.sock"

重啟執(zhí)行器以實施更改:

$ sudo gitlab-runner restart

驗證新的執(zhí)行器在 GitLab 項目的 設置Settings -> CI/CD -> 執(zhí)行器Runners

Restart the GitLab runnerRestart the GitLab runner

接下來,驗證你的 CI 流水線正在使用執(zhí)行器。你的 CI 任務日志將提及正在使用的執(zhí)行器的名稱以及任何其他配置信息,例如 執(zhí)行器的執(zhí)行環(huán)境的功能標志和容器鏡像。

View CI tasklogs to display the runnerView CI tasklogs to display the runner

Podman-in-Podman(pipglr)

Chris Evich 創(chuàng)建了 pipglr,這是一個 Podman-in-Podman 設置,用于使用免 root 的 Podman 來支持你自己的免 root 的 GitLab 執(zhí)行器。此方法不需要對 .gitlab-ci.yaml 配置進行任何更改,因此你可以繼續(xù)按原樣使用現(xiàn)有設置。

以下是幫助你運行此程序的快速設置指南。

配置步驟

容器鏡像是從 pipglr Containerfile 自動構(gòu)建的,因此將鏡像設置為該倉庫:

$ IMAGE="registry.gitlab.com/qontainers/pipglr:latest"

接下來,使用你的 GitLab 注冊令牌創(chuàng)建 Podman 密鑰:

$ echo '<actual registration token>' | podman secret create REGISTRATION_TOKEN -

創(chuàng)建一個空白的 config.toml,稍后將包含你的所有執(zhí)行器設置。你必須執(zhí)行此步驟才能使以下 podman container register runlabel $IMAGE 步驟成功:

$ touch ./config.toml  # 重要:文件必須存在,即使是空的。

注冊你的執(zhí)行器。你可以重復此步驟來注冊多個執(zhí)行器。如果你想使用可能不同的標簽或配置選項集并行運行多個 CI 任務,這非常有用。

$ podman container runlabel register $IMAGE

使用你選擇的編輯器編輯 config.toml。這是可選的,但通常需要更改用于實際 CI 任務的容器鏡像。默認情況下,鏡像設置為:registry.fedoraproject.org/fedora:latest。

$ $EDITOR ./config.toml  # if desired

最后,配置對卷的訪問。容器卷內(nèi)使用多個用戶,因此你必須專門配置它們以允許訪問。再次使用 runlabel 來完成:

$ podman container runlabel setupstorage $IMAGE
$ podman container runlabel setupcache $IMAGE

測試執(zhí)行器

是時候檢查配置了。首先啟動 GitLab 執(zhí)行器容器:

$ podman container runlabel run $IMAGE

允許執(zhí)行器用戶在注銷后運行服務:

$ sudo loginctl enable-linger $(id -u)

驗證你的新執(zhí)行器在 GitLab 項目的 設置Settings -> CI/CD -> 執(zhí)行器Runners

Verify the new runner is visibleVerify the new runner is visible

最后,驗證你的 CI 流水線正在使用你的執(zhí)行器:

Verify the CI pipelineVerify the CI pipeline

總結(jié)

使用 Podman 啟動 GitLab 執(zhí)行器有多種方法,我在此處概述了其中兩種。嘗試一下,然后讓我知道哪一個最適合你。如果 Docker 執(zhí)行環(huán)境方法有任何問題,請登錄并通過 Podman 上游 或 GitLab 支持 提交問題。如果 pipglr 方法出現(xiàn)問題,請在 pipglr 上游 提交問題。

GitLab 與 Podman 一起運行愉快 ??

責任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2021-07-25 10:34:17

FedoraPodmanLinux

2020-09-09 07:00:00

TensorFlow神經(jīng)網(wǎng)絡人工智能

2022-05-10 09:12:16

TypeScript裝飾器

2022-04-29 08:41:40

開發(fā)應用程序執(zhí)行器

2011-08-10 09:31:41

Hibernateunion

2021-03-09 07:27:40

Kafka開源分布式

2015-08-27 09:46:09

swiftAFNetworkin

2021-06-09 09:36:18

DjangoElasticSearLinux

2022-05-17 08:25:10

TypeScript接口前端

2024-01-18 08:37:33

socketasyncio線程

2022-06-23 08:00:53

PythonDateTime模塊

2024-11-04 15:30:43

Python裝飾器函數(shù)

2025-03-21 09:58:59

Python數(shù)據(jù)類型安全

2021-09-10 10:30:22

Java代碼

2022-10-25 09:07:28

Linuxxargs命令

2023-12-01 09:18:27

AxiosAxios 庫

2015-11-26 10:57:56

DockerOpen vSwitc

2019-09-16 19:00:48

Linux變量

2014-07-02 09:47:06

SwiftCocoaPods

2020-04-09 10:18:51

Bash循環(huán)Linux
點贊
收藏

51CTO技術(shù)棧公眾號