SBT:使用sbt-native-packager构建rpm

时间:2016-08-08 10:41:40

标签: scala sbt rpm sbt-native-packager

我正在尝试使用sbt为Centos / Fedora创建rpm,我在project/plugins.sbt中添加了这个:

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.1.1")

并在build.sbt文件中:

lazy val root = (project in file(".")).
  enablePlugins(RpmPlugin).
  settings(
    scalaVersion := currentScalaVersion,
    packageName in Rpm := "MyProject",
    maintainer in Linux := "First Lastname <first.last@example.com>",
    packageArchitecture in Rpm := "noarch",
    packageSummary in Linux := "My custom package summary",
    packageDescription := "My longer package description",
    rpmRelease := "1",
    rpmVendor := "typesafe",
    rpmUrl := Some("http://www.somewhere.com"),
    rpmLicense := Some("Apache v2"),
    rpmGroup := Some("System Environment/Daemons")
  )

但是当我从命令行运行时:

$> sbt rpm:package-bin

我回来了:

[info] Building target platforms: noarch-typesafe-Linux
[info] Building for target noarch-typesafe-Linux
[info] Executing(%install): /bin/sh -e /tmp/sbt_d54063d5/rpm-tmp.giKTst
[error] + umask 022
[error] + cd /home/justdev/dev/workspace/my-project/target/rpm/BUILD
[error] + '[' /home/justdev/dev/workspace/my-project/target/rpm/buildroot '!=' / ']'
[error] + rm -rf /home/justdev/dev/workspace/my-project/target/rpm/buildroot
[error] ++ dirname /home/justdev/dev/workspace/my-project/target/rpm/buildroot
[error] + mkdir -p /home/justdev/dev/workspace/my-project/target/rpm
[error] + mkdir /home/justdev/dev/workspace/my-project/target/rpm/buildroot
[error] + '[' -e /home/justdev/dev/workspace/my-project/target/rpm/buildroot ']'
[error] + mv '/home/justdev/dev/workspace/my-project/target/rpm/tmp-buildroot/*' /home/justdev/dev/workspace/my-project/target/rpm/buildroot
[error] mv: cannot stat '/home/justdev/dev/workspace/my-project/target/rpm/tmp-buildroot/*': No such file or directory
[error] error: Bad exit status from /tmp/sbt_d54063d5/rpm-tmp.giKTst (%install)
[info] 
[info] 
[info] RPM build errors:
[error]     Bad exit status from /tmp/sbt_d54063d5/rpm-tmp.giKTst (%install)
java.lang.RuntimeException: Unable to run rpmbuild, check output for details. Errorcode 1
    at scala.sys.package$.error(package.scala:27)
    at com.typesafe.sbt.packager.rpm.RpmHelper$$anonfun$buildPackage$1.apply(RpmHelper.scala:89)
    at com.typesafe.sbt.packager.rpm.RpmHelper$$anonfun$buildPackage$1.apply(RpmHelper.scala:74)
    at sbt.IO$.withTemporaryDirectory(IO.scala:291)
    at com.typesafe.sbt.packager.rpm.RpmHelper$.buildPackage(RpmHelper.scala:74)
    at com.typesafe.sbt.packager.rpm.RpmHelper$.buildRpm(RpmHelper.scala:20)
    at com.typesafe.sbt.packager.rpm.RpmPlugin$$anonfun$projectSettings$31.apply(RpmPlugin.scala:100)
    at com.typesafe.sbt.packager.rpm.RpmPlugin$$anonfun$projectSettings$31.apply(RpmPlugin.scala:98)
    at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:35)
    at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
[error] (rpm:packageBin) Unable to run rpmbuild, check output for details. Errorcode 1

这是target/rpm/SPECS/MyProject.spec生成的:

Name: MyProject
Version: 1
Release: 1
Summary: My custom package summary
prefix: /opt
License: Apache v2
Vendor: typesafe
URL: http://www.somewhere.com
Group: System Environment/Daemons
AutoProv: yes
AutoReq: yes
BuildRoot: /home/justdev/dev/workspace/my-project/target/rpm/buildroot
BuildArch: noarch

%description
My longer package description


