openSUSE:构建服务 Debian 构建

跳转到:导航搜索

Debian 构建

此页面提供有关 openSUSE 构建服务支持的基于 *Debian* 的 Linux 发行版的打包信息,目前包括 Debian 本身和 Ubuntu。

与 RPM 一样,Debian 软件包分为二进制和源代码两种类别。二进制软件包具有.deb扩展名,它们包含您想要分发的应用程序的编译版本。源代码软件包不是单个文件(如.src.rpm机制);相反,它们由多个文件组成。

对于在 upstream 源代码中提供 `debian/` 子目录的软件包(称为原生软件包)。

  • 原始 tarball
  • A.dsc文件

如果 packager 提供 `debian/` 子目录(非原生软件包)。

  • 原始 tarball
  • 一个差异文件或一个.debian.tar.xz文件
  • A.dsc文件

如果软件包没有 upstream 源代码,则原始 tarball 可能不存在。

.dsc文件是从解压后的源代码软件包生成的元数据文件,主要包含对源代码软件包其他文件的引用,以便使用 Debian 源代码软件包的工具确切地知道需要使用哪些文件。此文件中的元数据主要来自debian/control文件,使其易于例如在不解压 Debian tarball 的情况下找到软件包的构建依赖项。由于.dsc文件包含校验和和这些文件的签名,因此工具可以验证文件是否被篡改。

软件包仓库

构建服务不会为.deb-based 发行版创建源代码仓库;只会创建.deb文件并发布。

因此,重要的是要记住,标准的 Debian 仓库至少由两个目录组成

(your repository root)
|
+-binary
+-source

而构建服务只会创建带有发行版名称的二进制目录,例如 http://download.opensuse.org/repositories/home:/yourself/Debian_Etch/ 对应于二进制目录,而不是仓库根目录(这将是 http://download.opensuse.org/repositories/home:/yourself/ )。

此外,请记住,创建源代码软件包的三个部分不是为了创建 .deb 软件包而需要的。相反,它们是在您创建源代码仓库并允许通过 apt-get 在用户的机器上自动编译和打包时需要的。

构建服务不会创建源代码仓库,因此您根本不需要知道它们的构造和使用方式。

构建标准的 Debian 软件包

如果您熟悉在 Debian 或 Ubuntu 中使用的标准打包方式,则可以使用原生 Debian 或 Ubuntu 工具创建(或重用)标准的 Debian 源代码软件包。简而言之,标准的 Debian 源代码软件包由两个或三个文件组成

  • 原始 tarball(仅适用于带有 upstream tarball 的软件包)
  • 一个差异文件或一个 Debian tarball
  • A.dsc文件

可以使用 Debian 系统上的工具(例如 `dpkg-buildpackage -S` 或 `dpkg-source -b`)创建这样的源代码软件包,如 Debian 文档中所述。

如果您使用这种标准方式创建软件包,则无需担心更新.dsc文件,因为 Debian 工具会为您执行此操作。

可以将这些文件作为源代码文件上传到构建服务,构建服务可以使用这些文件来构建软件包。

或者,可以使用“添加文件”的“服务”功能通过 URI 指定文件。这样,构建服务将从现有的 Debian 或 Ubuntu 源代码仓库下载这三个文件!

http://packages.ubuntu.com/(Ubuntu 软件包搜索)的源代码软件包页面底部,有组成软件包的三个文件的 URL。可以使用您浏览器的“复制链接”功能将这些 URL 复制到剪贴板。然后可以使用 buildservice 的“添加文件”页面中的 URL。 (在本页的“从远程 URL 上传”字段中。) 这样,您就可以从例如 Ubuntu “Universe” 仓库重建软件包,而无需在您的系统上拥有源代码。

为不同的发行版版本提供不同的配置

