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

Docker mappings - incomplete? #424

Merged
merged 1 commit into from
Dec 18, 2014
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
54 changes: 27 additions & 27 deletions src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import SbtNativePackager.Universal
* Future versions of the Docker Plugin may use the REST API, so you don't need docker installed
* locally.
*
* @note this plugin is not inteded to build very customizable docker images, but turn your mappings
* @note this plugin is not intended to build very customizable docker images, but turn your mappings
* configuration in a docker image with almost no ''any'' configuration.
*
* @example Enable the plugin in the `build.sbt`
Expand All @@ -63,46 +63,45 @@ object DockerPlugin extends AutoPlugin {
dockerBaseImage := "dockerfile/java:latest",
dockerExposedPorts := Seq(),
dockerExposedVolumes := Seq(),
name in Docker <<= name,
packageName in Docker <<= packageName,
executableScriptName in Docker <<= executableScriptName,
dockerRepository := None,
dockerUpdateLatest := false,
sourceDirectory in Docker <<= sourceDirectory apply (_ / "docker"),
target in Docker <<= target apply (_ / "docker"),
dockerEntrypoint := Seq("bin/%s" format executableScriptName.value)

) ++ mapGenericFilesToDocker ++ inConfig(Docker)(Seq(
executableScriptName := executableScriptName.value,
mappings ++= dockerPackageMappings.value,
mappings ++= Seq(dockerGenerateConfig.value) pair relativeTo(target.value),
name := name.value,
packageName := packageName.value,
publishLocal <<= (stage, dockerTarget, dockerUpdateLatest, streams) map {
(context, target, updateLatest, s) =>
publishLocalDocker(context, target, updateLatest, s.log)
},
publish <<= (publishLocal, dockerTarget, dockerUpdateLatest, streams) map {
(_, target, updateLatest, s) =>
publishDocker(target, s.log)
if (updateLatest) {
val name = target.substring(0, target.lastIndexOf(":")) + ":latest"
publishDocker(name, s.log)
}
},
sourceDirectory := sourceDirectory.value / "docker",
stage <<= (streams, stagingDirectory, mappings) map Stager.stage(Docker.name),
stagingDirectory := (target in Docker).value / "stage",
target := target.value / "docker",

daemonUser := "daemon",
defaultLinuxInstallLocation := "/opt/docker",
dockerPackageMappings <<= (sourceDirectory) map { dir =>

dockerPackageMappings <<= sourceDirectory map { dir =>
MappingsHelper contentOf dir
},
mappings <++= dockerPackageMappings,
stage <<= (dockerGenerateConfig, dockerGenerateContext, streams) map {
(dockerfile, contextDir, s) =>
s.log.success("created docker file: " + dockerfile.getPath)
contextDir
},
dockerGenerateConfig <<= (dockerBaseImage, defaultLinuxInstallLocation,
maintainer, daemonUser, executableScriptName,
dockerExposedPorts, dockerExposedVolumes, target, dockerEntrypoint) map generateDockerConfig,
dockerGenerateContext := Stager.stage("docker")(streams.value, target.value / "files", mappings.value),
dockerTarget <<= (dockerRepository, packageName, version) map {
(repo, name, version) =>
repo.map(_ + "/").getOrElse("") + name + ":" + version
},
publishLocal <<= (dockerGenerateConfig, dockerGenerateContext, dockerTarget, dockerUpdateLatest, streams) map {
(config, _, target, updateLatest, s) =>
publishLocalDocker(config, target, updateLatest, s.log)
},
publish <<= (publishLocal, dockerTarget, dockerUpdateLatest, streams) map {
(_, target, updateLatest, s) =>
publishDocker(target, s.log)
if (updateLatest) {
val name = target.substring(0, target.lastIndexOf(":")) + ":latest"
publishDocker(name, s.log)
}
}
))

Expand All @@ -117,9 +116,10 @@ object DockerPlugin extends AutoPlugin {
}

val dockerCommands = Seq(
Cmd("ADD", "files /"),
Cmd("ADD", "* /"),
Copy link
Contributor

Choose a reason for hiding this comment

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

This will always include the Dockerfile, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed it will, hence the removal of it further down. I could be more explicit about what is included if you want me to. This seemed like the simpler approach though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will the internal path change? I mean, currently it is /opt/docker/<app> and for me
it looks like /stage/opt/docker/<app> now

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah... the stagingDirectory is used for this?

Cmd("WORKDIR", "%s" format dockerBaseDirectory),
ExecCmd("RUN", "chown", "-R", daemonUser, "."),
ExecCmd("RUN", "rm", "/Dockerfile"),
Cmd("USER", daemonUser),
ExecCmd("ENTRYPOINT", entrypoint: _*),
ExecCmd("CMD")
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import sbt._
*/
trait DockerKeys {
val dockerGenerateConfig = TaskKey[File]("docker-generate-config", "Generates configuration file for Docker.")
val dockerGenerateContext = TaskKey[File]("docker-generate-context", "Generates context directory for Docker.")
val dockerPackageMappings = TaskKey[Seq[(File, String)]]("docker-package-mappings", "Generates location mappings for Docker build.")
val dockerTarget = TaskKey[String]("docker-target", "Defines target used when building and publishing Docker image")

Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/docker/staging/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Stage the distribution and ensure files show up.
> docker:stage
$ exists target/docker/Dockerfile
$ exists target/docker/files
$ exists target/docker/stage/Dockerfile
$ exists target/docker/stage/opt
4 changes: 2 additions & 2 deletions src/sbt-test/docker/test-executableScriptName/test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generate the Docker image locally
> docker:publishLocal
$ exists target/docker/Dockerfile
$ exists target/docker/files/opt/docker/bin/docker-exec
$ exists target/docker/stage/Dockerfile
$ exists target/docker/stage/opt/docker/bin/docker-exec
> check-dockerfile
$ exec bash -c 'docker run docker-package:0.1.0 | grep -q "Hello world"'
4 changes: 2 additions & 2 deletions src/sbt-test/docker/test-packageName-universal/test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generate the Docker image locally
> docker:publishLocal
$ exists target/docker/Dockerfile
$ exists target/docker/files/opt/docker/bin/docker-test
$ exists target/docker/stage/Dockerfile
$ exists target/docker/stage/opt/docker/bin/docker-test
> check-dockerfile
$ exec bash -c 'docker run docker-package:0.1.0 | grep -q "Hello world"'
4 changes: 2 additions & 2 deletions src/sbt-test/docker/test-packageName/test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generate the Docker image locally
> docker:publishLocal
$ exists target/docker/Dockerfile
$ exists target/docker/files/opt/docker/bin/docker-test
$ exists target/docker/stage/Dockerfile
$ exists target/docker/stage/opt/docker/bin/docker-test
> check-dockerfile
$ exec bash -c 'docker run docker-package:0.1.0 | grep -q "Hello world"'
7 changes: 7 additions & 0 deletions test-project-docker/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enablePlugins(JavaAppPackaging)

name := "docker-test"

version := "0.1.0"

maintainer := "Gary Coady <[email protected]>"
1 change: 1 addition & 0 deletions test-project-docker/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.7
3 changes: 3 additions & 0 deletions test-project-docker/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lazy val root = Project("plugins", file(".")).dependsOn(plugin)

lazy val plugin = file("../").getCanonicalFile.toURI
3 changes: 3 additions & 0 deletions test-project-docker/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Main extends App {
println("Hello world")
}