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

AshScriptPlugin with DockerPlugin does not correctly pass arguments #1332

Closed
JLofgren opened this issue Apr 23, 2020 · 1 comment · Fixed by #1334
Closed

AshScriptPlugin with DockerPlugin does not correctly pass arguments #1332

JLofgren opened this issue Apr 23, 2020 · 1 comment · Fixed by #1334

Comments

@JLofgren
Copy link

JLofgren commented Apr 23, 2020

Expected behaviour

Given this basic program that prints its command lines arguments and the length of the argument list:

object Hello {
  def main(args: Array[String]): Unit = {
    val formattedArgs = args.toList.map(arg => s"'$arg'").toString
    println(s"argsLength=${args.length}, args=$formattedArgs")
  }
}

The program is packaged as a docker container with AshScriptPlugin:

sbt docker:publishLocal

When the program is run with no arguments, the program should print an args length of 0 and an empty list:

$ docker run sbt-native-packager-ashscriptplugin-bug:0.1.0-SNAPSHOT
argsLength=0, args=List()

And when called with two arguments, the program should print an args length of 2 and a list with the two arguments:

$ docker run sbt-native-packager-ashscriptplugin-bug:0.1.0-SNAPSHOT --foo bar
argsLength=2, args=List('--foo', 'bar')

Actual behaviour

The length of the argument list is always 1.

In the case where no arguments are given, the argument list passed to the app is a list of one empty string:

$ docker run sbt-native-packager-ashscriptplugin-bug:0.1.0-SNAPSHOT
argsLength=1, args=List('')

In the case of two arguments, the argument list is one string containing a space-separated list of the arguments with a leading space:

$ docker run sbt-native-packager-ashscriptplugin-bug:0.1.0-SNAPSHOT --foo bar
argsLength=1, args=List(' --foo bar')

Information

  • What sbt-native-packager are you using
    • 1.7.0
  • What sbt version
    • 1.3.9
  • What is your build system (e.g. Ubuntu, MacOS, Windows, Debian )
    • MacOS
  • What package are you building (e.g. docker, rpm, ...)
    • docker
  • What version has your build tool (find out with e.g. rpm --version)
$ docker version
Client: Docker Engine - Community
 Version:           19.03.8
...
Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  • What is your target system (e.g. Ubuntu 16.04, CentOS 7)
    • docker base image openjdk:11-jre

Example

This bug is reproduced in: https://github.com/JLofgren/sbt-native-packager-ashscriptplugin-bug

@muuki88
Copy link
Contributor

muuki88 commented Apr 27, 2020

Hi @JLofgren and thanks for the very well written bug report.

I can reproduce the error and this doesn't look right. The reason for this is very likely some (b)ash quoting thing. I'm very bad at writing or debugging these things 😬

Here is the ash template: https://github.com/sbt/sbt-native-packager/blob/master/src/main/resources/com/typesafe/sbt/packager/archetypes/scripts/ash-template

And this is an sbt test that demonstrates how to override it.

You could fiddle around with the script until you found the cause 👍 Pull requests welcome or anything else that helps to solve this ❤️

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

Successfully merging a pull request may close this issue.

2 participants