From 250ae60881ae2a7aa9a1e7c7b74160bfba140d76 Mon Sep 17 00:00:00 2001 From: Greg Zoller Date: Fri, 14 Aug 2015 17:31:45 -0500 Subject: [PATCH] ash support documentation plus default ash-template --- .../sbt/packager/archetypes/ash-template | 36 +++++++++++++++++++ .../packager/archetypes/AshScriptPlugin.scala | 7 ++-- src/sphinx/formats/docker.rst | 21 +++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/com/typesafe/sbt/packager/archetypes/ash-template diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/ash-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/ash-template new file mode 100644 index 000000000..80eaa4635 --- /dev/null +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/ash-template @@ -0,0 +1,36 @@ +#!/bin/sh + +realpath () { +( + TARGET_FILE="$1" + + cd "$(dirname "$TARGET_FILE")" + TARGET_FILE=$(basename "$TARGET_FILE") + + COUNT=0 + while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ] + do + TARGET_FILE=$(readlink "$TARGET_FILE") + cd "$(dirname "$TARGET_FILE")" + TARGET_FILE=$(basename "$TARGET_FILE") + COUNT=$(($COUNT + 1)) + done + + if [ "$TARGET_FILE" == "." -o "$TARGET_FILE" == ".." ]; then + cd "$TARGET_FILE" + TARGET_FILEPATH= + else + TARGET_FILEPATH=/$TARGET_FILE + fi + + echo "$(pwd -P)/$TARGET_FILE" +) +} + +real_script_path="$(realpath "$0")" +app_home="$(realpath "$(dirname "$real_script_path")")" +lib_dir="$(realpath "${app_home}/../lib")" + +${{template_declares}} + +java -classpath $app_classpath $app_mainclass $@ diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/AshScriptPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/AshScriptPlugin.scala index 1fa9502db..eb926ef2c 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/AshScriptPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/AshScriptPlugin.scala @@ -73,15 +73,14 @@ import SbtNativePackager.{ Universal, Debian } */ object AshScriptPlugin extends AutoPlugin { - val bashTemplate = "bash-template" - override def requires = JavaAppPackaging - //object autoImport extends JavaAppKeys - import JavaAppPackaging.autoImport._ + val ashTemplate = "ash-template" + override def projectSettings = Seq( + bashScriptTemplateLocation := (sourceDirectory.value / "templates" / ashTemplate), makeBashScript <<= (bashScriptTemplateLocation, bashScriptDefines, target in Universal, executableScriptName, sourceDirectory) map makeUniversalAshScript, bashScriptDefines <<= (Keys.mainClass in (Compile, bashScriptDefines), scriptClasspath in bashScriptDefines, bashScriptExtraDefines, bashScriptConfigLocation) map { (mainClass, cp, extras, config) => val hasMain = diff --git a/src/sphinx/formats/docker.rst b/src/sphinx/formats/docker.rst index e7530eeb4..8d841637f 100644 --- a/src/sphinx/formats/docker.rst +++ b/src/sphinx/formats/docker.rst @@ -254,3 +254,24 @@ Now let's start adding some Docker commands. ExecCmd("CMD", "echo", "Hello, World from Docker") ) +Busybox/Ash Support +~~~~~~~~~~~~~~~~~~~ + +The default shell support for the Java archetype (JavaAppPackaging) is bash, with a Windows +bat file also generated. Busybox is a popular minimal Docker base image that uses ash, a much +more limited shell than bash. The result is that if you build a Docker image for Busybox the +generated bash launch script will likely not work. + +Optionally you can use an ash-compatible archetype that derives from JavaAppPacking called +AshScriptPlugin. Enable this by including: + +.. code-block:: scala + + enablePlugins(AshScriptPlugin) + +With this plugin enabled an ash-compatible launch script will be generated in your Docker image. + +Just like for JavaAppPackaging you have the option of overriding the default script by supplying +your own src/templates/ash-template file. When overriding the file don't forget to include +${{template_declares}} somewhere to populate $app_classpath $app_mainclass from your sbt project. +You'll likely need these to launch your program.