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

Add withFileSystemBind + name parameters #206

Merged
merged 3 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class FixedHostPortGenericContainer(imageName: String,
classpathResourceMapping: Seq[(String, String, BindMode)] = Seq(),
waitStrategy: Option[WaitStrategy] = None,
exposedHostPort: Int,
exposedContainerPort: Int
exposedContainerPort: Int,
fileSystemBind: Seq[(String, String, BindMode)] = Seq()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Just realized that I haven't submitted another comment - would it make sense to introduce a case class instead of tuple? otherwise, we need to make it more easier to understand what first two string params are.

Copy link
Contributor Author

@benkio benkio Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to have that, what do you think is the best place to put such case class? as a name, I'm thinking about FileSystemBinding and we can use it also for the classpath binding (even if it's a change break, but at least we are consistent). Let me know your thoughts ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it's reasonable

) extends SingleContainer[JavaFixedHostPortGenericContainer[_]] {

override implicit val container: JavaFixedHostPortGenericContainer[_] = new JavaFixedHostPortGenericContainer(imageName)
Expand All @@ -23,26 +24,32 @@ class FixedHostPortGenericContainer(imageName: String,
container.withCommand(command: _*)
}
classpathResourceMapping.foreach{ case (r, c, m) => container.withClasspathResourceMapping(r, c, m) }
fileSystemBind.foreach{ case (r, c, m) => container.withFileSystemBind(r, c, m) }
waitStrategy.foreach(container.waitingFor)
container.withFixedExposedPort(exposedHostPort, exposedContainerPort)
}

