Skip to content

Commit

Permalink
Fixing docker tests aswell
Browse files Browse the repository at this point in the history
  • Loading branch information
muuki88 committed Oct 11, 2014
1 parent c197cab commit 1cb20fc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
39 changes: 21 additions & 18 deletions src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,30 @@ import linux.LinuxPlugin.autoImport.{ daemonUser, defaultLinuxInstallLocation }
import universal.UniversalPlugin.autoImport.stage
import SbtNativePackager.Universal


/**
* == Docker Plugin ==
*
*
* This plugin helps you build docker containers.
*
*
* == Configuration ==
*
*
* In order to configure this plugin take a look at the available [[com.typesafe.sbt.packager.docker.DockerKeys]]
*
*
* == Requirements ==
*
*
* You need docker to have docker installed on your system and be able to execute commands.
* Check with a single command:
*
*
* {{{
* docker version
* }}}
*
*
* Future versions of the Docker Plugin may use the REST API, so you don't need docker installed
* locally.
*
* locally.
*
* @note this plugin is not inteded 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`
* {{{
* enablePlugins(DockerPlugin)
Expand All @@ -60,6 +59,8 @@ object DockerPlugin extends AutoPlugin {

override def requires = universal.UniversalPlugin

override def trigger = allRequirements

override lazy val projectSettings = Seq(
dockerBaseImage := "dockerfile/java:latest",
name in Docker <<= name,
Expand All @@ -68,13 +69,8 @@ object DockerPlugin extends AutoPlugin {
dockerRepository := None,
dockerUpdateLatest := false,
sourceDirectory in Docker <<= sourceDirectory apply (_ / "docker"),
target in Docker <<= target apply (_ / "docker"),
target in Docker <<= target apply (_ / "docker")

// TODO this must be changed, when there is a setting for the startScripts name
dockerGenerateConfig <<=
(dockerBaseImage in Docker, defaultLinuxInstallLocation in Docker, maintainer in Docker, daemonUser in Docker,
executableScriptName /* this is not scoped!*/ , dockerExposedPorts in Docker, dockerExposedVolumes in Docker, target in Docker) map
generateDockerConfig
) ++ mapGenericFilesToDocker ++ inConfig(Docker)(Seq(
daemonUser := "daemon",
defaultLinuxInstallLocation := "/opt/docker",
Expand All @@ -84,7 +80,14 @@ object DockerPlugin extends AutoPlugin {
MappingsHelper contentOf dir
},
mappings <++= dockerPackageMappings,
stage <<= (dockerGenerateConfig, dockerGenerateContext) map { (_, contextDir) => contextDir },
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) map generateDockerConfig,
dockerGenerateContext := Stager.stage("docker")(streams.value, target.value / "files", mappings.value),
dockerTarget <<= (dockerRepository, packageName, version) map {
(repo, name, version) =>
Expand Down
2 changes: 0 additions & 2 deletions src/sbt-test/docker/simple-docker/build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import NativePackagerKeys._

enablePlugins(JavaAppPackaging)

name := "docker-test"
Expand Down
2 changes: 1 addition & 1 deletion 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.
> show docker:stage
> docker:stage
$ exists target/docker/Dockerfile
$ exists target/docker/files
4 changes: 2 additions & 2 deletions src/sbt-test/docker/test-packageName-universal/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ enablePlugins(JavaAppPackaging)

name := "docker-test"

packageName := "docker-package" // sets the executable script, too
packageName := "docker-package"

version := "0.1.0"

maintainer := "Gary Coady <[email protected]>"

TaskKey[Unit]("check-dockerfile") <<= (target, streams) map { (target, out) =>
val dockerfile = IO.read(target / "docker" / "Dockerfile")
assert(dockerfile.contains("ENTRYPOINT [\"bin/docker-package\"]\n"), "dockerfile doesn't contain ENTRYPOINT [\"docker-package\"]\n" + dockerfile)
assert(dockerfile.contains("ENTRYPOINT [\"bin/docker-test\"]\n"), "dockerfile doesn't contain ENTRYPOINT [\"docker-test\"]\n" + dockerfile)
out.log.success("Successfully tested control script")
()
}
2 changes: 1 addition & 1 deletion 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-package
$ exists target/docker/files/opt/docker/bin/docker-test
> check-dockerfile
$ exec bash -c 'docker run docker-package:0.1.0 | grep -q "Hello world"'

0 comments on commit 1cb20fc

Please sign in to comment.