Skip to content

Commit fb50b59

Browse files
committed
feat: Add support for M1 Mac to MySQLContainer.
1 parent 6cd56e6 commit fb50b59

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

docker-controller-scala-core/src/main/scala/com/github/j5ik2o/dockerController/DockerController.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,15 @@ private[dockerController] class DockerControllerImpl(
101101
this
102102
}
103103

104+
protected def isPlatformLinuxAmd64AtM1Mac: Boolean = false
105+
104106
protected def newCreateContainerCmd(): CreateContainerCmd = {
105-
dockerClient.createContainerCmd(repoTag)
107+
var cmd = dockerClient.createContainerCmd(repoTag)
108+
val osArch = sys.props("os.arch")
109+
if (isPlatformLinuxAmd64AtM1Mac && osArch == "aarch64") {
110+
cmd = cmd.withPlatform("linux/amd64")
111+
}
112+
cmd
106113
}
107114

108115
protected def newRemoveContainerCmd(): RemoveContainerCmd = {

docker-controller-scala-mysql/src/main/scala/com/github/j5ik2o/dockerController/mysql/MySQLController.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class MySQLController(
4747
databaseName: Option[String] = None
4848
) extends DockerControllerImpl(dockerClient, outputFrameInterval)(imageName, imageTag) {
4949

50+
override protected def isPlatformLinuxAmd64AtM1Mac: Boolean = true
51+
5052
private val environmentVariables: Map[String, String] = {
5153
val env1 = Map[String, String](
5254
"MYSQL_ROOT_PASSWORD" -> rootPassword
@@ -61,11 +63,12 @@ class MySQLController(
6163
val containerPort = ExposedPort.tcp(DefaultContainerPort)
6264
val portBinding = new Ports()
6365
portBinding.bind(containerPort, Ports.Binding.bindPort(hostPort))
64-
super
66+
val cmd = super
6567
.newCreateContainerCmd()
6668
.withEnv(environmentVariables.map { case (k, v) => s"$k=$v" }.toArray: _*)
6769
.withExposedPorts(containerPort)
6870
.withHostConfig(newHostConfig().withPortBindings(portBinding))
71+
cmd
6972
}
7073

7174
override protected def newRemoveContainerCmd(): RemoveContainerCmd = {

docker-controller-scala-mysql/src/test/scala/com/github/j5ik2o/dockerController/MySQLControllerSpec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MySQLControllerSpec extends AnyFreeSpec with DockerControllerSpecSupport w
2626
s"jdbc:mysql://$flywayDbHost:$flywayDbHostPort/$flywayDbName?useSSL=false&user=$flywayDbUserName&password=$flywayDbPassword"
2727

2828
val controller: MySQLController = MySQLController(dockerClient)(hostPort, rootPassword, databaseName = Some("test"))
29+
2930
override protected val dockerControllers: Vector[DockerController] = Vector(controller)
3031

3132
override protected val waitPredicatesSettings: Map[DockerController, WaitPredicateSetting] =
@@ -36,7 +37,7 @@ class MySQLControllerSpec extends AnyFreeSpec with DockerControllerSpecSupport w
3637
dockerHost,
3738
hostPort,
3839
(1 * testTimeFactor).seconds,
39-
Some((8 * testTimeFactor).seconds)
40+
Some((15 * testTimeFactor).seconds)
4041
)
4142
)
4243
)

0 commit comments

Comments
 (0)