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

Add dockerExecCommand setting #910

Merged
merged 1 commit into from
Nov 13, 2016
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
Expand Up @@ -82,13 +82,14 @@ object DockerPlugin extends AutoPlugin {
dockerUpdateLatest := false,
dockerEntrypoint := Seq("bin/%s" format executableScriptName.value),
dockerCmd := Seq(),
dockerExecCommand := Seq("docker"),
dockerBuildOptions := Seq("--force-rm") ++ Seq("-t", dockerAlias.value.versioned) ++ (
if (dockerUpdateLatest.value)
Seq("-t", dockerAlias.value.latest)
else
Seq()
),
dockerBuildCommand := Seq("docker", "build") ++ dockerBuildOptions.value ++ Seq("."),
dockerBuildCommand := dockerExecCommand.value ++ Seq("build") ++ dockerBuildOptions.value ++ Seq("."),
dockerCommands := {
val dockerBaseDirectory = (defaultLinuxInstallLocation in Docker).value
val user = (daemonUser in Docker).value
Expand Down Expand Up @@ -122,11 +123,11 @@ object DockerPlugin extends AutoPlugin {
publishLocalDocker(context, buildCommand, s.log)
s.log.info(s"Built image $alias")
},
publish <<= (publishLocal, dockerAlias, dockerUpdateLatest, streams) map {
(_, alias, updateLatest, s) =>
publishDocker(alias.versioned, s.log)
publish <<= (publishLocal, dockerAlias, dockerUpdateLatest, dockerExecCommand, streams) map {
(_, alias, updateLatest, dockerExecCommand, s) =>
publishDocker(dockerExecCommand ,alias.versioned, s.log)
if (updateLatest) {
publishDocker(alias.latest, s.log)
publishDocker(dockerExecCommand, alias.latest, s.log)
}
},
sourceDirectory := sourceDirectory.value / "docker",
Expand Down Expand Up @@ -310,7 +311,7 @@ object DockerPlugin extends AutoPlugin {
throw new RuntimeException("Nonzero exit value: " + ret)
}

def publishDocker(tag: String, log: Logger): Unit = {
def publishDocker(execCommand: Seq[String], tag: String, log: Logger): Unit = {
val loginRequired = new AtomicBoolean(false)

def publishLogger(log: Logger) =
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ trait DockerKeys {
"dockerCmd",
"Docker CMD. Used together with dockerEntrypoint. Arguments passed in exec form"
)
val dockerExecCommand = SettingKey[Seq[String]]("dockerExecCommand", "The shell command used to exec Docker")
val dockerBuildOptions = SettingKey[Seq[String]]("dockerBuildOptions", "Options used for the Docker build")
val dockerBuildCommand = SettingKey[Seq[String]]("dockerBuildCommand", "Command for building the Docker image")

Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/docker/simple-docker/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enablePlugins(JavaAppPackaging)

name := "docker-test"
name := "simple-docker"

version := "0.1.0"

Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/docker/simple-docker/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Generate the Docker image locally
> docker:publishLocal
$ exec bash -c 'docker run docker-test:0.1.0 | grep -q "Hello world"'
$ exec bash -c 'docker run simple-docker:0.1.0 | grep -q "Hello world"'
9 changes: 9 additions & 0 deletions src/sbt-test/docker/simple-sudo-docker/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enablePlugins(JavaAppPackaging)

name := "simple-sudo-docker"

version := "0.1.0"

maintainer := "G. Richard Bellamy <[email protected]>"

dockerExecCommand := Seq("sudo", "docker")
1 change: 1 addition & 0 deletions src/sbt-test/docker/simple-sudo-docker/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Main extends App {
println("Hello world")
}
3 changes: 3 additions & 0 deletions src/sbt-test/docker/simple-sudo-docker/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generate the Docker image locally
> docker:publishLocal
$ exec bash -c 'docker run simple-sudo-docker:0.1.0 | grep -q "Hello world"'
10 changes: 7 additions & 3 deletions src/sphinx/formats/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,20 @@ Publishing Settings

``dockerAlias``
The alias to be used for tagging the resulting image of the Docker build.
The type of the setting key is ``DockerAlias`.
The type of the setting key is ``DockerAlias``.
Defaults to ``[dockerRepository/][name]:[version]``.

``dockerBuildOptions``
Overrides the default Docker build options.
Defaults to ``Seq("--force-rm", "-t", "[dockerAlias]")``. This default is expanded if ``dockerUpdateLatest`` is set to true.

``dockerExecCommand``
Overrides the default Docker exec command.
Defaults to ``Seq("docker")``

``dockerBuildCommand``
Overrides the default Docker build command.
Defaults to ``Seq("docker", "build", "[dockerBuildOptions]", ".")``.
Overrides the default Docker build command. The reason for this is that many systems restrict docker execution to root, and while the accepted guidance is to alias the docker command ``alias docker='/usr/bin/docker'``, neither Java nor Scala support passing aliases to sub-processes, and most build systems run builds using a non-login, non-interactive shell, which also have limited support for aliases, which means that the only viable option is to use ``sudo docker`` directly.
Defaults to ``Seq("[dockerExecCommand]", "build", "[dockerBuildOptions]", ".")``.

Tasks
-----
Expand Down