Skip to content

Commit

Permalink
FIX #1026 Add validatePackageConfiguration task
Browse files Browse the repository at this point in the history
This is an initial draft to provide helpful feedback to users
during their configuration phase with sbt-native-packager.

The intention is to give a short explanation why a warning or
error is triggerd and a detailed description how to fix the issue.
  • Loading branch information
muuki88 committed Aug 24, 2018
1 parent d869c92 commit fae1f54
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
packageSummary in Debian := (packageSummary in Linux).value,
maintainer in Debian := (maintainer in Linux).value,
validatePackageValidators in Debian := Seq(
nonEmptyMappings((linuxPackageMappings in Debian).value.flatMap(_.mappings)),
filesExist((linuxPackageMappings in Debian).value.flatMap(_.mappings)),
nonEmptyMappings((mappings in Debian).value),
filesExist((mappings in Debian).value),
checkMaintainer((maintainer in Debian).value, asWarning = false)
),
// override the linux sourceDirectory setting
Expand Down
28 changes: 13 additions & 15 deletions src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,19 @@ object DockerPlugin extends AutoPlugin {
}

private[this] def validateExposedPorts(ports: Seq[Int], udpPorts: Seq[Int]): Validation.Validator = () => {
if (ports.isEmpty && udpPorts.isEmpty) {
List(
ValidationWarning(
description = "There are no exposed ports for your docker image",
howToFix = """| Configure the `dockerExposedPorts` or `dockerExposedUdpPorts` setting. E.g.
if(ports.isEmpty && udpPorts.isEmpty) {
List(ValidationWarning(
description = "There are no exposed ports for your docker image",
howToFix =
"""| Configure the `dockerExposedPorts` or `dockerExposedUdpPorts` setting. E.g.
|
| // standard tcp ports
| dockerExposedPorts ++= Seq(9000, 9001)
|
| // for udp ports
| dockerExposedUdpPorts += 4444
""".stripMargin
)
)
))
} else {
List.empty
}
Expand All @@ -424,12 +423,10 @@ object DockerPlugin extends AutoPlugin {
private[this] def validateDockerVersion(dockerVersion: Option[DockerVersion]): Validation.Validator = () => {
dockerVersion match {
case Some(_) => List.empty
case None =>
List(
ValidationWarning(
description =
"sbt-native-packager wasn't able to identify the docker version. Some features may not be enabled",
howToFix = """|sbt-native packager tries to parse the `docker version` output. This can fail if
case None => List(ValidationWarning(
description = "sbt-native-packager wasn't able to identify the docker version. Some features may not be enabled",
howToFix =
"""|sbt-native packager tries to parse the `docker version` output. This can fail if
|
| - the output has changed:
| $ docker version --format '{{.Server.Version}}'
Expand All @@ -448,9 +445,10 @@ object DockerPlugin extends AutoPlugin {
| import com.typesafe.sbt.packager.docker.DockerVersion
| dockerVersion := Some(DockerVersion(17, 5, 0, Some("ce"))
""".stripMargin
)
)
))
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object Validation {
* @return aggregated result of all validator function
*/
def apply(validators: Seq[Validator]): Validation = validators.flatMap(_.apply()).foldLeft(Validation(Nil, Nil)) {
case (validation, error: ValidationError) => validation.copy(errors = validation.errors :+ error)
case (validation, error: ValidationError) => validation.copy(errors = validation.errors :+ error)
case (validation, warning: ValidationWarning) => validation.copy(warnings = validation.warnings :+ warning)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.typesafe.sbt.packager.validation

import sbt._


trait ValidationKeys {

/**
Expand All @@ -19,4 +20,4 @@ trait ValidationKeys {
val validatePackageValidators = taskKey[Seq[Validation.Validator]]("validator functions")
}

object ValidationKeys extends ValidationKeys
object ValidationKeys extends ValidationKeys

0 comments on commit fae1f54

Please sign in to comment.