要在 OBS 上为多个 Debian 或 Ubuntu 版本使用不同的配置,您需要指定多个 .dsc 文件。它们应以类似于基于 RPM 的发行版的替代 .spec 文件的方案命名,即 *projectName-repository.dsc。不同的 .dsc 文件可以引用不同的源代码 tarball(如果需要)。

示例

  • wonderproj-xUbuntu_10.10.dsc
  • wonderproj_0.0.1-1.debian.tar.gz
  • wonderproj_0.0.1.orig.tar.bz2

在这种情况下,wonderproj-xUbuntu_10.10.dsc 将包含如下引用

Format: 3.0 (quilt)
Source: wonderproj
Binary: wonderproj
Architecture: any
Version: 0.0.1-1
Maintainer: I.M.Coder <im@wonder-code.org>
Standards-Version: 0.0.1
Build-Depends:  cdbs, cmake, debhelper, pkg-kde-tools, kdelibs5-dev
Checksums-Sha1:
 0ba9af478421ce1b0ca652b0d035a49ed4f5513f 2893892 wonderproj_0.0.1.orig.tar.bz2
 f0d12c000ac09c48439408e2978eea56f152ae1c 20710 wonderproj_0.0.1-1.debian.tar.gz
Checksums-Sha256:
 0afd23eecf11a8d387019a007064c6554dad3adaf640c28a39a12143ac8ccc19 2893892 wonderproj_0.0.1.orig.tar.bz2
 f10e4a9ff5b629b2b73e8b6ca97f4d47b7ac4e53c33930db1e5fefc317f2c123 20710 wonderproj_0.0.1-1.debian.tar.gz
Files:
 437a8d1df895203af8b08e64717a6e30 2893892 wonderproj_0.0.1.orig.tar.bz2
 0323ebdd4a1983de61a5e4f326194426 20710 wonderproj_0.0.1-1.debian.tar.gz

处理构建依赖关系差异

如果您需要为某些发行版版本提供额外的构建依赖项,可以在Build-Depends行中在 .dsc 文件中提供它们。

如果debian/control(在 .debian.tar.gz 文件中)包含的任何构建依赖项不适用于某些发行版版本,请将其从debian/control中删除,并为仍然需要它们的发行版版本将其添加到相应的 .dsc 文件中。

您可能需要删除debian/control文件中的版本号规范,如果它们对某些发行版版本不正确。

如果debian/control文件已被修改,请按如下方式提供它

  • 重新创建 .debian.tar.gz 文件以包含修改后的debian/control文件
  • 修改 .dsc 文件以包含 .debian.tar.gz 文件的新的校验和和文件大小。可以使用以下命令获取新的校验和md5sum, sha1sumsha256sum.

创建 Debian 软件包的另一种方法

对于另一种方法,OBS 使用 debtransform 工具。该工具需要 5 个文件,如果存在任何debian.*文件,则会自动调用它

  • packageName.dsc
  • debian.changelog
  • debian.control
  • debian.rules
  • 源代码 tarball

`debtransform` 将从这些文件生成适当的源代码软件包。然后,OBS 将构建源代码软件包到二进制.deb. debtransformobs-build工具的一部分,通常安装到 `/usr/lib/build/debtransform` 中。

构建 .deb 软件包的 openSUSE 先决条件

