-
Notifications
You must be signed in to change notification settings - Fork 436
/
dockerfile.scala
89 lines (83 loc) · 1.95 KB
/
dockerfile.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.typesafe.sbt
package packager
package docker
/**
* a single line in a dockerfile. See subclasses for more detail
*
*/
trait CmdLike {
/**
* Creates the command which can be placed inside a Dockerfile.
*
* @return the docker command
*/
def makeContent: String
}
/**
* Executable command
*
* @example {{{
* ExecCmd("RUN", "chown", "-R", daemonUser, ".")
* }}}
*
* @example {{{
* ExecCmd("ENTRYPOINT", "bin/%s" format execScript),
* }}}
*
* @example {{{
* ExecCmd("CMD")
* }}}
*
* @example {{{
* ExecCmd("VOLUME", exposedVolumes: _*)
* }}}
*/
case class ExecCmd(cmd: String, args: String*) extends CmdLike {
def makeContent =
"%s [%s]\n" format (cmd, args.map('"' + _ + '"').mkString(", "))
}
/**
* An arbitrary command
*
* @example
* {{{
* 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, args: String*) extends CmdLike {
def makeContent = "%s %s\n" format (cmd, args.mkString(" "))
}
/**
* A command that consists of a CMD string and an CmdLike object
*
* @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 CombinedCmd(cmd: String, arg: CmdLike) extends CmdLike {
def makeContent = "%s %s\n" format (cmd, arg.makeContent)
}
/** Represents dockerfile used by docker when constructing packages. */
case class Dockerfile(commands: CmdLike*) {
def makeContent: String = {
val sb = new StringBuilder
commands foreach { sb append _.makeContent }
sb toString
}
}