如何使用 gitlab-ci 在 docker 中构建 archlinux pkgbuild

How to build archlinux pkgbuild inside docker with gitlab-ci

我需要将 gitlab-ci 与 docker 一起使用,以便在每次提交时自动构建和测试 archlinux 包。

我的.gitlab-ci.yml:

image: pritunl/archlinux

before_script:
  - pacman -Su pkgbuild-introspection --noconfirm

stages:
  - build

makepkg:
  script:
    - makepkg --clean --rmdeps --syncdeps --noarchive --noconfirm --noprogressbar --asdeps
  stage: build

一切都很好,但是当 CI 调用 makepkg 命令时我得到这个错误:

==> ERROR: Running makepkg as root is not allowed as it can cause permanent, catastrophic damage to your system.

==> ERROR: An unknown error has occurred. Exiting...

我该如何解决?

AFAIK,无法以 root 身份 运行 makepkg。如果你 运行 作为 root,makepkg 可以将文件放在你系统的任何地方,而不仅仅是 $pkgdir 那个包的来源。这是通过使用 fakeroot 停止的,当 运行 为 root 时禁用。

A fake root is simply a subdirectory within the build directory that functions and behaves as the system's root directory. In conjunction with the fakeroot program, makepkg creates a fake root directory, and installs the compiled binaries and associated files into it, with root as owner.

我建议您扩展 pritunl/archlinux 图像并添加一个简单的用户,仅用于 makepkg 操作。