I was working on project in which we were having Airflow python code packaged as part of RPMs. By default rpmbuild process compiles the python files which Airflow server does not likes when it seem them. Airflow likes to compile themselves. So rpm job was to ship files which raw.
Here is complete run sheet to make rpm files using Sbt native packager and disable java jar recompress and python compilation.
Edit to file
project > plugins.sbt and add the pluginaddSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.1.1")Disable Java jar repackaging and Python compilation
Add the following file
src/main/rpm/preThe rpm pre scriplet is executed just before rpm is installed. Read more about rpm scripts at this link.
%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-java-repack-jars[[:space:]].*$!!g' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')The above script is removing the
bra-java-repack-jars and brb-python-bytecompile process from pre step of RPM installation.import RpmConstants._ maintainerScripts in Rpm := maintainerScriptsAppendFromFile((maintainerScripts in Rpm).value)( Pre -> (sourceDirectory.value / "main" / "rpm" / "pre") )
The complete
rpm.sbt is shown belowimport sbt.Keys._
import NativePackagerHelper._
enablePlugins(UniversalPlugin)
enablePlugins(RpmPlugin, RpmDeployPlugin)
maintainer in Linux := "admin@mail.com"
packageSummary in Linux := "Package code"
packageDescription := s"Application ${name.value}"
rpmVendor := "My company"
version in Rpm <<= version { (v: String) =>
v.trim.replace("-SNAPSHOT", s".${System.currentTimeMillis}")
}
rpmLicense := Option("Apache")
rpmObsoletes := Seq(s"${name.value}")
// This does not work
rpmBrpJavaRepackJars := false
defaultLinuxInstallLocation := "/var/lib/airflow"
// This allows to override the install location using RPM prefix
rpmPrefix := Some(defaultLinuxInstallLocation.value)
import RpmConstants._
// Remove all jars
mappings in Universal := (mappings in Universal).value.filterNot{
case (file, fname) => fname.endsWith(".jar")}
// Add fat jar
mappings in Universal += {
val fatJar = (assembly in Compile).value
fatJar -> s"${name.value}.jar"
}
// Copy contents of dags folder
mappings in Universal ++= directory("src/main/dags")
// Add version.txt file
mappings in Universal += {
val file = target.value / "version.txt"
IO.write(file, s"${(version in Rpm).value}")
file -> "version.txt"
}
import RpmConstants._
maintainerScripts in Rpm := maintainerScriptsAppendFromFile(
(maintainerScripts in Rpm).value)(
Pre -> (sourceDirectory.value / "main" / "rpm" / "pre")
)
publishTo <<= version { (v: String) =>
val artifactory = "https://artifactory.com/"
if (v.trim.endsWith("SNAPSHOT"))
Some("Artifactory Realm" at artifactory + "artifactory/rpm-snapshots")
else
Some("Artifactory Realm" at artifactory + "artifactory/rpm-releases/")
}Build the rpm using sbt command
rpm:packageBinTo publish the rpm use
rpm:publishReferences