Skip to content

Commit

Permalink
adding sbt-native-packager for #57
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyweston committed Apr 5, 2018
1 parent b9f3737 commit 0e01ac7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
9 changes: 9 additions & 0 deletions package.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enablePlugins(JavaServerAppPackaging)
enablePlugins(DebianPlugin)
enablePlugins(JDebPackaging)

maintainer := "Toby Weston <toby@temperature-machine.com>"

packageSummary := "temperature-machine"

packageDescription := """Homebrew temperature data logger based on the DS18B20 sensor."""
6 changes: 5 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ addSbtPlugin("com.47deg" %% "sbt-microsites" % "0.7.14")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.1")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.3")

libraryDependencies += "org.vafer" % "jdeb" % "1.6" artifacts (Artifact("jdeb", "jar", "jar"))
65 changes: 65 additions & 0 deletions site/src/main/tut/docs/create_debian_pkg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

## sbt-native-packager

[https://www.scala-sbt.org/sbt-native-packager](https://www.scala-sbt.org/sbt-native-packager)

Native packager only takes care of packaging, the act of putting a list of mappings (source file to install target path) into a distinct package format (zip, rpm, etc.).

Archetypes like Java Application Archetype or Java Server Application Archetype only add additional files to the mappings enriching the created package, but they don’t provide any new features for native-packager core functionality.

### Not in Scope

* Providing application lifecyle management.
* The Java Server Application Archetype provides configurations for common systeloaders like SystemV, Upstart or SystemD. However create a custome solution, which includes stop scripts, PID management, etc. are not part of native packager.
* Providing deployment configurations
* Native packager produces artefacts with the packageBin task. What you do with these is part of another step in your process.

### Core Concepts

1. [Packaging format plugins](https://www.scala-sbt.org/sbt-native-packager/introduction.html#format-plugins) - the _how_ an application is packaged; universal, linux, debian, rpm, docker, windows etc
1. [Archetype plugins](https://www.scala-sbt.org/sbt-native-packager/introduction.html#archetype-plugins) - the _what_ gets packaged (incs. predefined configurations); java application, java server application, system loaders etc
1. [Mappings](https://www.scala-sbt.org/sbt-native-packager/introduction.html#mappings) - map source files to target system locations

## Folder Structures

Each packaging format will expect files to include in your package to be in a specific folder. For example, the Universal plugin will look in `src\universal` by default.


## Packaging

### Java

Running `sbt universal:packageBin` would copy anything in `src\universal` into the generated zip file but without adding the Java format plugin, no class files would be included (so the zip would basically be empty).

Include `enablePlugins(JavaApplicationPlugin)` and it will copy in all the JARs (including the application). It also creates default startup scripts which, for us, are no good. They're close; they create an executable (and batch file) for each `App` and a general one to take care of the classpath etc.

So you'll get something like the following.

total 80
drwxr-xr-x 9 toby staff 288 5 Apr 11:15 ./
drwxr-xr-x 4 toby staff 128 5 Apr 11:15 ../
-rwxr-xr-x 1 toby staff 1388 5 Apr 11:15 client*
-rw-r--r-- 1 toby staff 110 5 Apr 11:15 client.bat
-rwxr-xr-x 1 toby staff 1388 5 Apr 11:15 server*
-rw-r--r-- 1 toby staff 110 5 Apr 11:15 server.bat
-rwxr-xr-x 1 toby staff 11484 5 Apr 11:15 temperature-machine*
-rw-r--r-- 1 toby staff 7530 5 Apr 11:15 temperature-machine.bat

Where `client` for example, ends up running the following.

# execute the main start script
$SCRIPTPATH/temperature-machine -main bad.robot.temperature.client.Client "$@"

...and `temperature-machine` handles classpath and Java setup etc.

Including 'enablePlugins(JavaServerAppPackaging)' adds some additional stuff.

### Debian

I think the control file will be defaulted if you don't override it (override by adding into `src\debian\DEBIAN`).

Package with `sbt debian:packageBin`.

When the `.deb` package is built, the same scripts are created in `temperature-machine_2.1-SNAPSHOT_all.deb/data/usr/bin`.

The "log" folder seems to default to `/var/lig/temperature-machine` although I don't know what will go in there.

0 comments on commit 0e01ac7

Please sign in to comment.