0

在带有 sbt-native-packager (0.7.x) 的 Play 框架 (2.3.x) Java 项目中,如何创建客户特定的 .deb 和 .rpm 包变体?

二进制包(.deb、.zip)是使用通用设置创建的。一些客户需要根据他们的规范使用守护程序用户名或日志位置等特殊信息。我想保持通用包及其设置不变,并添加例如带有一些覆盖的新配置,以便我可以使用activator customer:packageBin.

到目前为止,我尝试的是创建一个新的 SBT 配置,它是 sbt-native-packager 的配置,因此我的有限理解应该继承它的设置和任务extendDebian然后我希望能够设置 eg daemonUser in Customer := "custom",否则使用现有的 Debian 设置。

build.sbt的示例 Play-Java 项目 ( activator newplay-java):

import NativePackagerKeys._

name := """play-java"""

version := "1.0-SNAPSHOT"

lazy val Customer = config("customer") extend(Debian)

lazy val root = (project in file("."))
    .enablePlugins(PlayJava)
    .configs(Customer)
    .settings( inConfig(Customer)(packagerSettings) : _*)

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  javaWs
)

maintainer := "Me"

packageSummary := "Example project"

packageDescription in Debian := "Longer description"

daemonUser in Customer := "custom-user"

如您所见,我现在可以设置 eg daemonUser in Customer。在 Play 控制台中,我可以看到它已正确应用inspect customer:daemonUser. 我可以用 .deb 创建一个 .deb 包activator customer:packageBin但是包几乎是空的,并且不包含应用程序:

$ dpkg-deb -c target/play-java_1.0-SNAPSHOT_all.deb 
drwxr-xr-x root/root         0 2014-10-06 22:08 ./
drwxr-xr-x root/root         0 2014-10-06 22:08 ./usr/
drwxr-xr-x root/root         0 2014-10-06 22:08 ./usr/share/
drwxr-xr-x root/root         0 2014-10-06 22:08 ./usr/share/play-java/
drwxr-xr-x root/root         0 2014-10-06 22:08 ./universal/
drwxr-xr-x root/root         0 2014-10-06 22:08 ./universal/tmp/
drwxr-xr-x root/root         0 2014-10-06 22:08 ./universal/tmp/bin/
-rw-r--r-- root/root        64 2014-10-06 22:08 ./universal/tmp/bin/debianprerm
-rw-r--r-- root/root       137 2014-10-06 22:08 ./universal/tmp/bin/debianpostinst
lrwxrwxrwx root/root         0 2014-10-06 22:08 ./usr/share/play-java/logs -> /var/log/play-java

每个客户的额外配置是可行的方式还是不像我想象的那样工作?

有没有不同的方法来实现我需要的东西,例如子项目?

4

1 回答 1

1

I’ve solved my problem with a different approach:

The customer name has to be provided as system property. Inside build.sbt I have if-then-elses wherever a customer needs a special setting.

build.sbt:

val customer = sys.props.get("customer") getOrElse ""

daemonUser in Linux := {
    customer match {
        case "customerA" => "custom-user"
        case _ => (daemonUser in Linux).value
    }
}

Then start the build with activator -Dcustomer=customerA debian:package-bin.

Advantages:

  • Everything is in one build.sbt. The if-then-elses are easy to read and it is clear what is going on.
  • You can manipulate every aspect as needed, e.g. list of files to be packaged

Disadvantages:

  • You have to run the build several times for each package variant you need.
  • The pacakge contents are not guaranteed to be identical e.g. if timestamps differ.

I’m happy so far, but if someone comes along with a better idea I’d still like to hear it.

于 2014-10-21T09:59:54.457 回答