Skip to content

Commit

Permalink
Don't compress debian packages (#787)
Browse files Browse the repository at this point in the history
Also allow custom options to dpkg-deb --build
  • Loading branch information
pauldraper authored and muuki88 committed May 10, 2016
1 parent ae04b90 commit cee091c
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
(maintainerScripts in Debian).value,
(linuxScriptReplacements in Debian).value,
(target in Universal).value
)
),
debianNativeBuildOptions := Nil
)

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ trait DebianKeys {
val debianMakeChownReplacements = TaskKey[(String, String)]("debianMakeChownReplacements", "Creates the chown commands for correct own files and directories")

val debianPackageInstallSize = TaskKey[Long]("debian-installed-size")

val debianNativeBuildOptions = SettingKey[Seq[String]]("debian-native-build-options", "Options passed to dpkg-deb, e.g. compression level")
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ trait DebianNativePackaging extends DebianPluginLike {
* package.
*/
private[debian] def debianNativeSettings: Seq[Setting[_]] = inConfig(Debian)(Seq(
debianNativeBuildOptions += "-Znone", // packages are largely JARs, which are already compressed
genChanges <<= (packageBin, target, debianChangelog, name, version, debianPackageMetadata) map {
(pkg, tdir, changelog, name, version, data) =>
changelog match {
Expand Down Expand Up @@ -81,12 +82,12 @@ trait DebianNativePackaging extends DebianPluginLike {
},

/** Implementation of the actual packaging */
packageBin <<= (debianExplodedPackage, debianMD5sumsFile, debianSection, debianPriority, name, version, packageArchitecture, target, streams) map {
(pkgdir, _, section, priority, name, version, arch, tdir, s) =>
packageBin <<= (debianExplodedPackage, debianMD5sumsFile, debianSection, debianPriority, name, version, packageArchitecture, debianNativeBuildOptions, target, streams) map {
(pkgdir, _, section, priority, name, version, arch, options, tdir, s) =>
s.log.info("Building debian package with native implementation")
// Make the package. We put this in fakeroot, so we can build the package with root owning files.
val archive = archiveFilename(name, version, arch)
Process(Seq("fakeroot", "--", "dpkg-deb", "--build", pkgdir.getAbsolutePath, "../" + archive), Some(tdir)) ! s.log match {
Process(Seq("fakeroot", "--", "dpkg-deb", "--build") ++ options ++ Seq(pkgdir.getAbsolutePath, "../" + archive), Some(tdir)) ! s.log match {
case 0 => ()
case x => sys.error("Failure packaging debian file. Exit code: " + x)
}
Expand Down
14 changes: 14 additions & 0 deletions src/sbt-test/debian/native-build-compress/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enablePlugins(DebianPlugin)

debianNativeBuildOptions in Debian := Nil

maintainer := "Maintainer <[email protected]>"

packageDescription := "Description"

packageSummary := "Summary"

TaskKey[Unit]("check-deb-compression") := {
val deb = target.value / s"${(name in Debian).value}_${(version in Debian).value}_all.deb"
assert(Seq("ar", "-t", deb.toString).lines.exists(_.startsWith("data.tar."))) // exact extension varies by dpkg-deb version
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
2 changes: 2 additions & 0 deletions src/sbt-test/debian/native-build-compress/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> debian:packageBin
> check-deb-compression
12 changes: 12 additions & 0 deletions src/sbt-test/debian/native-build-default/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
enablePlugins(DebianPlugin)

maintainer := "Maintainer <[email protected]>"

packageDescription := "Description"

packageSummary := "Summary"

TaskKey[Unit]("check-deb-compression") := {
val deb = target.value / s"${(name in Debian).value}_${(version in Debian).value}_all.deb"
assert(Seq("ar", "-t", deb.toString).lines.contains("data.tar"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
2 changes: 2 additions & 0 deletions src/sbt-test/debian/native-build-default/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> debian:packageBin
> check-deb-compression
15 changes: 15 additions & 0 deletions src/sphinx/formats/debian.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ Enable the debian plugin to activate the native package implementation.
enablePlugins(DebianPlugin)
Native packaging
~~~~~~~~~~~~~~~~

Since JARs are by default already compressed, `DebianPlugin` disables additional compression of the debian package
contents.

To compress the debian package, override `debianNativeBuildOptions` with
`options <http://man7.org/linux/man-pages/man1/dpkg-deb.1.html>`_ for `dpkg-deb`.

.. code-block:: scala
debianNativeBuildOptions in Debian := Nil // dpkg-deb's default compression (currently xz)
debianNativeBuildOptions in Debian := Seq("-Zgzip", "-z3") // gzip compression at level 3
Java based packaging
~~~~~~~~~~~~~~~~~~~~

Expand Down

7 comments on commit cee091c

@jpic
Copy link
Contributor

@jpic jpic commented on cee091c Jun 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is not supported by debian wheezy's python-apt module: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=718330

So, installing it with something like ansible or whatever using python-apt will crash with something like : No debian package found, missing data.tar.{gz,xz,lzma,bz2}

I should have been fixed in python-apt 0.9.3.4, which is available in jessie, but wheezy is stuck in 8.8 and I haven't found no official backport.

@muuki88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info. Do you think a hint in the docs would be helpful? Wheezy will be supported for two more years and I'm not sure if this an edge case or could be a common problem.

@jpic
Copy link
Contributor

@jpic jpic commented on cee091c Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO a hint in the docs would be extremely helpful to pure developers who do not have the chance to work in a DevOps environment, ie. developers with absolutely no idea how to debug this kind of problem with the service command and no available die hard linux nerd able to help, because they will read all the docs you have published, in my experience, which is BTW one of my favourite features of the java community heh I've been trying to dissuade my user from not using sbt-native-packager but on the other hand they "just want to start a jar service" so that seems to be an extremely common use-case. TBH I'm a completely newbie in the java ecosystem and I can't tell if it's really feasible for one package like sbt-native-packager to cover all sub-use cases or if it would be the right thing to do. After all, we can also install an init script from an ansible role.

Edge or common honnestly IDK, how much of your userbase have wheezy in production ? It seemed little to me when I wrote the above comment, but with your feedback now I tend to think there might be a ton or two. Java is, after all, extremely well supported on this platform which suggests that there might be a huge community of sbt-native-packager + wheezy + python-apt users. I've seen more and more companies encouraging java and ops/python teams to work together the last years, and so far I've had nothing but brilliant feedback, python/linux people (both communities are already unioning on ansible) learn from java people and vice-versa, so I'd say that this might become trendy, and I'd suspect there would be growing demand. Albeit one would say it's a bit unusual to consider support for such a case of using a modern tool (python-apt|ansible) on an old distro version to be a requirement for forward compatibility with the growing demand, but is this discussion going to the point where we're going to consider this as a regression ?!!

I do imagine that a lot if not most users with a mostly java-developer background, and not necessarily a linux background, who love the service script generated by sbt-native-package, like it's the case here (bonjour from Paris !).

@muuki88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the detailed explanation.

IMHO a hint in the docs would be extremely helpful to pure developers who do not have the chance to work in a DevOps environment

TBH I have no really a clue what the main user group of native-packager is, but in doubt, I would rather add a hint in the docs. Would you like to make a small pull-request, adding the necessary information to fix this?

I've seen more and more companies encouraging java and ops/python teams to work together the last years

great to hear :) More languages and a broader background usually tend to improve code quality in all languages and create a more open mindset.

@muuki88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who love the service script generated by sbt-native-package, like it's the case here (bonjour from Paris !)

Always good to hear that our work is appreciated :)

@jpic
Copy link
Contributor

@jpic jpic commented on cee091c Jun 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #811, thanks a heap for sharing some of your insight !

@muuki88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for sharing as well 😃 and helping to make this project again a bit more user friendly

Please sign in to comment.