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

ash support documentation #652

Merged
merged 1 commit into from
Aug 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 $@
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

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

I fear this won't be enough. You have to create the ash template. Something like

bashScriptTemplateLocation := {
   // generate the file, so it can be found
   val script = (target in Universal) / "tmp" / "ash-start-script"
   val content = .. // getResource from internal 
   // fill in the contents from the interally shipped jar
   IO.write(script, content)
   // return this as template location
   script
}

Copy link
Author

Choose a reason for hiding this comment

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

I'm afraid I'm confused on this point. I've got something like this in makeUniversalAshScript() in file AshScriptPlugin.scala. I've built it locally and it seems to work great for a project that consumes this feature. Looks like this:

      val template = resolveTemplate(defaultTemplateLocation)
      val scriptBits = JavaAppAshScript.generateScript(defines, template)
      val script = tmpDir / "tmp" / "bin" / name   // fine since this is an ash-specific archetype
      IO.write(script, scriptBits)
      script.setExecutable(true)
      Some(script)

On a separate note, I'm not sure why one of the tests is failing. I'll check but I don't think this is anything I modified. Perhaps I pulled something I shouldn't?

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 =
Expand Down
21 changes: 21 additions & 0 deletions src/sphinx/formats/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.