Giter Site home page Giter Site logo

sbt-native-packager-examples's Introduction

Goal

This is a small collection of sbt-native-packager examples. Each example is very small and should be easy to understand. Pick the ones you need and tailor your packaging process.

Not all examples are 100% tested. Just open an issue if something doesn't work

Examples

Currently all examples are tested for Debian only. Feel free to correct and contribute.

Application configuration

Your application has an external configuration, which you want to change and the application should pick up this changes.

Requirements

How it's done

Typesafe config uses the system property config.file to pass in a configuration location. So you don't need to add a folder to the classpath, which could be a potential security risk.

Project

You can find a working example at application-conf

Log4j configuration

This is related to the Application configuration. This time we use log4j.

Requirements

  • Linux OS (debian/rpm)
  • Log4j 2 (works in a similar way with 1.x)

How it's done

Log4j uses the system property log4j.configurationFile to pass in a configuration location. So you don't need to add a folder to the classpath, which could be a potential security risk.

Log4j 2 as also a cool auto reconfigurate feature, which can come in very handy.

Project

You can find a working example at log4j-conf

Custom Startup Parameters

A small example how to configure your startup parameters with SBT Native Packager. You'll see how to add java system properties and application arguments. We also change the -Xmx and -Xms settings.

Requirements

  • Linux OS (debian/rpm)

How it's done

Create a file src/templates/etc-default and fill it with the content you need.

Project

You can find a working example at startscript-parameters

Links

sbt-native-packager-examples's People

Contributors

dacr avatar hstraub avatar intracer avatar muuki88 avatar nornagon avatar ryanberckmans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sbt-native-packager-examples's Issues

dynamic-mappings loads env from environment, not config file

The the dynamic mappings example project doesn't actually load the env value from the config files, instead it loads from the environment variable directly. The simplest way to see this to run sbt -Denv=prod run in the terminal and note that the output This package runs in prod is not what would be expected as prod.conf sets env = production and not env = prod.

Are there any examples of jar packing?

How to run, is there an example of jar, and directory public dev,test,prod environment example?Thank you very much

So let's do packageJar

I don't know how to change this phase example

sbt

testPackage / Universal / packageBin
stagePackage / Universal / packageBin
prodPackage / Universal / packageBin

Using variables in application.ini files

I am new to sbt-native-packager. I see examples in sbt-native-packager-examples with variables using in application.ini file (simple-web-example). Docs says:

This file currently doesn’t has any variable substitution. We recommend using the build.sbt if you need any information from your build. docs

I've tried to use application.ini with variables and it doesn't work variables are not substituted.

simple-rpm fails on Suse Leap 42.1

Unfortunately I see this error:

info] Loading project definition from /home/andreas/dev/sbt-native-packager-examples/simple-rpm/project                  
[info] Updating {file:/home/andreas/dev/sbt-native-packager-examples/simple-rpm/project/}simple-rpm-build...              
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] downloading https://jcenter.bintray.com/org/ow2/asm/asm/5.0.3/asm-5.0.3.jar ...                                    
[info]  [SUCCESSFUL ] org.ow2.asm#asm;5.0.3!asm.jar (236ms)                                                               
[info] downloading https://jcenter.bintray.com/org/ow2/asm/asm-commons/5.0.3/asm-commons-5.0.3.jar ...
[info]  [SUCCESSFUL ] org.ow2.asm#asm-commons;5.0.3!asm-commons.jar (224ms)
[info] downloading https://jcenter.bintray.com/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.jar ...
[info]  [SUCCESSFUL ] org.ow2.asm#asm-tree;5.0.3!asm-tree.jar (168ms)
[info] Done updating.
[info] Set current project to simple-rpm (in build file:/home/andreas/dev/sbt-native-packager-examples/simple-rpm/)
> rpm:packageBin
[info] Wrote /home/andreas/dev/sbt-native-packager-examples/simple-rpm/target/scala-2.10/simple-rpm_2.10-1.0.pom
[info] Building target platforms: noarch-mukis.de, Muki-Linux
[info] Building for target noarch-mukis.de
[info] Executing(%install): /bin/sh -e /tmp/sbt_9368df18/rpm-tmp.MShUFI
[error] + umask 022
[error] + cd /home/andreas/dev/sbt-native-packager-examples/simple-rpm/target/rpm/BUILD
[error] + '[' -e /home/andreas/dev/sbt-native-packager-examples/simple-rpm/target/rpm/buildroot ']'
[error] + mv /home/andreas/dev/sbt-native-packager-examples/simple-rpm/target/rpm/tmp-buildroot/etc /home/andreas/dev/sbt-native-packager-examples/simple-rpm/target/rpm/tmp-buildroot/usr /home/andreas/dev/sbt-native-packager-examples/simple-rpm/target/rpm/tmp-buildroot/var /home/andreas/dev/sbt-native-packager-examples/simple-rpm/target/rpm/buildroot
[error] + /usr/lib/rpm/brp-compress
[error] + /usr/lib/rpm/brp-strip /usr/bin/strip
[error] + /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip
[error] /tmp/sbt_9368df18/rpm-tmp.MShUFI: line 39: /usr/lib/rpm/brp-strip-static-archive: No such file or directory
[error] error: Bad exit status from /tmp/sbt_9368df18/rpm-tmp.MShUFI (%install)
[error]     Bad exit status from /tmp/sbt_9368df18/rpm-tmp.MShUFI (%install)
[info] 
[info] 
[info] RPM build errors:
[trace] Stack trace suppressed: run last rpm:packageBin for the full output.
[error] (rpm:packageBin) Unable to run rpmbuild, check output for details. Errorcode 1
[error] Total time: 0 s, completed Feb 3, 2016 2:45:52 PM

