Skip to content

Commit

Permalink
Use DockerCommand from ActionContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
chetanmeh committed Jul 6, 2018
1 parent 62a1cc5 commit 304d0be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object ActionContainer {
}.get // This fails if the docker binary couldn't be located.
}

private lazy val dockerCmd: String = {
lazy val dockerCmd: String = {
/*
* The docker host is set to a provided property 'docker.host' if it's
* available; otherwise we check with WhiskProperties to see whether we are
Expand Down
26 changes: 3 additions & 23 deletions tests/src/test/scala/whisk/core/database/s3/S3Minio.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

package whisk.core.database.s3

import java.io.File
import java.net.ServerSocket

import actionContainers.ActionContainer
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.typesafe.config.ConfigFactory
import common.{SimpleExec, StreamLogging, WhiskProperties}
import common.{SimpleExec, StreamLogging}
import org.scalatest.{BeforeAndAfterAll, FlatSpec}
import whisk.common.{Logging, TransactionId}
import whisk.core.database.{AttachmentStore, DocumentSerializer}
Expand Down Expand Up @@ -96,33 +96,13 @@ trait S3Minio extends FlatSpec with BeforeAndAfterAll with StreamLogging {

private def dockerExec(cmd: String): String = {
implicit val tid: TransactionId = TransactionId.testing
val command = s"$dockerCmd $cmd"
val command = s"${ActionContainer.dockerCmd} $cmd"
val cmdSeq = command.split(" ").map(_.trim).filter(_.nonEmpty)
val (out, err, code) = SimpleExec.syncRunCmd(cmdSeq)
assert(code == 0, s"Error occurred for command '$command'. Exit code: $code, Error: $err")
out
}

//Taken from ActionContainer
private lazy val dockerBin: String = {
List("/usr/bin/docker", "/usr/local/bin/docker")
.find { bin =>
new File(bin).isFile
}
.getOrElse(???) // This fails if the docker binary couldn't be located.
}

private lazy val dockerCmd: String = {
val version = WhiskProperties.getProperty("whisk.version.name")
// Check if we are running on docker-machine env.
val hostStr = if (version.toLowerCase().contains("mac")) {
s" --host tcp://${WhiskProperties.getMainDockerEndpoint} "
} else {
""
}
s"$dockerBin $hostStr"
}

private def freePort(): Int = {
val socket = new ServerSocket(0)
try socket.getLocalPort
Expand Down

0 comments on commit 304d0be

Please sign in to comment.