object FixedHostPortGenericContainer {
def apply(imageName: String,
exposedPorts: Seq[Int] = Seq(),
env: Map[String, String] = Map(),
command: Seq[String] = Seq(),
classpathResourceMapping: Seq[(String, String, BindMode)] = Seq(),
waitStrategy: WaitStrategy = null,
exposedHostPort: Int,
exposedContainerPort: Int): FixedHostPortGenericContainer=
new FixedHostPortGenericContainer(imageName,
exposedPorts,
env,
command,
classpathResourceMapping,
Option(waitStrategy),
exposedHostPort,
exposedContainerPort
def apply(
imageName: String,
exposedPorts: Seq[Int] = Seq(),
env: Map[String, String] = Map(),
command: Seq[String] = Seq(),
classpathResourceMapping: Seq[(String, String, BindMode)] = Seq(),
waitStrategy: WaitStrategy = null,
exposedHostPort: Int,
exposedContainerPort: Int,
fileSystemBind: Seq[(String, String, BindMode)] = Seq()
): FixedHostPortGenericContainer=
new FixedHostPortGenericContainer(
imageName = imageName,
exposedPorts = exposedPorts,
env = env,
command = command,
classpathResourceMapping = classpathResourceMapping,
fileSystemBind = fileSystemBind,
waitStrategy = Option(waitStrategy),
exposedHostPort = exposedHostPort,
exposedContainerPort = exposedContainerPort
)
}
107 changes: 73 additions & 34 deletions core/src/main/scala/com/dimafeng/testcontainers/GenericContainer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class GenericContainer(
waitStrategy: Option[WaitStrategy] = None,
labels: Map[String, String] = Map.empty,
tmpFsMapping: Map[String, String] = Map.empty,
imagePullPolicy: Option[ImagePullPolicy] = None
imagePullPolicy: Option[ImagePullPolicy] = None,
fileSystemBind: Seq[(String, String, BindMode)] = Seq()
) = this({
val underlying: JavaGenericContainer[_] = dockerImage match {
case DockerImage(Left(imageFromDockerfile)) => new JavaGenericContainer(imageFromDockerfile)
Expand All @@ -39,6 +40,7 @@ class GenericContainer(
underlying.withCommand(command: _*)
}
classpathResourceMapping.foreach{ case (r, c, m) => underlying.withClasspathResourceMapping(r, c, m) }
fileSystemBind.foreach{ case (r, c, m) => underlying.withFileSystemBind(r, c, m) }
waitStrategy.foreach(underlying.waitingFor)

if (labels.nonEmpty) {
Expand Down Expand Up @@ -68,17 +70,30 @@ object GenericContainer {
DockerImage(Left(imageName))
}

def apply(dockerImage: DockerImage,
exposedPorts: Seq[Int] = Seq(),
env: Map[String, String] = Map(),
command: Seq[String] = Seq(),
classpathResourceMapping: Seq[(String, String, BindMode)] = Seq(),
waitStrategy: WaitStrategy = null,
labels: Map[String, String] = Map.empty,
tmpFsMapping: Map[String, String] = Map.empty,
imagePullPolicy: ImagePullPolicy = null): GenericContainer =
new GenericContainer(dockerImage, exposedPorts, env, command, classpathResourceMapping, Option(waitStrategy), labels, tmpFsMapping,
Option(imagePullPolicy))
def apply(
dockerImage: DockerImage,
exposedPorts: Seq[Int] = Seq(),
env: Map[String, String] = Map(),
command: Seq[String] = Seq(),
classpathResourceMapping: Seq[(String, String, BindMode)] = Seq(),
waitStrategy: WaitStrategy = null,
labels: Map[String, String] = Map.empty,
tmpFsMapping: Map[String, String] = Map.empty,
imagePullPolicy: ImagePullPolicy = null,
fileSystemBind: Seq[(String, String, BindMode)] = Seq()
): GenericContainer =
new GenericContainer(
dockerImage = dockerImage,
exposedPorts = exposedPorts,
env = env,
command = command,
classpathResourceMapping = classpathResourceMapping,
fileSystemBind = fileSystemBind,
waitStrategy = Option(waitStrategy),
labels = labels,
tmpFsMapping = tmpFsMapping,
imagePullPolicy = Option(imagePullPolicy)
)

abstract class Def[C <: GenericContainer](init: => C) extends ContainerDef {
override type Container = C
Expand All @@ -87,32 +102,56 @@ object GenericContainer {

object Def {

private final case class Default(dockerImage: DockerImage,
exposedPorts: Seq[Int] = Seq(),
env: Map[String, String] = Map(),
command: Seq[String] = Seq(),
classpathResourceMapping: Seq[(String, String, BindMode)] = Seq(),
waitStrategy: WaitStrategy = null,
labels: Map[String, String] = Map.empty,
tmpFsMapping: Map[String, String] = Map.empty,
imagePullPolicy: ImagePullPolicy = null) extends Def[GenericContainer](
private final case class Default(
dockerImage: DockerImage,
exposedPorts: Seq[Int] = Seq(),
env: Map[String, String] = Map(),
command: Seq[String] = Seq(),
classpathResourceMapping: Seq[(String, String, BindMode)] = Seq(),
waitStrategy: WaitStrategy = null,
labels: Map[String, String] = Map.empty,
tmpFsMapping: Map[String, String] = Map.empty,
imagePullPolicy: ImagePullPolicy = null,
fileSystemBind: Seq[(String, String, BindMode)] = Seq()
) extends Def[GenericContainer](
GenericContainer(
dockerImage, exposedPorts, env, command, classpathResourceMapping, waitStrategy,
labels, tmpFsMapping, imagePullPolicy)
dockerImage = dockerImage,
exposedPorts = exposedPorts,
env = env,
command = command,
classpathResourceMapping = classpathResourceMapping,
fileSystemBind = fileSystemBind,
waitStrategy = waitStrategy,
labels = labels,
tmpFsMapping = tmpFsMapping,
imagePullPolicy = imagePullPolicy
)
)

def apply(dockerImage: DockerImage,
exposedPorts: Seq[Int] = Seq(),
env: Map[String, String] = Map(),
command: Seq[String] = Seq(),
classpathResourceMapping: Seq[(String, String, BindMode)] = Seq(),
waitStrategy: WaitStrategy = null,
labels: Map[String, String] = Map.empty,
tmpFsMapping: Map[String, String] = Map.empty,
imagePullPolicy: ImagePullPolicy = null): GenericContainer.Def[GenericContainer] =
def apply(
dockerImage: DockerImage,
exposedPorts: Seq[Int] = Seq(),
env: Map[String, String] = Map(),
command: Seq[String] = Seq(),
classpathResourceMapping: Seq[(String, String, BindMode)] = Seq(),
waitStrategy: WaitStrategy = null,
labels: Map[String, String] = Map.empty,
tmpFsMapping: Map[String, String] = Map.empty,
imagePullPolicy: ImagePullPolicy = null,
fileSystemBind: Seq[(String, String, BindMode)] = Seq()
): GenericContainer.Def[GenericContainer] =
Default(
dockerImage, exposedPorts, env, command, classpathResourceMapping, waitStrategy,
labels, tmpFsMapping, imagePullPolicy)
dockerImage = dockerImage,
exposedPorts = exposedPorts,
env = env,
command = command,
classpathResourceMapping = classpathResourceMapping,
fileSystemBind = fileSystemBind,
waitStrategy = waitStrategy,
labels = labels,
tmpFsMapping = tmpFsMapping,
imagePullPolicy = imagePullPolicy
)

}

Expand Down