As I try already for a some hours, is the RPM Build with 1.0 working at all?

Remove root artifact from multi project build

These examples helped me a lot with working out how to setup a multi project build. I was missing the dependsOn on the root project which makes a big difference.

However there is one thing that I was hoping this example would include which is: how to exclude the artifact from the root project?

In multi-module-build if I run universal:packageBin and look in the lib folder within the ZIP there is still that pesky de.mukis.mukis-fullstack-1.0.jar which has nothing but a MANIFEST.

Porting my sbt to sbt-native-packager

Thank you @muuki88 for your nice work, can you help me port the following sbt to native-packager?

import com.typesafe.sbt.SbtAspectj._
import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._

// my normal sbt stuff ....

libraryDependencies ~= { _.map(_.exclude("org.slf4j", "slf4j-simple")) }

aspectjSettings

javaOptions in (run) <++= AspectjKeys.weaverOptions in Aspectj

javaOptions in (run) ++= Seq(
  "-Djava.library.path=src/main/resources/sigar",
  "-javaagent:" + System.getProperty("user.home") + s"/.ivy2/cache/org.jolokia/jolokia-jvm/jars/jolokia-jvm-1.2.2-agent.jar=port=8181",
//"-XX:+ExtendedDTraceProbes"
  "-Xms128m",
  "-Xmx3G"
)

val buildSettings = Defaults.defaultSettings ++ Seq(
  javaOptions += "-Xmx3G"
)

mainClass in Compile := Some("ir.behrad.adp.boot.Run")

packageArchetype.akka_application

Revolver.settings.settings

mappings in Universal <+= (packageBin in Compile, sourceDirectory ) map { (_, src) =>
  val conf = src / "main" / "resources" / "application.conf"
  conf -> "conf/application.conf"
}
  1. I am using SbtAspectj to weave aspectJ and don't know how to integrate him with native-packager ?

  2. I don't know how to add my jvm options without duplicating them to a conf/jvmopts

  3. I read sbt/sbt-native-packager#375 but didn't find the relation to sbt stage. Should I move my src/main/resources/sigar to where so that native-packager adds it?

simle-rpm fails with error

I tried simple-rpm project and it fails with error. Please advice how to fix

[error] + umask 022
[error] + cd /opt/sbt-native-packager-examples/simple-rpm/target/rpm/BUILD
[error] + '[' /opt/sbt-native-packager-examples/simple-rpm/target/rpm/buildroot '!=' / ']'
[error] + rm -rf /opt/sbt-native-packager-examples/simple-rpm/target/rpm/buildroot
[error] ++ dirname /opt/sbt-native-packager-examples/simple-rpm/target/rpm/buildroot
[error] + mkdir -p /opt/sbt-native-packager-examples/simple-rpm/target/rpm
[error] + mkdir /opt/sbt-native-packager-examples/simple-rpm/target/rpm/buildroot
[error] + LANG=C
[error] + export LANG
[error] + unset DISPLAY
[error] + '[' -e /opt/sbt-native-packager-examples/simple-rpm/target/rpm/buildroot ']'
[error] + mv /opt/sbt-native-packager-examples/simple-rpm/target/rpm/tmp-buildroot/etc /opt/sbt-native-packager-examples/simple-rpm/target/rpm/tmp-buildroot/usr /opt/sbt-native-packager-examples/simple-rpm/target/rpm/tmp-buildroot/var /opt/sbt-native-packager-examples/simple-rpm/target/rpm/buildroot
[error] + /usr/lib/rpm/check-buildroot
[error] + /usr/lib/rpm/amazon/brp-compress
[error] + /usr/lib/rpm/amazon/brp-strip /usr/bin/strip
[error] + /usr/lib/rpm/amazon/brp-strip-static-archive /usr/bin/strip
[error] + /usr/lib/rpm/amazon/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
[error] + /usr/lib/rpm/brp-python-bytecompile
[error] + /usr/lib/rpm/amazon/brp-python-hardlink
[error] + /usr/lib/rpm/amazon/brp-python-shebang
[error] + /usr/lib/rpm/amazon/brp-java-repack-jars

packageBin on non-root projects

On the example multi-module-build, we are using the 'sbt universal:packageBin' on the root project.
Can you make a example of building each module separately (create 3 zip, one for each project)

I want to be able to do something like: 'sbt backend/universal:packageBin' ?
Because i'm trying an equivalent thing on my projects and i'm getting:

[error] No such setting/task
[error] universal:packageBin

Override environment-specific settings when root module isn't container of source code

Following your documented example for overriding settings by using sub-modules, how can this be adapted for a slightly more complex project topology, like:

lazy val app = project
  .in(file("mainProject"))
  .settings(
    name := "my-app",
    libraryDependencies += "com.typesafe" % "config" % "1.3.0"
  )

lazy val stagePackage = project
  .in(file("build/stage"))
  .enablePlugins(JavaAppPackaging)
  .settings(
    resourceDirectory in Compile := (resourceDirectory in (app, Compile)).value,
    mappings in Universal += {
      ((resourceDirectory in Compile).value / "stage.conf") -> "conf/application.conf"
    }
  )
  .dependsOn(app)

I'm guessing because your example contains src/main in the root directory, any sub project is able to find the main class. But I am getting: [warn] You have no main class in your project. No start script will be generated.

I think this is due to the fact that my source code is in: mainProject/src/main/. This is because, in addition to mainProject, I have a scalajs project as well. So is there a way to create submodules not depending on root?

When I print: println((scalaSource in Compile).value.absolutePath) it is:

/me/git/test-service/build/stage/src/main/scala

but needs to be:

/me/git/test-service/mainProject/src/main/scala

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.