Skip to content
Merged
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
4 changes: 2 additions & 2 deletions lib/src/commonMain/kotlin/org/katan/yoki/YokiConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private const val DOCKER_HOST_ENV_KEY = "DOCKER_HOST"

public class YokiConfig {

public var socketPath: String = ""
public var socketPath: String = DEFAULT_DOCKER_UNIX_SOCKET

/**
* The version of the Docker API that will be used during communication.
Expand All @@ -27,7 +27,7 @@ public class YokiConfig {
* Equivalent to:
* ```kotlin
* Yoki {
* socketPath = "unix:///var/run/docker.sock"
* socketPath = "unix://var/run/docker.sock"
* }
* ```
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import kotlin.jvm.JvmName
internal const val UNIX_SOCKET_PREFIX = "unix://"
internal const val HTTP_SOCKET_PREFIX = "tcp://"

public const val DEFAULT_DOCKER_UNIX_SOCKET: String = "$UNIX_SOCKET_PREFIX/var/run/docker.sock"
public const val DEFAULT_DOCKER_UNIX_SOCKET: String = "${UNIX_SOCKET_PREFIX}/var/run/docker.sock"
public const val DEFAULT_DOCKER_HTTP_SOCKET: String = "${HTTP_SOCKET_PREFIX}localhost:2375"
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ContainerResource internal constructor(
parameter("all", options.all)
parameter("limit", options.limit)
parameter("size", options.size)
parameter("filters", json.encodeToString(raw))
parameter("filters", options.filters?.let(json::encodeToString))
}.body()
}

Expand Down
6 changes: 4 additions & 2 deletions lib/src/jvmMain/kotlin/org/katan/yoki/io/SocketDns.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package org.katan.yoki.io
import okhttp3.Dns
import java.net.InetAddress

internal class SocketDns : Dns {
internal class SocketDns(
val isUnixSocket: Boolean,
) : Dns {

override fun lookup(hostname: String): List<InetAddress> {
return if (hostname.endsWith(".socket")) listOf(
return if (isUnixSocket) listOf(
InetAddress.getByAddress(
hostname,
byteArrayOf(0, 0, 0, 0)
Expand Down
12 changes: 8 additions & 4 deletions lib/src/jvmMain/kotlin/org/katan/yoki/io/configureHttpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.ktor.http.Url
import io.ktor.http.contentType
import io.ktor.http.encodedPath
import io.ktor.http.takeFrom
import okio.ByteString.Companion.encodeUtf8
import org.katan.yoki.Yoki
import java.util.concurrent.TimeUnit

Expand All @@ -23,9 +24,11 @@ internal actual fun <T : HttpClientEngineConfig> HttpClientConfig<out T>.configu
require(this is OkHttpConfig) { "Only OkHttp engine is supported for now" }

config {
if (isUnixSocket(client.config.socketPath))
val isUnixSocket = isUnixSocket(client.config.socketPath)
if (isUnixSocket) {
socketFactory(UnixSocketFactory())
dns(SocketDns())
}
dns(SocketDns(isUnixSocket))
readTimeout(0, TimeUnit.MILLISECONDS)
connectTimeout(0, TimeUnit.MILLISECONDS)
callTimeout(0, TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -54,13 +57,14 @@ private fun isUnixSocket(input: String): Boolean {
}

private fun createUrlBuilder(socketPath: String): URLBuilder {
val url = Url(socketPath)
return if (isUnixSocket(socketPath)) {
URLBuilder(
protocol = URLProtocol.HTTP,
host = "docker.socket"
port = 2375,
host = socketPath.substringAfter(UNIX_SOCKET_PREFIX).encodeUtf8().hex() + ".socket"
)
} else {
val url = Url(socketPath)
URLBuilder(
protocol = URLProtocol.HTTP,
host = url.host,
Expand Down