From e894cfe07fbc466e2ada70738ffbed5487610eb9 Mon Sep 17 00:00:00 2001 From: Carsten Saathoff Date: Wed, 12 Oct 2016 17:11:43 +0200 Subject: [PATCH 1/4] First try at #572. Config files from the `universal/conf` directory are correctly marked as `noconfig`, but `/etc/default` files provided by JavaServerApp archetype not. --- .../packager/linux/LinuxNoReplacePlugin.scala | 24 ++++++++ src/sbt-test/rpm/config-no-replace/build.sbt | 57 +++++++++++++++++++ .../rpm/config-no-replace/project/plugins.sbt | 1 + .../config-no-replace/src/universal/conf/test | 1 + src/sbt-test/rpm/config-no-replace/test | 7 +++ 5 files changed, 90 insertions(+) create mode 100644 src/main/scala/com/typesafe/sbt/packager/linux/LinuxNoReplacePlugin.scala create mode 100644 src/sbt-test/rpm/config-no-replace/build.sbt create mode 100644 src/sbt-test/rpm/config-no-replace/project/plugins.sbt create mode 100644 src/sbt-test/rpm/config-no-replace/src/universal/conf/test create mode 100644 src/sbt-test/rpm/config-no-replace/test diff --git a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxNoReplacePlugin.scala b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxNoReplacePlugin.scala new file mode 100644 index 000000000..f578df4cc --- /dev/null +++ b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxNoReplacePlugin.scala @@ -0,0 +1,24 @@ +package com.typesafe.sbt.packager.linux + +import com.typesafe.sbt.packager.rpm.RpmPlugin +import com.typesafe.sbt.packager.rpm.RpmPlugin.autoImport +import sbt._ + +/** + * Created by carsten on 12.10.16. + */ +object LinuxNoReplacePlugin extends AutoPlugin with LinuxKeys { + override def requires = RpmPlugin + + override def projectSettings = inConfig(autoImport.Rpm)(Seq( + linuxPackageMappings := configWithNoReplace(linuxPackageMappings.value), + makeEtcDefault := makeEtcDefault.value + )) + + def configWithNoReplace(mappings: Seq[LinuxPackageMapping]): Seq[LinuxPackageMapping] = { + mappings.map { + case mapping if mapping.fileData.config != "false" => mapping.withConfig("noreplace") + case mapping => mapping + } + } +} diff --git a/src/sbt-test/rpm/config-no-replace/build.sbt b/src/sbt-test/rpm/config-no-replace/build.sbt new file mode 100644 index 000000000..1f5838e0a --- /dev/null +++ b/src/sbt-test/rpm/config-no-replace/build.sbt @@ -0,0 +1,57 @@ +import com.typesafe.sbt.packager.archetypes.JavaServerAppPackaging +import com.typesafe.sbt.packager.archetypes.systemloader.SystemVPlugin +import com.typesafe.sbt.packager.linux.{LinuxNoReplacePlugin, _} +import com.typesafe.sbt.packager.rpm.RpmPlugin + +enablePlugins(JavaServerAppPackaging, RpmPlugin, LinuxNoReplacePlugin) + +name := "rpm-test" + +version := "0.1.0" + +maintainer := "Josh Suereth " + +packageSummary := "Test rpm package" + +packageDescription := """A fun package description of our software, + with multiple lines.""" + +rpmRelease := "1" + +rpmVendor := "typesafe" + +rpmUrl := Some("http://github.com/sbt/sbt-native-packager") + +rpmLicense := Some("BSD") + +packageArchitecture in Rpm := "x86_64" + +TaskKey[Unit]("unzip") <<= (packageBin in Rpm, streams) map { (rpmFile, streams) => + val rpmPath = Seq(rpmFile.getAbsolutePath) + Process("rpm2cpio", rpmPath) #| Process("cpio -i --make-directories") ! streams.log +} + +TaskKey[Unit]("checkSpecFile") <<= (target, streams) map { (target, out) => + val spec = IO.read(target / "rpm" / "SPECS" / "rpm-test.spec") + + assert( + spec contains + "%files\n%dir %attr(0755,root,root) /usr/share/rpm-test/conf", + "Contains configuration directory." + ) + + assert( + spec contains + "%config(noreplace) %attr(0644,root,root) /usr/share/rpm-test/conf/test", + "Sets config to 'noreplace'" + ) + + assert( + spec contains + "%config(noreplace) %attr(0644,root,root) /etc/default/rpm-test", + "Sets config to 'noreplace'" + ) + + out.log.success("Successfully tested rpm test file") + () +} diff --git a/src/sbt-test/rpm/config-no-replace/project/plugins.sbt b/src/sbt-test/rpm/config-no-replace/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/rpm/config-no-replace/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/rpm/config-no-replace/src/universal/conf/test b/src/sbt-test/rpm/config-no-replace/src/universal/conf/test new file mode 100644 index 000000000..92e38dfb2 --- /dev/null +++ b/src/sbt-test/rpm/config-no-replace/src/universal/conf/test @@ -0,0 +1 @@ +# Test configuration file! diff --git a/src/sbt-test/rpm/config-no-replace/test b/src/sbt-test/rpm/config-no-replace/test new file mode 100644 index 000000000..e6620db76 --- /dev/null +++ b/src/sbt-test/rpm/config-no-replace/test @@ -0,0 +1,7 @@ +# Run the debian packaging. +> rpm:package-bin +$ exists target/rpm/RPMS/x86_64/rpm-test-0.1.0-1.x86_64.rpm + +> unzip + +> checkSpecFile \ No newline at end of file From 2f5678789fbc7b42ceaf2f29d1babee87175a0dc Mon Sep 17 00:00:00 2001 From: Carsten Saathoff Date: Thu, 13 Oct 2016 13:00:49 +0200 Subject: [PATCH 2/4] Added a RpmConfigNoReplacePlugin that depends on the Rpm and ServerAppPackaging plugins. It marks all config files as "noreplace" in the RPM, thus preventing them from being replaced during updates. The main method was added to the LinuxMappingDSL and can also be used in build.sbt for non server projects. --- .../sbt/packager/linux/LinuxMappingDSL.scala | 16 +++++++ .../packager/linux/LinuxNoReplacePlugin.scala | 24 ---------- .../linux/RpmNoReplaceConfigPlugin.scala | 18 +++++++ .../rpm/config-no-replace-dsl/build.sbt | 48 +++++++++++++++++++ .../config-no-replace-dsl/project/plugins.sbt | 1 + .../src/universal/conf/test | 1 + src/sbt-test/rpm/config-no-replace-dsl/test | 7 +++ src/sbt-test/rpm/config-no-replace/build.sbt | 13 ++--- .../packager/linux/LinuxMappingDSLSpec.scala | 26 ++++++++++ 9 files changed, 121 insertions(+), 33 deletions(-) delete mode 100644 src/main/scala/com/typesafe/sbt/packager/linux/LinuxNoReplacePlugin.scala create mode 100644 src/main/scala/com/typesafe/sbt/packager/linux/RpmNoReplaceConfigPlugin.scala create mode 100644 src/sbt-test/rpm/config-no-replace-dsl/build.sbt create mode 100644 src/sbt-test/rpm/config-no-replace-dsl/project/plugins.sbt create mode 100644 src/sbt-test/rpm/config-no-replace-dsl/src/universal/conf/test create mode 100644 src/sbt-test/rpm/config-no-replace-dsl/test create mode 100644 src/test/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSLSpec.scala diff --git a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSL.scala b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSL.scala index 346423d4d..f70da76e9 100644 --- a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSL.scala +++ b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSL.scala @@ -32,6 +32,22 @@ trait LinuxMappingDSL { (src, dest) <- dirs path <- (src ***).get } yield path -> path.toString.replaceFirst(src.toString, dest) + + /** + * This method sets the config attribute of all files that are marked as configuration files to "noreplace". This is + * relevant for RPM packages as it controls the behaviour of RPM updates. + * + * See: http://www-uxsup.csx.cam.ac.uk/~jw35/docs/rpm_config.html + * + * @param mappings list of mappings to update + * @return updated list of mappings + */ + def configWithNoReplace(mappings: Seq[LinuxPackageMapping]): Seq[LinuxPackageMapping] = { + mappings.map { + case mapping if mapping.fileData.config != "false" => mapping.withConfig("noreplace") + case mapping => mapping + } + } } object Mapper extends LinuxMappingDSL diff --git a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxNoReplacePlugin.scala b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxNoReplacePlugin.scala deleted file mode 100644 index f578df4cc..000000000 --- a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxNoReplacePlugin.scala +++ /dev/null @@ -1,24 +0,0 @@ -package com.typesafe.sbt.packager.linux - -import com.typesafe.sbt.packager.rpm.RpmPlugin -import com.typesafe.sbt.packager.rpm.RpmPlugin.autoImport -import sbt._ - -/** - * Created by carsten on 12.10.16. - */ -object LinuxNoReplacePlugin extends AutoPlugin with LinuxKeys { - override def requires = RpmPlugin - - override def projectSettings = inConfig(autoImport.Rpm)(Seq( - linuxPackageMappings := configWithNoReplace(linuxPackageMappings.value), - makeEtcDefault := makeEtcDefault.value - )) - - def configWithNoReplace(mappings: Seq[LinuxPackageMapping]): Seq[LinuxPackageMapping] = { - mappings.map { - case mapping if mapping.fileData.config != "false" => mapping.withConfig("noreplace") - case mapping => mapping - } - } -} diff --git a/src/main/scala/com/typesafe/sbt/packager/linux/RpmNoReplaceConfigPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/linux/RpmNoReplaceConfigPlugin.scala new file mode 100644 index 000000000..9d48f20e4 --- /dev/null +++ b/src/main/scala/com/typesafe/sbt/packager/linux/RpmNoReplaceConfigPlugin.scala @@ -0,0 +1,18 @@ +package com.typesafe.sbt.packager.linux + +import com.typesafe.sbt.packager.archetypes.JavaServerAppPackaging +import com.typesafe.sbt.packager.rpm.RpmPlugin +import com.typesafe.sbt.packager.rpm.RpmPlugin.autoImport +import sbt._ + +/** + * This plugin automatically updates all config files in a RPM to "noreplace". Those files will not be overwritten + * during an update if they have been changed on disk. This is useful for server apps. + */ +object RpmNoReplaceConfigPlugin extends AutoPlugin with LinuxKeys with LinuxMappingDSL { + override def requires = JavaServerAppPackaging && RpmPlugin + + override def projectSettings = inConfig(autoImport.Rpm)(Seq( + linuxPackageMappings := configWithNoReplace(linuxPackageMappings.value) + )) +} diff --git a/src/sbt-test/rpm/config-no-replace-dsl/build.sbt b/src/sbt-test/rpm/config-no-replace-dsl/build.sbt new file mode 100644 index 000000000..b6cb49ad3 --- /dev/null +++ b/src/sbt-test/rpm/config-no-replace-dsl/build.sbt @@ -0,0 +1,48 @@ +enablePlugins(RpmPlugin) + +name := "rpm-test" + +version := "0.1.0" + +maintainer := "Josh Suereth " + +packageSummary := "Test rpm package" + +packageDescription := """A fun package description of our software, + with multiple lines.""" + +rpmRelease := "1" + +rpmVendor := "typesafe" + +rpmUrl := Some("http://github.com/sbt/sbt-native-packager") + +rpmLicense := Some("BSD") + +packageArchitecture in Rpm := "x86_64" + +linuxPackageMappings := configWithNoReplace(linuxPackageMappings.value) + +TaskKey[Unit]("unzip") <<= (packageBin in Rpm, streams) map { (rpmFile, streams) => + val rpmPath = Seq(rpmFile.getAbsolutePath) + Process("rpm2cpio", rpmPath) #| Process("cpio -i --make-directories") ! streams.log +} + +TaskKey[Unit]("checkSpecFile") <<= (target, streams) map { (target, out) => + val spec = IO.read(target / "rpm" / "SPECS" / "rpm-test.spec") + + assert( + spec contains + "%files\n%dir %attr(0755,root,root) /usr/share/rpm-test/conf", + "Contains configuration directory." + ) + + assert( + spec contains + "%config(noreplace) %attr(0644,root,root) /usr/share/rpm-test/conf/test", + "Sets custom config to 'noreplace'" + ) + + out.log.success("Successfully tested rpm test file") + () +} diff --git a/src/sbt-test/rpm/config-no-replace-dsl/project/plugins.sbt b/src/sbt-test/rpm/config-no-replace-dsl/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/rpm/config-no-replace-dsl/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/rpm/config-no-replace-dsl/src/universal/conf/test b/src/sbt-test/rpm/config-no-replace-dsl/src/universal/conf/test new file mode 100644 index 000000000..92e38dfb2 --- /dev/null +++ b/src/sbt-test/rpm/config-no-replace-dsl/src/universal/conf/test @@ -0,0 +1 @@ +# Test configuration file! diff --git a/src/sbt-test/rpm/config-no-replace-dsl/test b/src/sbt-test/rpm/config-no-replace-dsl/test new file mode 100644 index 000000000..e6620db76 --- /dev/null +++ b/src/sbt-test/rpm/config-no-replace-dsl/test @@ -0,0 +1,7 @@ +# Run the debian packaging. +> rpm:package-bin +$ exists target/rpm/RPMS/x86_64/rpm-test-0.1.0-1.x86_64.rpm + +> unzip + +> checkSpecFile \ No newline at end of file diff --git a/src/sbt-test/rpm/config-no-replace/build.sbt b/src/sbt-test/rpm/config-no-replace/build.sbt index 1f5838e0a..796052032 100644 --- a/src/sbt-test/rpm/config-no-replace/build.sbt +++ b/src/sbt-test/rpm/config-no-replace/build.sbt @@ -1,9 +1,4 @@ -import com.typesafe.sbt.packager.archetypes.JavaServerAppPackaging -import com.typesafe.sbt.packager.archetypes.systemloader.SystemVPlugin -import com.typesafe.sbt.packager.linux.{LinuxNoReplacePlugin, _} -import com.typesafe.sbt.packager.rpm.RpmPlugin - -enablePlugins(JavaServerAppPackaging, RpmPlugin, LinuxNoReplacePlugin) +enablePlugins(RpmNoReplaceConfigPlugin) name := "rpm-test" @@ -43,13 +38,13 @@ TaskKey[Unit]("checkSpecFile") <<= (target, streams) map { (target, out) => assert( spec contains "%config(noreplace) %attr(0644,root,root) /usr/share/rpm-test/conf/test", - "Sets config to 'noreplace'" + "Sets custom config to 'noreplace'" ) assert( spec contains - "%config(noreplace) %attr(0644,root,root) /etc/default/rpm-test", - "Sets config to 'noreplace'" + "%config(noreplace) %attr(644,root,root) /etc/default/rpm-test", + "Sets /etc/default/rpm-test to 'noreplace'" ) out.log.success("Successfully tested rpm test file") diff --git a/src/test/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSLSpec.scala b/src/test/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSLSpec.scala new file mode 100644 index 000000000..323122b0a --- /dev/null +++ b/src/test/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSLSpec.scala @@ -0,0 +1,26 @@ +package com.typesafe.sbt.packager.linux + +import java.io.File + +import org.scalatest.{Matchers, WordSpec} + +/** + * Created by carsten on 13.10.16. + */ +class LinuxMappingDSLSpec + extends WordSpec + with Matchers with LinuxMappingDSL { + + "The LinuxMappingDSL" should { + + "map config files to noreplace" in { + val f1 = LinuxPackageMapping(Map(new File("/tmp/1") -> "/tmp/1")) + val f2 = LinuxPackageMapping(Map(new File("/tmp/1") -> "/tmp/1")).withConfig() + + val f1Mapped :: f2Mapped :: Nil = configWithNoReplace(Seq(f1, f2)) + + f1Mapped.fileData.config should be ("false") + f2Mapped.fileData.config should be ("noreplace") + } + } +} From e45d1b42ee3307c9c2668da555a83e1922f3b286 Mon Sep 17 00:00:00 2001 From: Carsten Saathoff Date: Thu, 13 Oct 2016 16:42:20 +0200 Subject: [PATCH 3/4] Fixed formatting. --- .../rpm/override-start-script-systemd/build.sbt | 2 +- .../rpm/override-start-script-systemv/build.sbt | 2 +- .../rpm/override-start-script-upstart/build.sbt | 2 +- .../sbt/packager/linux/LinuxMappingDSLSpec.scala | 11 +++-------- .../sbt/packager/universal/ZipHelperSpec.scala | 8 ++------ version.sbt | 2 +- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/sbt-test/rpm/override-start-script-systemd/build.sbt b/src/sbt-test/rpm/override-start-script-systemd/build.sbt index 6822bd36e..feed54a6b 100644 --- a/src/sbt-test/rpm/override-start-script-systemd/build.sbt +++ b/src/sbt-test/rpm/override-start-script-systemd/build.sbt @@ -33,4 +33,4 @@ TaskKey[Unit]("checkStartupScript") <<= (target, streams) map { (target, out) => val script = IO.read(file("usr/lib/systemd/system/rpm-test.service")) assert(script.startsWith("# right systemd template"), s"override script wasn't picked, script is\n$script") () -} \ No newline at end of file +} diff --git a/src/sbt-test/rpm/override-start-script-systemv/build.sbt b/src/sbt-test/rpm/override-start-script-systemv/build.sbt index dc9d810f9..10781fda8 100644 --- a/src/sbt-test/rpm/override-start-script-systemv/build.sbt +++ b/src/sbt-test/rpm/override-start-script-systemv/build.sbt @@ -33,4 +33,4 @@ TaskKey[Unit]("checkStartupScript") <<= (target, streams) map { (target, out) => val script = IO.read(file("etc/init.d/rpm-test")) assert(script.startsWith("# right systemv template"), s"override script wasn't picked, script is\n$script") () -} \ No newline at end of file +} diff --git a/src/sbt-test/rpm/override-start-script-upstart/build.sbt b/src/sbt-test/rpm/override-start-script-upstart/build.sbt index 760c2f56d..564431b93 100644 --- a/src/sbt-test/rpm/override-start-script-upstart/build.sbt +++ b/src/sbt-test/rpm/override-start-script-upstart/build.sbt @@ -33,4 +33,4 @@ TaskKey[Unit]("checkStartupScript") <<= (target, streams) map { (target, out) => val script = IO.read(file("etc/init/rpm-test.conf")) assert(script.startsWith("# right upstart template"), s"override script wasn't picked, script is\n$script") () -} \ No newline at end of file +} diff --git a/src/test/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSLSpec.scala b/src/test/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSLSpec.scala index 323122b0a..64d1a9f7a 100644 --- a/src/test/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSLSpec.scala +++ b/src/test/scala/com/typesafe/sbt/packager/linux/LinuxMappingDSLSpec.scala @@ -4,12 +4,7 @@ import java.io.File import org.scalatest.{Matchers, WordSpec} -/** - * Created by carsten on 13.10.16. - */ -class LinuxMappingDSLSpec - extends WordSpec - with Matchers with LinuxMappingDSL { +class LinuxMappingDSLSpec extends WordSpec with Matchers with LinuxMappingDSL { "The LinuxMappingDSL" should { @@ -19,8 +14,8 @@ class LinuxMappingDSLSpec val f1Mapped :: f2Mapped :: Nil = configWithNoReplace(Seq(f1, f2)) - f1Mapped.fileData.config should be ("false") - f2Mapped.fileData.config should be ("noreplace") + f1Mapped.fileData.config should be("false") + f2Mapped.fileData.config should be("noreplace") } } } diff --git a/src/test/scala/com/typesafe/sbt/packager/universal/ZipHelperSpec.scala b/src/test/scala/com/typesafe/sbt/packager/universal/ZipHelperSpec.scala index f6a9fb269..0d6882802 100644 --- a/src/test/scala/com/typesafe/sbt/packager/universal/ZipHelperSpec.scala +++ b/src/test/scala/com/typesafe/sbt/packager/universal/ZipHelperSpec.scala @@ -4,15 +4,11 @@ import com.typesafe.sbt.packager._ import com.typesafe.sbt.packager.permissions import org.scalatest._ import java.io.File -import java.nio.file.{Path, Paths, Files} +import java.nio.file.{Files, Path, Paths} import java.nio.file.attribute.PosixFilePermission._ import scala.collection.JavaConversions._ -class ZipHelperSpec - extends WordSpec - with Matchers - with BeforeAndAfterEach - with BeforeAndAfterAll { +class ZipHelperSpec extends WordSpec with Matchers with BeforeAndAfterEach with BeforeAndAfterAll { var tmp: Path = _ val toDelete = scala.collection.mutable.ListBuffer[Path]() diff --git a/version.sbt b/version.sbt index 7bc4f283b..a8bd390a4 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "1.2.0-SNAPSHOT" \ No newline at end of file +version in ThisBuild := "1.2.0-SNAPSHOT" From b0ace7f35a0fa87c912c093067d4f73059a857e3 Mon Sep 17 00:00:00 2001 From: Carsten Saathoff Date: Sat, 15 Oct 2016 19:39:38 +0200 Subject: [PATCH 4/4] Removed RpmConfigNoReplace plugin in favour of the DSL. Added docs for the DSL. --- .../linux/RpmNoReplaceConfigPlugin.scala | 18 ------- .../rpm/config-no-replace-dsl/build.sbt | 48 ------------------- .../config-no-replace-dsl/project/plugins.sbt | 1 - .../src/universal/conf/test | 1 - src/sbt-test/rpm/config-no-replace-dsl/test | 7 --- src/sbt-test/rpm/config-no-replace/build.sbt | 10 ++-- src/sphinx/formats/rpm.rst | 15 ++++++ 7 files changed, 18 insertions(+), 82 deletions(-) delete mode 100644 src/main/scala/com/typesafe/sbt/packager/linux/RpmNoReplaceConfigPlugin.scala delete mode 100644 src/sbt-test/rpm/config-no-replace-dsl/build.sbt delete mode 100644 src/sbt-test/rpm/config-no-replace-dsl/project/plugins.sbt delete mode 100644 src/sbt-test/rpm/config-no-replace-dsl/src/universal/conf/test delete mode 100644 src/sbt-test/rpm/config-no-replace-dsl/test diff --git a/src/main/scala/com/typesafe/sbt/packager/linux/RpmNoReplaceConfigPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/linux/RpmNoReplaceConfigPlugin.scala deleted file mode 100644 index 9d48f20e4..000000000 --- a/src/main/scala/com/typesafe/sbt/packager/linux/RpmNoReplaceConfigPlugin.scala +++ /dev/null @@ -1,18 +0,0 @@ -package com.typesafe.sbt.packager.linux - -import com.typesafe.sbt.packager.archetypes.JavaServerAppPackaging -import com.typesafe.sbt.packager.rpm.RpmPlugin -import com.typesafe.sbt.packager.rpm.RpmPlugin.autoImport -import sbt._ - -/** - * This plugin automatically updates all config files in a RPM to "noreplace". Those files will not be overwritten - * during an update if they have been changed on disk. This is useful for server apps. - */ -object RpmNoReplaceConfigPlugin extends AutoPlugin with LinuxKeys with LinuxMappingDSL { - override def requires = JavaServerAppPackaging && RpmPlugin - - override def projectSettings = inConfig(autoImport.Rpm)(Seq( - linuxPackageMappings := configWithNoReplace(linuxPackageMappings.value) - )) -} diff --git a/src/sbt-test/rpm/config-no-replace-dsl/build.sbt b/src/sbt-test/rpm/config-no-replace-dsl/build.sbt deleted file mode 100644 index b6cb49ad3..000000000 --- a/src/sbt-test/rpm/config-no-replace-dsl/build.sbt +++ /dev/null @@ -1,48 +0,0 @@ -enablePlugins(RpmPlugin) - -name := "rpm-test" - -version := "0.1.0" - -maintainer := "Josh Suereth " - -packageSummary := "Test rpm package" - -packageDescription := """A fun package description of our software, - with multiple lines.""" - -rpmRelease := "1" - -rpmVendor := "typesafe" - -rpmUrl := Some("http://github.com/sbt/sbt-native-packager") - -rpmLicense := Some("BSD") - -packageArchitecture in Rpm := "x86_64" - -linuxPackageMappings := configWithNoReplace(linuxPackageMappings.value) - -TaskKey[Unit]("unzip") <<= (packageBin in Rpm, streams) map { (rpmFile, streams) => - val rpmPath = Seq(rpmFile.getAbsolutePath) - Process("rpm2cpio", rpmPath) #| Process("cpio -i --make-directories") ! streams.log -} - -TaskKey[Unit]("checkSpecFile") <<= (target, streams) map { (target, out) => - val spec = IO.read(target / "rpm" / "SPECS" / "rpm-test.spec") - - assert( - spec contains - "%files\n%dir %attr(0755,root,root) /usr/share/rpm-test/conf", - "Contains configuration directory." - ) - - assert( - spec contains - "%config(noreplace) %attr(0644,root,root) /usr/share/rpm-test/conf/test", - "Sets custom config to 'noreplace'" - ) - - out.log.success("Successfully tested rpm test file") - () -} diff --git a/src/sbt-test/rpm/config-no-replace-dsl/project/plugins.sbt b/src/sbt-test/rpm/config-no-replace-dsl/project/plugins.sbt deleted file mode 100644 index b53de154c..000000000 --- a/src/sbt-test/rpm/config-no-replace-dsl/project/plugins.sbt +++ /dev/null @@ -1 +0,0 @@ -addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/rpm/config-no-replace-dsl/src/universal/conf/test b/src/sbt-test/rpm/config-no-replace-dsl/src/universal/conf/test deleted file mode 100644 index 92e38dfb2..000000000 --- a/src/sbt-test/rpm/config-no-replace-dsl/src/universal/conf/test +++ /dev/null @@ -1 +0,0 @@ -# Test configuration file! diff --git a/src/sbt-test/rpm/config-no-replace-dsl/test b/src/sbt-test/rpm/config-no-replace-dsl/test deleted file mode 100644 index e6620db76..000000000 --- a/src/sbt-test/rpm/config-no-replace-dsl/test +++ /dev/null @@ -1,7 +0,0 @@ -# Run the debian packaging. -> rpm:package-bin -$ exists target/rpm/RPMS/x86_64/rpm-test-0.1.0-1.x86_64.rpm - -> unzip - -> checkSpecFile \ No newline at end of file diff --git a/src/sbt-test/rpm/config-no-replace/build.sbt b/src/sbt-test/rpm/config-no-replace/build.sbt index 796052032..b6cb49ad3 100644 --- a/src/sbt-test/rpm/config-no-replace/build.sbt +++ b/src/sbt-test/rpm/config-no-replace/build.sbt @@ -1,4 +1,4 @@ -enablePlugins(RpmNoReplaceConfigPlugin) +enablePlugins(RpmPlugin) name := "rpm-test" @@ -21,6 +21,8 @@ rpmLicense := Some("BSD") packageArchitecture in Rpm := "x86_64" +linuxPackageMappings := configWithNoReplace(linuxPackageMappings.value) + TaskKey[Unit]("unzip") <<= (packageBin in Rpm, streams) map { (rpmFile, streams) => val rpmPath = Seq(rpmFile.getAbsolutePath) Process("rpm2cpio", rpmPath) #| Process("cpio -i --make-directories") ! streams.log @@ -41,12 +43,6 @@ TaskKey[Unit]("checkSpecFile") <<= (target, streams) map { (target, out) => "Sets custom config to 'noreplace'" ) - assert( - spec contains - "%config(noreplace) %attr(644,root,root) /etc/default/rpm-test", - "Sets /etc/default/rpm-test to 'noreplace'" - ) - out.log.success("Successfully tested rpm test file") () } diff --git a/src/sphinx/formats/rpm.rst b/src/sphinx/formats/rpm.rst index fedd293ab..5e8c7b0ef 100644 --- a/src/sphinx/formats/rpm.rst +++ b/src/sphinx/formats/rpm.rst @@ -359,3 +359,18 @@ For more information on this topic follow these links: .. _OpenSuse issue: https://github.com/sbt/sbt-native-packager/issues/215 .. _RPM Scaladocs: http://www.scala-sbt.org/sbt-native-packager/latest/api/#com.typesafe.sbt.packager.rpm.RpmPlugin$$Names$ .. _MaintainerScriptHelper Scaladocs: http://www.scala-sbt.org/sbt-native-packager/latest/api/#com.typesafe.sbt.packager.MaintainerScriptHelper$ + + +Marking config files as ``noreplace`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +By default, rpm replaces config files on disk when the content has changed between two version. Often, this is not desirable +as configurations are often customized and should not change during updates. rpm provides a means to turn of the default behaviour +by marking config files as ``noreplace`` in the spec file. In order to enable this for the build, we provide a helper method that +can be used to modify all config file mappings: + +.. code-block:: scala + + linuxPackageMappings := configWithNoReplace(linuxPackageMappings.value) + +This will mark all config files as ``noreplace`` and prevent them from being changed during updates. \ No newline at end of file