Skip to content

Update to the new docker client #154

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v2
- name: Cache
uses: coursier/cache-action@v6
- name: Setup SBT
uses: coursier/setup-action@v1
with:
distribution: temurin
java-version: 11
apps: sbt
jvm: adopt:11
- name: Build and Test
run: sbt -v +test
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ You can read about reasoning behind it at [Finely Distributed](https://finelydis

## Setup

docker-it-scala works with Spotify's docker-client to communicate to docker engine through *REST API* or *unix socket*.
- [Spotify's docker-client](https://github.com/spotify/docker-client) (used in Whisk)

```scala
libraryDependencies ++= Seq(
"com.whisk" %% "docker-testkit-scalatest" % "0.11.0" % "test"
Expand Down Expand Up @@ -145,4 +142,4 @@ class MultiContainerTest
assert(mongodbContainer.mappedPortOpt(27017).nonEmpty, "port 2017 is exposed")
}
}
```
```
39 changes: 27 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
lazy val commonSettings = Seq(
organization := "com.whisk",
version := "0.12.0",
scalaVersion := "2.13.6",
crossScalaVersions := Seq("2.13.6", "2.12.15", "2.11.12", "3.0.2"),
version := "0.13.0",
scalaVersion := "2.13.16",
crossScalaVersions := Seq("2.13.16", "2.12.20", "3.7.0"),
scalacOptions ++= Seq("-feature", "-deprecation"),
Test / fork := true,
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
Expand Down Expand Up @@ -43,11 +43,19 @@ lazy val core =
.settings(commonSettings: _*)
.settings(
name := "docker-testkit-core",
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % "1.7.25",
"com.spotify" % "docker-client" % "8.16.0",
"com.google.code.findbugs" % "jsr305" % "3.0.1"
)
libraryDependencies ++= {
val base = Seq(
"org.slf4j" % "slf4j-api" % "1.7.25",
"org.mandas" % "docker-client" % "9.0.3",
"com.google.code.findbugs" % "jsr305" % "3.0.1"
)
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
base :+ ("org.immutables" % "value" % "2.9.3" % Provided)
case _ =>
base
}
}
)

lazy val scalatest =
Expand Down Expand Up @@ -87,10 +95,17 @@ lazy val coreShaded =
.settings(commonSettings: _*)
.settings(
name := "docker-testkit-core-shaded",
libraryDependencies ++=
Seq(
"com.spotify" % "docker-client" % "8.16.0" classifier "shaded",
libraryDependencies ++= {
val base = Seq(
"org.mandas" % "docker-client" % "9.0.3",
"com.google.code.findbugs" % "jsr305" % "3.0.1"
),
)
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
base :+ ("org.immutables" % "value" % "2.9.3" % Provided)
case _ =>
base
}
},
target := baseDirectory.value / "target-shaded"
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.whisk.docker.testkit

import java.util.concurrent.atomic.AtomicReference

import com.spotify.docker.client.messages.ContainerInfo
import org.mandas.docker.client.messages.ContainerInfo
import org.slf4j.LoggerFactory

import scala.collection.JavaConverters._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.whisk.docker.testkit
import java.nio.charset.StandardCharsets
import java.util.concurrent.TimeUnit

import com.google.common.io.Closeables
import com.spotify.docker.client.DockerClient.{AttachParameter, RemoveContainerParam}
import com.spotify.docker.client.messages._
import com.spotify.docker.client.{DockerClient, LogMessage, LogStream}
import org.mandas.docker.client.DockerClient.RemoveContainerParam
import org.mandas.docker.client.messages._
import org.mandas.docker.client.{DockerClient, LogMessage, LogStream}

import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.Try

class StartFailedException(msg: String) extends Exception(msg)

Expand Down Expand Up @@ -57,8 +57,14 @@ class ContainerCommandExecutor(val client: DockerClient) {
private def logStreamFuture(id: String, withErr: Boolean)(implicit
ec: ExecutionContext
): Future[LogStream] = {
val baseParams = List(AttachParameter.STDOUT, AttachParameter.STREAM, AttachParameter.LOGS)
val logParams = if (withErr) AttachParameter.STDERR :: baseParams else baseParams
val baseParams = List(
DockerClient.AttachParameter.STDOUT,
DockerClient.AttachParameter.STREAM,
DockerClient.AttachParameter.LOGS
)
val logParams =
if (withErr) DockerClient.AttachParameter.STDERR :: baseParams
else baseParams
Future(scala.concurrent.blocking(client.attachContainer(id, logParams: _*)))
}

Expand Down Expand Up @@ -90,7 +96,7 @@ class ContainerCommandExecutor(val client: DockerClient) {
val str = StandardCharsets.US_ASCII.decode(t.content()).toString
if (f(str)) {
p.trySuccess(())
Closeables.close(stream, true)
Try(client.close())
}
}
})
Expand All @@ -113,7 +119,6 @@ class ContainerCommandExecutor(val client: DockerClient) {
)
}

def close(): Unit = {
Closeables.close(client, true)
}
def close(): Unit = Try(client.close())

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.whisk.docker.testkit

import java.util.Collections

import com.spotify.docker.client.messages.{ContainerConfig, HostConfig, PortBinding}
import com.spotify.docker.client.messages.HostConfig.Bind
import org.mandas.docker.client.messages.{ContainerConfig, HostConfig, PortBinding}
import org.mandas.docker.client.messages.HostConfig.Bind

import scala.collection.JavaConverters._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.whisk.docker.testkit

import java.util.concurrent.{ConcurrentHashMap, TimeUnit}

import com.spotify.docker.client.exceptions.ImageNotFoundException
import com.spotify.docker.client.messages.ContainerCreation
import org.mandas.docker.client.exceptions.ImageNotFoundException
import org.mandas.docker.client.messages.ContainerCreation
import org.slf4j.LoggerFactory

import scala.concurrent.{Await, ExecutionContext, Future}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.whisk.docker.testkit

import com.spotify.docker.client.messages.PortBinding
import org.mandas.docker.client.messages.PortBinding
import com.whisk.docker.testkit.scalatest.DockerTestKitForAll
import org.scalatest.Suite

import scala.concurrent.duration._

trait DockerClickhouseService extends DockerTestKitForAll { self: Suite =>
override val dockerTestTimeouts: DockerTestTimeouts = DockerTestTimeouts(pull = 10.minutes, init = 10.minutes, stop = 1.minutes)
override val dockerTestTimeouts: DockerTestTimeouts =
DockerTestTimeouts(pull = 10.minutes, init = 10.minutes, stop = 1.minutes)

def ClickhouseAdvertisedPort = 8123
def ClickhouseExposedPort = 8123
Expand All @@ -20,14 +21,14 @@ trait DockerClickhouseService extends DockerTestKitForAll { self: Suite =>
.withPortBindings((ClickhouseAdvertisedPort, PortBinding.of("0.0.0.0", ClickhouseExposedPort)))
.withReadyChecker(
DockerReadyChecker
.Jdbc(
driverClass = "com.clickhouse.jdbc.ClickHouseDriver",
user = ClickhouseUser,
password = Some(ClickhousePassword)
)
.Jdbc(
driverClass = "com.clickhouse.jdbc.ClickHouseDriver",
user = ClickhouseUser,
password = Some(ClickhousePassword)
)
.looped(15, 1.second)
)
.toContainer
)
.toContainer

override val managedContainers: ManagedContainers = clickhouseContainer.toManagedContainer
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.whisk.docker.testkit

import com.spotify.docker.client.messages.PortBinding
import org.mandas.docker.client.messages.PortBinding
import com.whisk.docker.testkit.scalatest.DockerTestKitForAll
import org.scalatest.Suite

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package com.whisk.docker.testkit.scalatest

import java.util.concurrent.ForkJoinPool

import com.spotify.docker.client.{DefaultDockerClient, DockerClient}
import org.mandas.docker.client.{DockerClient}
import com.whisk.docker.testkit._
import org.scalatest.{Args, Status, Suite, SuiteMixin}

import scala.concurrent.ExecutionContext
import scala.language.implicitConversions
import org.mandas.docker.client.builder.DockerClientBuilder

trait DockerTestKitForAll extends SuiteMixin { self: Suite =>

val dockerClient: DockerClient = DefaultDockerClient.fromEnv().build()
val dockerClient: DockerClient = DockerClientBuilder.fromEnv().build();

val dockerExecutionContext: ExecutionContext = ExecutionContext.fromExecutor(new ForkJoinPool())

Expand Down