Skip to content

Commit

Permalink
Attempt to move docker-client dependency back to the provided scope (#…
Browse files Browse the repository at this point in the history
…1196)

* Attempt to move docker-client dependency back to the provided scope

* Fix crossbuilding

* Formatting
  • Loading branch information
gpgekko authored and muuki88 committed Jan 25, 2019
1 parent b81ae1d commit a2baeb2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
18 changes: 5 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
// put jdeb on the classpath for scripted tests
classpathTypes += "maven-plugin"
libraryDependencies ++= Seq(
// these dependencies have to be explicitly added by the user
"com.spotify" % "docker-client" % "8.14.3" % Provided,
"org.vafer" % "jdeb" % "1.7" % Provided artifacts Artifact("jdeb", "jar", "jar"),
"org.apache.commons" % "commons-compress" % "1.18",
// for jdkpackager
"org.apache.ant" % "ant" % "1.10.5",
Expand All @@ -22,19 +25,8 @@ libraryDependencies ++= Seq(
libraryDependencies ++= {
(pluginCrossBuild / sbtVersion).value match {
case v if v.startsWith("1.") =>
Seq(
"org.scala-sbt" %% "io" % "1.2.2",
// these dependencies have to be explicitly added by the user
// FIXME temporary remove the 'provided' scope. SBT 1.0.0-M6 changed the resolving somehow
"com.spotify" % "docker-client" % "8.14.3" /* % "provided" */,
"org.vafer" % "jdeb" % "1.7" % Provided artifacts Artifact("jdeb", "jar", "jar")
)
case _ =>
Seq(
// these dependencies have to be explicitly added by the user
"com.spotify" % "docker-client" % "8.14.3" % Provided,
"org.vafer" % "jdeb" % "1.7" % Provided artifacts Artifact("jdeb", "jar", "jar")
)
Seq("org.scala-sbt" %% "io" % "1.2.2")
case _ => Seq()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package com.typesafe.sbt.packager.docker

import java.nio.file.Paths

import com.spotify.docker.client.DockerClient.BuildParam
import com.spotify.docker.client.messages.ProgressMessage
import com.spotify.docker.client.{DefaultDockerClient, DockerClient, ProgressHandler}
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.stage

import sbt.Keys._
import sbt._

Expand Down Expand Up @@ -63,6 +61,35 @@ object DockerSpotifyClientPlugin extends AutoPlugin {
val log = streams.value.log

val dockerDirectory = context.toString

val docker = new DockerClientTask()
docker.packageDocker(primaryAlias, aliases, dockerDirectory, log)
}

def dockerServerVersion: Def.Initialize[Task[Option[DockerVersion]]] = Def.task {
val docker = new DockerClientTask()
docker.dockerServerVersion()
}

}

/**
* == Docker Client Task ==
*
* This private class contains all the docker-plugin specific implementations. It's only invoked when the docker
* plugin is enabled and the `docker:publishLocal` task is called. This means that all classes in
* `com.spotify.docker.client._` are only loaded when required and allows us to put the dependency in the "provided"
* scope. The provided scope means that we have less dependency issues in an sbt build.
*/
private class DockerClientTask {
import com.spotify.docker.client.DockerClient.BuildParam
import com.spotify.docker.client.messages.ProgressMessage
import com.spotify.docker.client.{DefaultDockerClient, DockerClient, ProgressHandler}

def packageDocker(primaryAlias: DockerAlias,
aliases: Seq[DockerAlias],
dockerDirectory: String,
log: Logger): Unit = {
val docker: DockerClient = DefaultDockerClient.fromEnv().build()

log.info(s"PublishLocal using Docker API ${docker.version().apiVersion()}")
Expand All @@ -80,9 +107,8 @@ object DockerSpotifyClientPlugin extends AutoPlugin {
}
}

def dockerServerVersion: Def.Initialize[Task[Option[DockerVersion]]] = Def.task {
def dockerServerVersion(): Option[DockerVersion] = {
val docker: DockerClient = DefaultDockerClient.fromEnv().build()
DockerVersion.parse(docker.version().version())
}

}

0 comments on commit a2baeb2

Please sign in to comment.