Skip to content

Commit

Permalink
Move some defaults of docker to global scope (#1403)
Browse files Browse the repository at this point in the history
SBT strongly recommends to use the global scope for default settings,
see https://www.scala-sbt.org/1.x/docs/Plugins-Best-Practices.html#Provide+default+values+in

This allows to set the docker image and common labels once in ThisBuild
for all subprojects, and makes it easier to use a different
docker-compatible container builder by overriding the command, e.g.

    sbt 'set ThisBuild / dockerExecCommand := Seq("podman")' docker:publish
  • Loading branch information
swsnr committed Mar 15, 2021
1 parent efe7c7a commit 6dc2d7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ object DockerPlugin extends AutoPlugin {
// Instead of making dockerPermissionStrategy dependent on the Docker version, what we do instead is to
// run validation, and warn the build users if the strategy is not compatible with `docker` that's in scope.
dockerPermissionStrategy := DockerPermissionStrategy.MultiStage,
dockerChmodType := DockerChmodType.UserGroupReadExecute
)

override lazy val projectSettings: Seq[Setting[_]] = Seq(
dockerChmodType := DockerChmodType.UserGroupReadExecute,
dockerBaseImage := "openjdk:8",
dockerExposedPorts := Seq(),
dockerExposedUdpPorts := Seq(),
Expand All @@ -90,14 +87,18 @@ object DockerPlugin extends AutoPlugin {
dockerEnvVars := Map(),
dockerRepository := None,
dockerUsername := None,
dockerUpdateLatest := false,
dockerAutoremoveMultiStageIntermediateImages := true,
dockerCmd := Seq()
)

override lazy val projectSettings: Seq[Setting[_]] = Seq(
dockerAlias := DockerAlias(
(dockerRepository in Docker).value,
(dockerUsername in Docker).value,
(packageName in Docker).value,
Option((version in Docker).value)
),
dockerUpdateLatest := false,
dockerAutoremoveMultiStageIntermediateImages := true,
dockerLayerGrouping := { _: String =>
None
},
Expand Down Expand Up @@ -126,7 +127,6 @@ object DockerPlugin extends AutoPlugin {
Seq(alias)
},
dockerEntrypoint := Seq(s"${(defaultLinuxInstallLocation in Docker).value}/bin/${executableScriptName.value}"),
dockerCmd := Seq(),
dockerVersion := Try(
Process(dockerExecCommand.value ++ Seq("version", "--format", "'{{.Server.Version}}'")).!!
).toOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ object UniversalPlugin extends AutoPlugin {
override def projectConfigurations: Seq[Configuration] =
Seq(Universal, UniversalDocs, UniversalSrc)

override lazy val buildSettings: Seq[Setting[_]] = Seq[Setting[_]](
// Since more than just the docker plugin uses the docker command, we define this in the universal plugin
// so that it can be configured once and shared by all plugins without requiring the docker plugin. Also, make it
// a build settings so that it can be overridden once, at the build level.
DockerPlugin.autoImport.dockerExecCommand := Seq("docker"),
containerBuildImage := None
)
override def globalSettings: Seq[Def.Setting[_]] =
Seq[Setting[_]](
// Since more than just the docker plugin uses the docker command, we define this in the universal plugin
// so that it can be configured once and shared by all plugins without requiring the docker plugin.
DockerPlugin.autoImport.dockerExecCommand := Seq("docker")
)

override lazy val buildSettings: Seq[Setting[_]] = Seq[Setting[_]](containerBuildImage := None)

/** The basic settings for the various packaging types. */
override lazy val projectSettings: Seq[Setting[_]] = Seq[Setting[_]](
Expand Down

0 comments on commit 6dc2d7e

Please sign in to comment.