-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding 'dockerBuild{Command, Options}' and renaming 'dockerTag' (#854)
* dockerBuildCommand The 'dockerBuildCommand' let users customize the command for building Docker images. The current default is 'docker build [dockerBuildOptions] .'. * dockerBuildOptions Furthermore 'dockerBuildOptions' defines which build options are used. The current default is '--force-rm -t [dockerAlias]' (which is expanded if 'dockerUpdateLatest' is set to 'true'. This results in an execution of 'docker build --force-rm -t [dockerAlias] .' (if 'dockerUpdateLatest' is 'false'). * dockerTag being renamed to dockerAlias The 'dockerTag' setting is renamed to 'dockerAlias' as this better reflects the setting. Docker aliases consist of a registry path, username, name and tag ([REGISTRY_HOST/][USERNAME/]NAME[:TAG]). To not confuse the Docker image tag with this setting (as it takes the full alias name), the setting is renamed.
- Loading branch information
Showing
19 changed files
with
97 additions
and
40 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/scala/com/typesafe/sbt/packager/docker/DockerAlias.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,19 @@ | ||
package com.typesafe.sbt.packager.docker | ||
|
||
/** | ||
* This class represents a Docker alias. | ||
* It generates a string in the form of {{{[REGISTRY_HOST/][USERNAME/]NAME[:TAG]}}}, | ||
* e.g. ''my-registry.com:1234/my-user/my-service:1.0.0'' or just ''my-service:1.0.0''. | ||
* @param registryHost Optional hostname of the registry (including port if applicable) | ||
* @param username Optional username or other qualifier | ||
* @param name Name of the image, e.g. the artifact name | ||
* @param tag Optional tag for the image, e.g. the version | ||
*/ | ||
case class DockerAlias(registryHost: Option[String], username: Option[String], name: String, tag: Option[String]) { | ||
protected val untagged = registryHost.map(_ + "/").getOrElse("") + username.map(_ + "/").getOrElse("") + name | ||
|
||
/** Tag with (optional) given version */ | ||
val versioned = untagged + tag.map(":" + _).getOrElse("") | ||
/** Tag with version 'latest' */ | ||
val latest = s"$untagged:latest" | ||
} |
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
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,7 @@ | ||
enablePlugins(JavaAppPackaging) | ||
|
||
name := "docker-alias-test" | ||
|
||
version := "0.1.0" | ||
|
||
dockerAlias := DockerAlias(None, None, "docker-alias-test", Some("0.1.0")) |
File renamed without changes.
File renamed without changes.
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 @@ | ||
# Stage the distribution and ensure files show up. | ||
> docker:publishLocal | ||
$ exec bash -c 'docker run docker-alias-test:0.1.0 | 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
enablePlugins(JavaAppPackaging) | ||
|
||
name := "docker-build-command-test" | ||
|
||
version := "0.1.0" | ||
|
||
import NativePackagerHelper._ | ||
mappings in Docker ++= directory("src/main/resources/docker-test") | ||
dockerBuildCommand := Seq("docker", "build", "-t", "docker-build-command-test:0.1.0", "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 |
---|---|---|
@@ -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/build-command/src/main/resources/docker-test/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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM busybox | ||
|
||
CMD ["echo", "docker build command override 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Stage the distribution and ensure files show up. | ||
> docker:publishLocal | ||
$ exec bash -c 'docker run docker-build-command-test:0.1.0 | grep -q "docker build command override 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enablePlugins(JavaAppPackaging) | ||
|
||
name := "docker-build-options-test" | ||
|
||
version := "0.1.0" | ||
|
||
dockerBuildOptions := dockerBuildOptions.value ++ Seq("-t", "docker-build-options-test:0.1.0-random-tag") |
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")) |
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,4 @@ | ||
# Stage the distribution and ensure files show up. | ||
> docker:publishLocal | ||
$ exec bash -c 'docker run docker-build-options-test:0.1.0 | grep -q "Hello world"' | ||
$ exec bash -c 'docker run docker-build-options-test:0.1.0-random-tag | grep -q "Hello world"' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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