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

Attempt to move docker-client dependency back to the provided scope #1196

Merged
merged 4 commits into from
Jan 25, 2019
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
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())
}

}