Last active
February 10, 2022 15:43
-
-
Save darl/7215ec147558d371d9c34430fde2add9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SshProviderStrategy extends DockerClientProviderStrategy { | |
| private val log = LoggerFactory.getLogger(classOf[SshProviderStrategy]) | |
| private val myDevHost: String = | |
| TestcontainersConfiguration.getInstance.getEnvVarOrProperty("my.dev.host", "") | |
| private lazy val tempUnixSocket = Path.of("/tmp", "tc.ssh-" + System.nanoTime() + ".sock") | |
| private lazy val command = Seq("ssh", "-nNT", "-L", s"$tempUnixSocket:/var/run/docker.sock", myDevHost) | |
| private lazy val command2 = Seq( | |
| "ssh", | |
| myDevHost, | |
| s"socat -d -d -T60 UNIX-LISTEN:$tempUnixSocket,reuseaddr,fork UNIX-CLIENT:/var/run/docker.sock" | |
| ) | |
| override def getDescription: String = "Unix socket on remote machine forwarded with ssh" | |
| override def isApplicable: Boolean = verticalsDevHost.nonEmpty | |
| override def isPersistable: Boolean = false | |
| override def getDockerHostIpAddress: String = verticalsDevHost | |
| override lazy val getTransportConfig: TransportConfig = { | |
| log.info(s"Starting SSH session with $verticalsDevHost, socket = $tempUnixSocket") | |
| val process = command.run() | |
| val process2 = command2.run() | |
| log.info(s"SSH session started") | |
| sys.addShutdownHook { | |
| log.info("Cleaning up containers") | |
| ResourceReaper.instance().performCleanup() | |
| log.info("Stopping ssh session") | |
| process2.destroy() | |
| process2.exitValue() | |
| process.destroy() | |
| process.exitValue() | |
| Files.deleteIfExists(tempUnixSocket) | |
| log.info(s"Stopped ssh session with $verticalsDevHost") | |
| } | |
| TransportConfig | |
| .builder() | |
| .dockerHost(URI.create(s"unix://$tempUnixSocket")) | |
| .build() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment