Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RpmNoReplaceplugin and LinuxMappingDSL for "noreplace" configs #896

Merged
merged 5 commits into from
Nov 2, 2016
Merged

RpmNoReplaceplugin and LinuxMappingDSL for "noreplace" configs #896

merged 5 commits into from
Nov 2, 2016

Conversation

kodemaniak
Copy link
Contributor

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.

Fixes #572.

* 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not convinced of my initial idea implementing this as an autoplugin. It only makes sense when enabled by default and for debian as well.

This will break backwards compatibility, which I usually prefer to avoid. If you can make a good case ( maybe some best practices, blog posts on this issue? ) I'm fine with adding this.

From a code perspective:

  • instead of extending the LinuxKeys use the "global" Keys object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is not enabled by default. Only when I explicitly use the plugin it will change the behaviour, so I don't see backwards compatibility being broken. However, using the helper from the DSL is definitely more explicit, and you don't save too much boilerplate by using the plugin. So I am also fine in removing the plugin and using only the helper.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess starting with the helper is enough. We can make this a default later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I remove the plugin for now. And I'll add some docs then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. When you have added some docs this is ready to be merged. Thanks for your time and patience :)

/**
* Created by carsten on 13.10.16.
*/
class LinuxMappingDSLSpec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Have you run sbt test:scalafmt on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, yes :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

@@ -312,13 +312,14 @@ case class RpmSpec(meta: RpmMetadata,
if (symlinks.isEmpty)
None
else {
val checkUninstall = "if [ $1 -eq 0 ] ;\nthen"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is from #894 . Can you remove this from the PR when #894 is merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that slipped in, I thought I created the branch based on master. I'll try to fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the commit from the pull request.

Carsten Saathoff and others added 4 commits October 13, 2016 16:29
…re correctly marked as `noconfig`, but `/etc/default` files provided by JavaServerApp archetype not.
…pPackaging 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.
@kodemaniak
Copy link
Contributor Author

I removed the plugin and added some docs. Please let me know if any further changes are required.

Copy link
Contributor

@muuki88 muuki88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM.

@kodemaniak
Copy link
Contributor Author

I just realized that the /etc/default/<package-name> mapping is still not set to noreplace by using the DSL. Is that one somehow added in the end? My assumption was that the auto plugins are executed before any modifications are made from the build.sbt.

@muuki88
Copy link
Contributor

muuki88 commented Oct 26, 2016

Ah. This is as scoping issue. The server archetype scopes the etc default template to Rpm and Debian. To fix this you need to use the correct scoped linuxPackageMappings.

linuxPackageMappings in Rpm := ...

@muuki88
Copy link
Contributor

muuki88 commented Oct 30, 2016

Ah... hmm.. updating adds a merge commit. Let's see how that plays out when using the "squash & merge" button.

@muuki88 muuki88 added the rpm label Oct 31, 2016
@muuki88 muuki88 merged commit b751818 into sbt:master Nov 2, 2016
@kodemaniak kodemaniak deleted the linux-no-replace-plugin branch November 17, 2016 10:09
@kodemaniak
Copy link
Contributor Author

I finally had the time to try it out, but when I scope the linuxPackageMappings to Rpm, then /etc/default/<package-name> is completely gone.

@muuki88
Copy link
Contributor

muuki88 commented Nov 19, 2016

I can confirm this ( for rpm ATM ). It seems a lot of things are missing when linuxPackageMappings in Rpm := configWithNoReplace(linuxPackageMappings.value) is added.

The spec file without the configurationin thetest-project-simple`.

%files
%attr(0755,root,root) /usr/share/test-project-simple/bin/test-project-simple
%config %attr(0644,root,root) /usr/share/test-project-simple/conf/application.ini
%attr(0644,root,root) /usr/share/test-project-simple/lib/default.test-project-simple-0.2.0.jar
%attr(0644,root,root) /usr/share/test-project-simple/lib/org.scala-lang.scala-library-2.10.6.jar
%attr(0644,root,root) /usr/share/test-project-simple/lib/com.typesafe.config-1.2.1.jar
%dir %attr(755,test-project-simple,test-project-simple) /var/log/test-project-simple
%config %attr(644,root,root) /etc/default/test-project-simple
%dir %attr(755,test-project-simple,test-project-simple) /var/run/test-project-simple
%config %attr(0644,root,root) /usr/lib/systemd/system/test-project-simple.service

And this is with the configWithNoReplace

%attr(0755,root,root) /usr/share/test-project-simple/bin/test-project-simple
%config(noreplace) %attr(0644,root,root) /usr/share/test-project-simple/conf/application.ini
%attr(0644,root,root) /usr/share/test-project-simple/lib/default.test-project-simple-0.2.0.jar
%attr(0644,root,root) /usr/share/test-project-simple/lib/org.scala-lang.scala-library-2.10.6.jar
%attr(0644,root,root) /usr/share/test-project-simple/lib/com.typesafe.config-1.2.1.jar
%dir %attr(755,test-project-simple,test-project-simple) /var/log/test-project-simple

For me, this look like a more general bug and not in your implementation.

@muuki88
Copy link
Contributor

muuki88 commented Nov 19, 2016

Sorry. This is again, a configuration issue.

If you replace the linuxPackageMappings in Rpm you must use same as an input.

linuxPackageMappings in Rpm := configWithNoReplace((linuxPackageMappings in Rpm).value)

Would you mind making a small PR and add this to the docs?

@kodemaniak
Copy link
Contributor Author

Just fixed the docs:

#920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants