为 Debian 打包 Go 应用程序 [英] Packaging Go application for Debian
问题描述
如何将我的 Go 二进制文件放入 Debian 包中?由于 Go 是静态链接的,我只有一个可执行文件——我不需要很多复杂的项目元数据信息.有没有一种简单的方法来打包可执行文件和资源文件,而不需要经历 debuild
的创伤?
How can I put my Go binary into a Debian package? Since Go is statically linked, I just have a single executable--I don't need a lot of complicated project metadata information. Is there a simple way to package the executable and resource files without going through the trauma of debuild
?
我已经到处寻找现有的问题;然而,我所有的研究都出现了关于包含 golang 开发环境的 .deb 文件的问题/答案(即,如果你执行 sudo apt-get install golang-go
会得到什么).
I've looked all over for existing questions; however, all of my research turns up questions/answers about a .deb file containing the golang development environment (i.e., what you would get if you do sudo apt-get install golang-go
).
推荐答案
嗯.我认为 debuild
的唯一创伤"是它在构建包之后运行 lintian
,而 lintian
试图发现你的问题包.
Well. I think the only "trauma" of debuild
is that it runs lintian
after building the package, and it's lintian
who tries to spot problems with your package.
所以有两种方法可以对抗这种情况:
So there are two ways to combat the situation:
- 不要使用
debuild
:这个工具只调用dpkg-buildpackage
,它确实做了必要的力量举.构建二进制包的常用调用是dpkg-buildpackage -us -uc -b
.您仍然可以出于其他目的调用debuild
,例如debuild clean
. - 添加所谓的"lintian override",可以用来制作
lintian
对 selected 包的问题视而不见,你坚持认为这些问题不是问题.
- Do not use
debuild
: this tool merely callsdpkg-buildpackage
which really does the necessary powerlifting. The usual call to build a binary package isdpkg-buildpackage -us -uc -b
. You still might calldebuild
for other purposes, likedebuild clean
for instance. - Add the so-called "lintian override" which can be used to make
lintian
turn a blind eye to selected problems with your package which, you insist, are not problems.
这两种方法都意味着您不要尝试通过打包工具构建您的应用程序,而是将其视为只是包装到包中的 blob.这需要稍微避免 debian/rules
的正常工作方式(不尝试构建任何东西).
Both approaches imply that you do not attempt to build your application by the packaging tools but rather treat it as a blob which is just wrapped to a package. This would require slightly abstraining from the normal way debian/rules
work (to not attempt to build anything).
另一个可能可能的解决方案(并且实际上更像 Debian-ish)是尝试使用 gcc-go
(加上 gold
用于链接):因为它是一个 GCC 前端,所以这个工具会生成一个动态链接的应用程序(它链接到 libgo
或类似的东西).我个人还没有使用它的经验,并且只有在您打算尝试将您的软件包推送到 Debian 中时才会考虑使用它.
Another solution which might be possible (and is really way more Debian-ish) is to try to use gcc-go
(plus gold
for linking): since it's a GCC front-end, this tool produces a dynamically-linked application (which links against libgo
or something like this). I, personally, have no experience with it yet, and would only consider using it if you intend to try to push your package into the Debian proper.
关于为 Debian 打包 Go 程序的一般问题,您可能会发现以下资源很有用:
Regarding the general question of packaging Go programs for Debian, you might find the following resources useful:
- 此线程 由 Go for Debian 打包程序之一发起.
- 特别是,该线程中的第一篇文章链接到关于 debian 的 此讨论-开发.
- debian-devel 上关于同一问题的第二个线程(这是合乎逻辑的继续前一个线程).
- This thread started on go-nuts by one of Go for Debian packagers.
- In particular, the first post in that thread links to this discussion on debian-devel.
- The second thread on debian-devel regarding that same problem (it's a logical continuation of the former thread).
更新于 2015 年 10 月 15 日.
Update on 2015-10-15.
(由于这篇文章似乎仍在被人们搜索、发现和研究,我决定更新它以更好地反映当前的事态.)
(Since this post appears to still be searched and found and studied by people I've decided to update it to better reflec the current state of affairs.)
从那时起,打包 Go 应用程序和软件包的情况得到了显着改善,并且可以使用经典"Go(所谓的 gc
套件源自 Google)构建 Debian 软件包,而不是gcc-go
.并且还有一个很好的包基础设施.
Since then the situation with packaging Go apps and packages got improved dramatically, and it's possible to build a Debian package using "classic" Go (the so-called gc
suite originating from Google) rather than gcc-go
.
And there exist a good infrastructure for packages as well.
现在在对 Go 程序进行 debian 化时使用的关键工具是 dh-golang
,在此处.
The key tool to use when debianizing a Go program now is dh-golang
described here.
这篇关于为 Debian 打包 Go 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!