Skip to content

Instantly share code, notes, and snippets.

@fommil
Created July 8, 2015 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fommil/91b4097c0130b7ffa13d to your computer and use it in GitHub Desktop.
Save fommil/91b4097c0130b7ffa13d to your computer and use it in GitHub Desktop.
Example sbt-native-packager RPM
// plugins
import com.typesafe.sbt.packager.archetypes.JavaServerAppPackaging
import com.typesafe.sbt.packager.rpm.RpmPlugin
// the things that are available by magic in .sbt files
import com.typesafe.sbt.SbtNativePackager._
import com.typesafe.sbt.SbtNativePackager.autoImport.NativePackagerKeys._
// additional helpers
import com.typesafe.sbt.packager.linux.Mapper._
// quick deploy instructions:
//
// sbt rpm:package-bin
// scp target/rpm/RPMS/x86_64/thing-1.0.0_SNAPSHOT-1.x86_64.rpm remote:
//
// sudo yum --nogpgcheck install jdk-8u45-linux-x64.rpm
// sudo yum --nogpgcheck install thing-1.0.0_SNAPSHOT-1.x86_64.rpm
//
// ...
settings (
// PACKAGING
// https://github.com/sbt/sbt-native-packager/blob/master/src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala
// https://github.com/sbt/sbt-native-packager/blob/master/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala
// http://www.scala-sbt.org/sbt-native-packager/formats/universal.html
// http://www.scala-sbt.org/sbt-native-packager/archetypes/java_server/customize.html
// http://www.scala-sbt.org/sbt-native-packager/formats/rpm.html
name := "thing",
defaultLinuxInstallLocation := "/opt",
mainClass in Compile := Some("thing.with.the.Thing"), // needed to generate the script
// WORKAROUND: https://github.com/sbt/sbt-native-packager/issues/619
// see bundled src/templates/start
// WORKAROUND: https://github.com/sbt/sbt-native-packager/issues/620
defaultLinuxLogsLocation := defaultLinuxInstallLocation.value + "/" + packageName.value + "/logs",
linuxPackageMappings += packageTemplateMapping(defaultLinuxLogsLocation.value)().
withUser((daemonUser in Linux).value).
withGroup((daemonGroup in Linux).value),
linuxPackageMappings := linuxPackageMappings.value.filterNot { m =>
m.mappings.find(_._2 == (defaultLinuxLogsLocation.value + "/" + packageName.value )).isDefined
},
// provides programmatic values for src/templates/etc-default
linuxScriptReplacements := {
val orig = linuxScriptReplacements.value.toMap
orig ++ Seq(
("config_dir", defaultLinuxConfigLocation.value),
("logs_dir", defaultLinuxLogsLocation.value),
// WORKAROUND https://github.com/sbt/sbt-native-packager/issues/621
("control-functions", orig("control-functions").replace(" --system", "").replace("--no-create-home",""))
// can't use `javaOptions` here because of sbt limitations
)}.toSeq,
bashScriptExtraDefines += """addJava "-Dlogback.configurationFile=${LOGBACK_FILE}"""",
bashScriptExtraDefines += """addJava "-Dlogs.dir=${LOGS_DIR}"""",
bashScriptExtraDefines += """addJava "-Dthing.props.location=${CONFIG_FILE}"""",
bashScriptExtraDefines += """addJava "-Dcom.sun.management.jmxremote.port=${JMX_PORT}"""",
rpmVendor := "Thingymabob",
rpmLicense := Some("Proprietary"),
packageArchitecture in Rpm := "x86_64",
rpmRequirements += "jdk1.8.0_45",
rpmPost := None // disables starting the server on install
) enablePlugins (
// these import some Keys using magic that I don't understand
JavaServerAppPackaging,
RpmPlugin
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment