From 4c190b9d1c36d2e8ff0d477af17badecfd997e68 Mon Sep 17 00:00:00 2001 From: Martijn Riemers Date: Fri, 24 Jul 2015 18:59:48 +0200 Subject: [PATCH] Added CombinedCmd and removed EnvCmd I added CombinedCmd for ONBUILD instruction and possible future commands that will be added that will have a similar form. For readability I made it so that it uses a CmdLike object as an argument. Cmd could also be used with an extra argument but it would degrade readability. Removed ENV because it introduced an inconsistency with ADD and COPY. Made `Cmd` accept multiple arguments because this solves the ADD and ENV issue. This fix won't break the old api because a string with a space in the middle is still acceptable only less readable. --- .../sbt/packager/docker/dockerfile.scala | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/dockerfile.scala b/src/main/scala/com/typesafe/sbt/packager/docker/dockerfile.scala index 0492b47dc..46ae54bd1 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/dockerfile.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/dockerfile.scala @@ -44,22 +44,38 @@ case class ExecCmd(cmd: String, args: String*) extends CmdLike { * * @example * {{{ - * val add = Cmd("ADD", "src/resource/LICENSE.txt /opt/docker/LICENSE.txt") + * val add = Cmd("ADD", "src/resource/LICENSE.txt", "/opt/docker/LICENSE.txt") + * }}} + * + * @example + * {{{ + * val copy = Cmd("COPY", "src/resource/LICENSE.txt", "/opt/docker/LICENSE.txt") + * }}} + * + * @example + * {{{ + * val env = Cmd("ENV", "APP_SECRET", "7sdfy7s9hfisdufuusud") * }}} */ -case class Cmd(cmd: String, arg: String) extends CmdLike { - def makeContent = "%s %s\n" format (cmd, arg) +case class Cmd(cmd: String, args: String*) extends CmdLike { + def makeContent = "%s %s\n" format (cmd, args.mkString(" ")) } /** - * Environment command + * A command that consists of a CMD string and an CmdLike object * - * @example {{{ - * EnvCmd("FOO_BAR_SECRET_KEY", "HGkhjGKjhgJhgjkhgHKJ") + * @example + * {{{ + * val onBuildAdd = CombinedCmd("ONBUILD", Cmd("ADD", "src/resource/LICENSE.txt", "/opt/docker/LICENSE.txt")) + * }}} + * + * @example + * {{{ + * val onBuildEnv = CombinedCmd("ONBUILD", Cmd("ENV", "APP_SECRET", "7sdfy7s9hfisdufuusud")) * }}} */ -case class EnvCmd(key: String, value: String) extends CmdLike { - def makeContent = "ENV %s %s\n" format (key, value) +case class CombinedCmd(cmd: String, arg: CmdLike) extends CmdLike { + def makeContent = "%s %s\n" format (cmd, arg.makeContent) } /** Represents dockerfile used by docker when constructing packages. */