要在基于 openSUSE 的发行版上使用 `osc build`:

  • dpkg`(用于dpkg)
  • binutils(用于ar)
  • devscripts(用于debchange,可选)

使用以下命令安装它们

# zypper install dpkg binutils devscripts

创建 .deb 的最小文件集

为了成功创建 .deb 软件包,您必须创建至少这些文件

  • packageName.dsc
  • debian.changelog
  • debian.control
  • debian.rules

当然,还有一个包含软件包源代码以进行编译的 tarball。

packageName.dsc

.dsc 文件格式

.dsc文件是描述源代码软件包的标准 Debian 文件,由分隔符分隔的标签和值组成:. .dsc文件不允许空行和注释。请记住在使用debtransform以下标签时。

最小模板

此文件的最小模板是

Format: 1.0
Source: packageName
Version: 5.6-3
Binary: packageName
Maintainer: FirstName LastName <email@hostname.org>
Architecture: any
Build-Depends: debhelper (>= 4.1.16), nameOfPackageNeededToBuildIt
Files: 
 d57283ebb8157ae919762c58419353c8 133282 packageName_5.6.orig.tar.gz
 2fecf324a32123b08cefc0f047bca5ee 63176 packageName_5.6-1.diff.tar.gz

在上面的模板中,仅列出了强制字段,但还有许多可选字段。您可以在 http://www.debian.org/doc/debian-policy/ch-controlfields.html 上找到有关这些字段的所有信息。

让我们在这里解释一个摘要,以便您了解它们的含义

  • 格式: 是软件包的格式.debdebtransform 仅知道1.0.
  • Source: 是发行版中的软件包名称
  • 版本: 由源代码的版本和软件包的修订版组成;在模板中,5.6是源代码的版本,而3(破折号后)是 Debian 软件包的修订版。每次更改创建.deb的一个文件时,您应该增加它。
  1. Binary: 是 apt 管理器看到的二进制软件包的名称(例如,要安装它,您指定 `apt-get install BinaryField 中写入的名称`)
  2. Maintainer : 是源代码维护者的名称(不是您的姓名或打包者的姓名)
  3. 架构: 您想要为其编译的架构列表
  4. Build-Depends: 编译所需的库。您必须指定debhelper (>= 4.1.16)因为它包含系统用于编译的所有辅助脚本。
  5. 文件: 从理论上讲,您必须指定所用文件的 MD5 和文件大小,但在实践中,只需放置一些值,即使它们不正确也没关系。重要的是存在带有三个字段的两行,如模板所示。(您可以复制并粘贴模板中的两行,并将 packageName 替换为您想要创建的名称,这样就可以了。debtransform 会完成其余的工作。).debDEBTRANSFORM 标签

可以在

中使用“debtransform”标签提供有关 OBS 的额外信息。请注意,这些标签仅在.dsc被调用时使用,即如果 OBS 包中存在任何 debian.* 文件。debtransformDEBTRANSFORM-RELEASE

添加以便 OBS 将自动递增的构建号附加到 Debian 软件包的版本中。DEBTRANSFORM-TAR

  • DEBTRANSFORM-FILES-TAR
  • DEBTRANSFORM-SERIES
  • 这些可用于指定一个 tar 文件(.gz/.bz2/.xz)作为可以在 RPM 和基于 Debian 的构建之间共享的源代码,还可以用于在 Debian 构建中重用 RPM 补丁。您可以像这样使用多个 tar 文件

更多提示在此邮件中:http://lists.opensuse.org/opensuse-buildservice/2007-03/msg00067.html

Debtransform-Files-Tar: debian.tar.gz debian-control-xUbuntu_6.06.tar.gz

Debian 创建一个

debian.changelog

的机制是将一个名为 ".debdebian" 的目录放入源代码树中,其中包含许多用于自动化提取、编译、安装和打包过程的文件。您不需要自己执行此操作,因为 debtransform 会为您创建该目录,并将所有名为

debian.fileName的文件放入其中。这对于所有

-based 发行版(包括 Ubuntu)都有效,对于.deb(而不是debian.changelogubuntu.changelog)同样适用。这是最小模板

您可能会认为它只是一个 changelog,但语法如此严格,以至于一个小错误(例如缺少空格)会导致整个过程失败。:-( 请注意 http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog 中指定的语法。为了避免语法问题,您可以使用

packageName (5.6-3) stable; urgency=low

  * Initial Release

 -- YourName <youremail@hostname.de>  Mon, 25 Dec 2007 10:50:38 +0100

命令(来自名为debchangedevscripts的软件包)来编辑此文件。如果您添加一个

,OBS 会检查 changelog 的版本号是否与debian.changelog文件中的版本号匹配。如果不匹配,它会添加一个包含来自.dsc文件的版本号的假条目。这可确保源代码和二进制软件包的版本保持同步。.dsc此文件用于描述软件包及其依赖项。这是一个最小模板

debian.control

有些冗余信息可以从

Source: packageName
Section: sectionName
Priority: optional
Maintainer: yourName <yourEmail@hostname.de>
Build-Depends: debhelper (>= 9), nameOfPackageNeededToBuildIt

Package: nameOfPackage
Architecture: any
Depends: ${shlibs:Depends}
Description: single-line brief description
 Then, here there is the long description of the package.
 .
 Prepend every line with a single space. Use a single full stop
 prepended by a space to separate paragraphs.
 .
 For more information on the syntax, see the Debian Policy:
 http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description

复制,.dsc文件Build-Depends; 软件包Binary; 架构维护者通常相同。

debian.rules

这是一个Makefile包含提取、编译、安装和打包源代码的所有规则的文件。您可以更改此文件中的任何内容,但简化方法是更改几行以使其编译。文件的其余部分可以保持不变。

#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#DH_VERBOSE = 1

# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh $@

# Extracted from Debian Maintainer Guide:
#
# You may need to run dh_* commands invoked via the new dh with added arguments,
# or to run additional commands with them, or to skip them. For such cases, you
# create an override_dh_foo target with its rule in the rules file defining an
# override_dh_foo target for the dh_foo command you want to change. It basically
# says run me instead.
# 
# Please note that the dh_auto_* commands tend to do more than what has been
# discussed in this (over)simplified explanation to take care of all the corner
# cases. It is a bad idea to use override_dh_* targets to substitute simplified
# equivalent commands (except for the override_dh_auto_clean target) since it
# may bypass such smart debhelper features.
# 
# So, for instance, if you want to store system configuration data in the
# /etc/gentoo directory instead of the usual /etc directory for the recent
# gentoo package using Autotools, you can override the default --sysconfig=/etc
# argument given by the dh_auto_configure command to the ./configure command by
# the following:
#
# override_dh_auto_configure:
#	dh_auto_configure -- --sysconfig=/etc/gentoo
# 
# The arguments given after -- are appended to the default arguments of the
# auto-executed program to override them. Using the dh_auto_configure command is
# better than directly invoking the ./configure command here since it will only
# override the --sysconfig argument and retain any other, benign arguments to
# the ./configure command.
# 
# If the Makefile in the source for gentoo requires you to specify build as its
# target to build it [52], you create an override_dh_auto_build target to enable
# this.
# 
# override_dh_auto_build:
#	dh_auto_build -- build
# 
# This ensures $(MAKE) is run with all the default arguments given by the
# dh_auto_build command plus the build argument.
# 
# If the Makefile in the source for gentoo requires you to specify the
# packageclean target to clean it for the Debian package instead of using
# distclean or clean targets, you can create an override_dh_auto_clean target to
# enable it.
# 
# override_dh_auto_clean:
#	$(MAKE) packageclean
# 
# If the Makefile in the source for gentoo contains a test target which you do
# not want to run for the Debian package building process, you can use an empty
# override_dh_auto_test target to skip it.
# 
# override_dh_auto_test:
# 
# If gentoo has an unusual upstream changelog file called FIXES,
# dh_installchangelogs will not install that file by default. The
# dh_installchangelogs command requires FIXES as its argument to install it.
# 
# override_dh_installchangelogs:
#	dh_installchangelogs FIXES

添加补丁

为了将补丁应用于您的源代码,您需要添加一个debian.series包含补丁名称和参数的文件,用于补丁工具,例如:

avoid_sysarg.patch -p1

配置 sources.list

在创建 .deb 包之后,您需要将仓库添加到 sources.list 文件(可能位于 /etc/apt/)中,以便使用 apt-get 安装您的包。对于以下内容,我们将假设您的项目是home:buschmann23:Cutelyst并且发行版是xUbuntu_22.04.

添加仓库签名密钥

apt-get 期望软件包仓库元数据由 GPG 密钥签名,这由构建服务自动完成。为了以安全的方式使用您的仓库,您必须导入公共仓库密钥。您可以从构建服务获取公共密钥,要么从您的项目中的密钥和证书页面,要么通过以下直接链接

https://build.opensuse.org/projects/<your project>/public_key

例如,要添加home:buschmann23:Cutelyst的密钥到您的系统,请使用以下命令

wget -qO- https://build.opensuse.org/projects/home:buschmann23:Cutelyst/public_key | sudo gpg --dearmor -o /etc/apt/keyrings/obs-home-buschmann23.gpg
Debian 及其衍生版本提高了仓库签名密钥的要求。如果您的项目仍然使用旧的 DSA 密钥,apt-get 将不会接受它,并且仓库将被标记为未签名,因此不安全。在这种情况下,您必须使用以下命令创建一个新的密钥osc signkey --create.


将仓库添加到 sources 列表

要将您的仓库添加到源列表,您必须将其附加到/etc/apt/sources.list或创建一个.list文件在/etc/apt/sources/list.d中。您可以在 sources.list(5) 中找到有关文件格式的更多信息。

如我们在上面的示例中将公共密钥存储为/etc/apt/keyrings/obs-home-buschmann23.gpg我们必须将其作为选项添加到源条目中。以上面的示例仓库为例,我们附加到/etc/apt/sources.list或作为单独的文件添加/etc/apt/sources.list.d/obs-home-buschmann23-cutelyst.list的条目必须具有以下内容

deb [signed-by=/etc/apt/keyrings/obs-home-buschmann23.gpg] https://download.opensuse.org/repositories/home:/buschmann23:/Cutelyst/xUbuntu_22.04/ ./

示例

您可以在我的主项目目录中找到示例:https://build.opensuse.org/project/show?project=home%3AEmmeG

常见陷阱

关于 packageName 的说明

RPM 包名称不像 Debian 的那样具有严格的语法。所以在上传您的归档文件之前请注意!

  • 软件包名称(源和二进制,参见 Package, Section 5.6.7)必须仅包含小写字母(a-z)、数字(0-9)、加号 (+) 和减号 (-) 符号以及句点 (.)。它们必须至少有两个字符长,并且必须以字母数字字符开头。

更多信息请参见 http://www.debian.org/doc/debian-policy/ch-controlfields.html

关于压缩格式的说明

当上游 tar 文件不是您想要使用的格式时,重新压缩服务将很有用,可以将其重新压缩为标准的 tar.gz 格式。

一个有用的例子

<services>
  <service name="download_url">
    <param name="host">master.dl.sourceforge.net</param>
    <param name="protocol">http</param>
    <param name="path">/project/someproject/somefolder/someproject.data.tar</param>
  </service>
  <service name="recompress">
    <param name="file">_service:download_url:someproject.data.tar</param>
    <param name="compression">gz</param>
  </service>
</services>

请注意 _service:download_url: 前缀,它是必需的,如果您正在重新压缩由服务下载的文件,则没有它将无法工作。

在 Web UI 中,这意味着您必须在创建条目后相应地编辑服务的参数(最初不会正确)。

关于 "postinst"(后安装)脚本的说明

如果您需要在后安装时运行一些脚本,您可以

  • 上传一个名为 debian.postinst 的文件(请参阅 "debian" 前缀),就像 debian.rules 一样
  • 将您的 package.postinst 文件(其中 "package" 是您的软件包名称)放在 debian.tar.gz 中

请参阅示例软件包 https://build.opensuse.org/package/show?package=openvas-scanner&project=security%3AOpenVAS%3ASTABLE%3Av4

Debian 文档

一些有用的 Debian 文档链接