-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding documentation, examples and tests.
- Loading branch information
Showing
10 changed files
with
145 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import com.typesafe.sbt.packager.docker._ | ||
|
||
enablePlugins(JavaAppPackaging) | ||
|
||
name := "docker-commands" | ||
|
||
version := "0.1.0" | ||
|
||
maintainer := "Gary Coady <[email protected]>" | ||
|
||
dockerCommands := Seq( | ||
Cmd("FROM", "dockerfile/java:latest"), | ||
Cmd("MAINTAINER", maintainer.value), | ||
ExecCmd("CMD", "echo", "Hello, World from Docker") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/docker/override-commands/src/main/scala/Main.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Main extends App { | ||
println("Hello world") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 docker-test:latest | grep -q "Hello world"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Stage the distribution and ensure files show up. | ||
> docker:stage | ||
$ exec grep -q -F 'VOLUME ["/opt/docker/logs", "/opt/docker/config"]' target/docker/Dockerfile | ||
$ exec grep -q -F 'RUN ["chown", "-R", "daemon:daemon", "/opt/docker/logs", "/opt/docker/config"]' target/docker/Dockerfile | ||
$ exec grep -q -F 'RUN ["mkdir", "-p", "/opt/docker/logs", "/opt/docker/config"]' target/docker/Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,11 @@ The Docker support provides the following commands: | |
Customize | ||
--------- | ||
|
||
There are some predefined settings, which you can easily customize. These | ||
settings are explained in some detail in the next sections. If you want to | ||
describe your Dockerfile completely yourself, you can provide your own | ||
`docker commands` as described in `Custom Dockerfile`_. | ||
|
||
Docker Image Name | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
|
@@ -149,9 +154,13 @@ Docker Image Customization | |
|
||
.. code-block:: scala | ||
dockerExposedPorts in Docker := Seq(9000, 9443) | ||
dockerExposedPorts := Seq(9000, 9443) | ||
dockerExposedVolumes := Seq("/opt/docker/logs") | ||
dockerExposedVolumes in Docker := Seq("/opt/docker/logs") | ||
In order to work properly with `USER daemon` the exposed volumes first | ||
created (if not existend) and chowned. | ||
|
||
Install Location | ||
~~~~~~~~~~~~~~~~ | ||
|
@@ -161,3 +170,87 @@ The files from ``mappings in Docker`` are extracted underneath this directory. | |
.. code-block:: scala | ||
defaultLinuxInstallLocation in Docker := "/opt/docker" | ||
Custom Dockerfile | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
All settings before are used to create a single sequence of docker commands. | ||
You have the option to write all of them on your own, filter or change existing | ||
commands or simply add some. | ||
|
||
First of all you should take a look what you docker commands look like. | ||
In your sbt console type | ||
|
||
.. code-block:: bash | ||
> show dockerCommands | ||
[info] List(Cmd(FROM,dockerfile/java:latest), Cmd(MAINTAINER,Your Name <[email protected]>), ...) | ||
Remove Commands | ||
=============== | ||
|
||
SBT Native Packager added some commands you may not need. For example | ||
the chowning of a exposed volume. | ||
|
||
.. code-block:: scala | ||
import com.typesafe.sbt.packager.docker._ | ||
// we want to filter the chown command for '/data' | ||
dockerExposedVolumes += "/data" | ||
dockerCommands := dockerCommands.value.filterNot { | ||
// ExecCmd is a case class, and args is a varargs variable, so you need to bind it with @ | ||
case ExecCmd("RUN", args @ _*) => args.contains("chown") && args.contains("/data") | ||
// dont filter the rest | ||
case cmd => false | ||
} | ||
Add Commands | ||
============ | ||
|
||
Adding commands is as straigtforward as adding anything in a list. | ||
|
||
.. code-block:: scala | ||
import com.typesafe.sbt.packager.docker._ | ||
dockerCommands += Cmd("USER", daemonUser.value) | ||
dockerCommands ++= Seq( | ||
// setting the run script executable | ||
ExecCmd("RUN", | ||
"chmod", "u+x", | ||
s"${(defaultLinuxInstallLocation in Docker).value}/bin/${executableScriptName.value}"), | ||
// setting a daemon user | ||
Cmd("USER", "daemon") | ||
) | ||
Write from Scratch | ||
================== | ||
|
||
You can simply wipe out all docker commands with | ||
|
||
.. code-block:: scala | ||
dockerCommands := Seq() | ||
Now let's start adding some Docker commands. | ||
|
||
.. code-block:: scala | ||
import com.typesafe.sbt.packager.docker._ | ||
dockerCommands := Seq( | ||
Cmd("FROM", "dockerfile/java:latest"), | ||
Cmd("MAINTAINER", maintainer.value), | ||
ExecCmd("CMD", "echo", "Hello, World from Docker") | ||
) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import com.typesafe.sbt.packager.docker._ | ||
|
||
enablePlugins(JavaAppPackaging) | ||
|
||
name := "docker-test" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import java.nio.file._ | ||
import scala.util._ | ||
|
||
object Main extends App { | ||
println("Hello world") | ||
|
||
val path = Paths get "/data/test01" | ||
val result = Try(Files createFile path) | ||
|
||
println(result) | ||
} |