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 ability to expose UDP ports #881

Merged
merged 1 commit into from
Sep 22, 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 @@ -74,6 +74,7 @@ object DockerPlugin extends AutoPlugin {
override lazy val projectSettings = Seq(
dockerBaseImage := "openjdk:latest",
dockerExposedPorts := Seq(),
dockerExposedUdpPorts := Seq(),
dockerExposedVolumes := Seq(),
dockerRepository := None,
dockerAlias := DockerAlias(dockerRepository.value, None, packageName.value, Some(version.value)),
Expand All @@ -99,7 +100,7 @@ object DockerPlugin extends AutoPlugin {
makeAdd(dockerBaseDirectory),
makeChown(user, group, "." :: Nil)
) ++
makeExposePorts(dockerExposedPorts.value) ++
makeExposePorts(dockerExposedPorts.value, dockerExposedUdpPorts.value) ++
makeVolumes(dockerExposedVolumes.value, user, group) ++
Seq(
makeUser(user),
Expand Down Expand Up @@ -207,8 +208,8 @@ object DockerPlugin extends AutoPlugin {
* @param exposedPorts
* @return if ports are exposed the EXPOSE command
*/
private final def makeExposePorts(exposedPorts: Seq[Int]): Option[CmdLike] = {
if (exposedPorts.isEmpty) None else Some(Cmd("EXPOSE", exposedPorts mkString " "))
private final def makeExposePorts(exposedPorts: Seq[Int], exposedUdpPorts: Seq[Int]): Option[CmdLike] = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we care? I think most of the methods in this class could have a more limited scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope. I always forget to configure this :/

if (exposedPorts.isEmpty) None else Some(Cmd("EXPOSE", (exposedPorts.map(_.toString) ++ exposedUdpPorts.map(_.toString).map(_ + "/udp")) mkString " "))
}

/**
Expand Down
3 changes: 2 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 @@ -12,7 +12,8 @@ trait DockerKeys {
val dockerPackageMappings = TaskKey[Seq[(File, String)]]("docker-package-mappings", "Generates location mappings for Docker build.")

val dockerBaseImage = SettingKey[String]("dockerBaseImage", "Base image for Dockerfile.")
val dockerExposedPorts = SettingKey[Seq[Int]]("dockerExposedPorts", "Ports exposed by Docker image")
val dockerExposedPorts = SettingKey[Seq[Int]]("dockerExposedPorts", "TCP Ports exposed by Docker image")
val dockerExposedUdpPorts = SettingKey[Seq[Int]]("dockerExposedUdpPorts", "UDP Ports exposed by Docker image")
val dockerExposedVolumes = SettingKey[Seq[String]]("dockerExposedVolumes", "Volumes exposed by Docker image")
val dockerRepository = SettingKey[Option[String]]("dockerRepository", "Repository for published Docker image")
val dockerAlias = SettingKey[DockerAlias]("dockerAlias", "Docker alias for the built image")
Expand Down
3 changes: 2 additions & 1 deletion src/sbt-test/docker/ports/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ name := "simple-test"

version := "0.1.0"

dockerExposedPorts := Seq(9000)
dockerExposedPorts := Seq(9000, 9001)
dockerExposedUdpPorts := Seq(10000, 10001)
2 changes: 1 addition & 1 deletion src/sbt-test/docker/ports/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Stage the distribution and ensure files show up.
> docker:stage
$ exec grep -q -F 'EXPOSE 9000' target/docker/Dockerfile
$ exec grep -q -F 'EXPOSE 9000 9001 10000/udp 10001/udp' target/docker/Dockerfile
5 changes: 4 additions & 1 deletion src/sphinx/formats/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ Environment Settings
The user to use when executing the application. Files below the install path also have their ownership set to this user.

``dockerExposedPorts``
A list of ports to expose from the Docker image.
A list of TCP ports to expose from the Docker image.

``dockerExposedUdpPorts``
A list of UDP ports to expose from the Docker image.

``dockerExposedVolumes in Docker``
A list of data volumes to make available in the Docker image.
Expand Down