%install
if [ -e "$RPM_BUILD_ROOT" ]; then
  mv "/home/justdev/dev/workspace/my-project/target/rpm/tmp-buildroot"/* "$RPM_BUILD_ROOT"
else
  mv "/home/justdev/dev/workspace/my-project/target/rpm/tmp-buildroot" "$RPM_BUILD_ROOT"
fi

%files

我不确定配置中缺少什么。有什么帮助吗?

更新

这是我的新conf:

lazy val root = (project in file(".")).
  enablePlugins(JavaServerAppPackaging, RpmPlugin).
  settings(
    scalaVersion := currentScalaVersion,
    defaultLinuxInstallLocation := "/opt",
    rpmPrefix := Some("/opt"),
    linuxPackageSymlinks := Seq.empty,
    defaultLinuxLogsLocation := defaultLinuxInstallLocation + "/" + name,
    packageName in Rpm := "myproject",
    packageArchitecture in Rpm := "noarch",
    rpmRelease := "1",
    rpmVendor := "typesafe",
    rpmUrl := Some("http://www.somewhere.com"),
    rpmLicense := Some("Apache v2"),
    rpmGroup := Some("System Environment/Daemons")
  )

包现在已经构建,但由于某些目标,例如:/sbt.SettingKey$$anon$4@3d5e9842/sbt.SettingKey$$anon$4@3d5e9842/myproject/

,rpm并不完全干净

这些是我能看到的消息:

[info] Building target platforms: noarch-typesafe-Linux
[info] Building for target noarch-typesafe-Linux
[info] Executing(%install): /bin/sh -e /tmp/sbt_6e8b6db6/rpm-tmp.3IdsrH
[error] + umask 022
[error] + cd /home/justdev/dev/workspace/myproject/target/rpm/BUILD
[error] + '[' /home/justdev/dev/workspace/myproject/target/rpm/buildroot '!=' / ']'
[error] + rm -rf /home/justdev/dev/workspace/myproject/target/rpm/buildroot
[error] ++ dirname /home/justdev/dev/workspace/myproject/target/rpm/buildroot
[error] + mkdir -p /home/justdev/dev/workspace/myproject/target/rpm
[error] + mkdir /home/justdev/dev/workspace/myproject/target/rpm/buildroot
[error] + '[' -e /home/justdev/dev/workspace/myproject/target/rpm/buildroot ']'
[error] + mv /home/justdev/dev/workspace/myproject/target/rpm/tmp-buildroot/etc /home/justdev/dev/workspace/myproject/target/rpm/tmp-buildroot/opt '/home/justdev/dev/workspace/myproject/target/rpm/tmp-buildroot/sbt.SettingKey$$anon$4@272251b5' /home/justdev/dev/workspace/myproject/target/rpm/tmp-buildroot/var /home/justdev/dev/workspace/myproject/target/rpm/buildroot
[error] + /usr/lib/rpm/check-buildroot
[error] + /usr/lib/rpm/redhat/brp-compress
[error] + /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
[error] + /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
[error] + /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
[error] + /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
[error] + /usr/lib/rpm/redhat/brp-python-hardlink
[error] + /usr/lib/rpm/redhat/brp-java-repack-jars
[info] Processing files: myproject-1.b1-1.noarch
[info] Provides: myproject = 1.b1-1 config(myproject) = 1.b1-1 osgi(ch.qos.logback.classic) = 1.1.3 osgi(ch.qos.logback.core) = 1.1.3 osgi(com.typesafe.akka.actor) = 2.4.8 osgi(com.typesafe.akka.cluster) = 2.4.8 osgi(com.typesafe.akka.cluster.tools) = 2.4.8 osgi(com.typesafe.akka.contrib) = 2.4.8 osgi(com.typesafe.akka.http.core) = 2.4.8 osgi(com.typesafe.akka.http.experimental) = 2.4.8 osgi(com.typesafe.akka.http.spray.json.experimental) = 2.4.8 osgi(com.typesafe.akka.parsing) = 2.4.8 osgi(com.typesafe.akka.persistence) = 2.4.8 osgi(com.typesafe.akka.protobuf) = 2.4.8 osgi(com.typesafe.akka.remote) = 2.4.8 osgi(com.typesafe.akka.slf4j) = 2.4.8 osgi(com.typesafe.akka.stream) = 2.4.8 osgi(com.typesafe.config) = 1.3.0 osgi(com.typesafe.sslconfig) = 0.2.1 osgi(com.typesafe.sslconfig.akka) = 0.2.1 osgi(io.spray.json) = 1.3.2 osgi(org.jboss.netty) = 3.10.6 osgi(org.reactivestreams.reactive-streams) = 1.0.0 osgi(org.scala-lang.modules.scala-java8-compat) = 0.7.0 osgi(org.scala-lang.modules.scala-parser-combinators) = 1.0.4 osgi(org.scala-lang.scala-library) = 2.11.8 osgi(org.scala-lang.scala-reflect) = 2.11.8 osgi(slf4j.api) = 1.7.16
[info] Requires(interp): /bin/sh /bin/sh /bin/sh /bin/sh
[info] Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
[info] Requires(pre): /bin/sh
[info] Requires(post): /bin/sh
[info] Requires(preun): /bin/sh
[info] Requires(postun): /bin/sh
[info] Requires: osgi(com.typesafe.sslconfig)
[info] Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/justdev/dev/workspace/myproject/target/rpm/buildroot
[info] Wrote: /home/justdev/dev/workspace/myproject/target/rpm/RPMS/noarch/myproject-1.b1-1.noarch.rpm
[info] Executing(%clean): /bin/sh -e /tmp/sbt_6e8b6db6/rpm-tmp.o4ADv9
[error] + umask 022
[error] + cd /home/justdev/dev/workspace/myproject/target/rpm/BUILD
[error] + /usr/bin/rm -rf /home/justdev/dev/workspace/myproject/target/rpm/buildroot
[error] + exit 0
[success] Total time: 60 s, completed 09-Aug-2016 10:39:18

更新2

我发现在/etc/init.d/my-project中有这一行:

RUN_CMD="$exec >> sbt.SettingKey$$anon$4@3a9831db/sbt.SettingKey$$anon$4@3ea7a250/my-project/$logf‌​ile 2>&

它与logfile的路径完全相同,就像在rpm中创建的空目录一样。

1 个答案:

答案 0 :(得分:1)

我在本地重建了你的问题。似乎sbt native packager需要一种由RpmPlugin提供的格式,但它也需要archetype来定义安装时要使用的模板类型。添加原型(即JavaServerAppPackaging)可以解决问题:

lazy val root = (project in file("."))
  .enablePlugins(JavaServerAppPackaging, RpmPlugin)

结果:

[info] Set current project to rpm-test-so (in build file:/root/projects/rpm-test-so/)
> rpm:packageBin
[info] Packaging /root/projects/rpm-test-so/target/scala-2.11/rpm-test-so_2.11-1.0-sources.jar ...
[info] Done packaging.
[info] Updating {file:/root/projects/rpm-test-so/}root...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Wrote /root/projects/rpm-test-so/target/scala-2.11/rpm-test-so_2.11-1.0.pom
[info] Packaging /root/projects/rpm-test-so/target/scala-2.11/rpm-test-so_2.11-1.0-javadoc.jar ...
[info] Done packaging.
[info] Packaging /root/projects/rpm-test-so/target/scala-2.11/rpm-test-so_2.11-1.0.jar ...
[info] Done packaging.
[info] Building target platforms: x86_64-typesafe-Linux
[info] Building for target x86_64-typesafe-Linux
[info] Executing(%install): /bin/sh -e /tmp/sbt_ed611eb/rpm-tmp.KaUO17
[error] + umask 022
[error] + cd /root/projects/rpm-test-so/target/rpm/BUILD
[error] + '[' /root/projects/rpm-test-so/target/rpm/buildroot '!=' / ']'
[error] + rm -rf /root/projects/rpm-test-so/target/rpm/buildroot
[error] ++ dirname /root/projects/rpm-test-so/target/rpm/buildroot
[error] + mkdir -p /root/projects/rpm-test-so/target/rpm
[error] + mkdir /root/projects/rpm-test-so/target/rpm/buildroot
[error] + LANG=C
[error] + export LANG
[error] + unset DISPLAY
[error] + '[' -e /root/projects/rpm-test-so/target/rpm/buildroot ']'
[error] + mv /root/projects/rpm-test-so/target/rpm/tmp-buildroot/etc /root/projects/rpm-test-so/target/rpm/tmp-buildroot/usr /root/projects/r  pm-test-so/target/rpm/tmp-buildroot/var /root/projects/rpm-test-so/target/rpm/buildroot
[error] + /usr/lib/rpm/check-buildroot
[error] + /usr/lib/rpm/redhat/brp-compress
[error] + /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
[error] + /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
[error] + /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
[error] + /usr/lib/rpm/brp-python-bytecompile /usr/bin/python
[error] + /usr/lib/rpm/redhat/brp-python-hardlink
[error] + /usr/lib/rpm/redhat/brp-java-repack-jars
[info] Processing files: MyProject-1.0-1.x86_64
[info] Provides: config(MyProject) = 1.0-1
[info] Requires(interp): /bin/sh /bin/sh /bin/sh /bin/sh
[info] Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
[info] Requires(pre): /bin/sh
[info] Requires(post): /bin/sh
[info] Requires(preun): /bin/sh
[info] Requires(postun): /bin/sh
[info] Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/projects/rpm-test-so/target/rpm/buildroot
[info] Wrote: /root/projects/rpm-test-so/target/rpm/RPMS/x86_64/MyProject-1.0-1.x86_64.rpm
[info] Executing(%clean): /bin/sh -e /tmp/sbt_ed611eb/rpm-tmp.sejiSr
[error] + umask 022
[error] + cd /root/projects/rpm-test-so/target/rpm/BUILD
[error] + /bin/rm -rf /root/projects/rpm-test-so/target/rpm/buildroot
[error] + exit 0
[success] Total time: 9 s, completed Aug 9, 2016 10:06:54 AM