-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Cognifide/host-internal-ip
Host internal IP always auto determined
- Loading branch information
Showing
4 changed files
with
23 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/cognifide/gradle/environment/docker/runtime/Base.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
package com.cognifide.gradle.environment.docker.runtime | ||
|
||
import com.cognifide.gradle.environment.EnvironmentExtension | ||
import com.cognifide.gradle.environment.docker.DockerProcess | ||
import com.cognifide.gradle.environment.docker.Runtime | ||
|
||
abstract class Base(protected val environment: EnvironmentExtension) : Runtime { | ||
|
||
protected val logger = environment.project.logger | ||
|
||
override fun toString(): String = name.toLowerCase() | ||
|
||
@Suppress("SpreadOperator", "TooGenericExceptionCaught") | ||
protected fun detectHostInternalIp(): String? = try { | ||
DockerProcess.execString { | ||
val args = listOf("run", "alpine", "/bin/ash", "-c", "ip -4 route list match 0/0 | cut -d ' ' -f 3") | ||
withArgs(*args.toTypedArray()) | ||
}.takeIf { it.isNotBlank() } | ||
} catch (e: Exception) { | ||
logger.debug("Cannot detect Docker host internal IP. Cause: ${e.message}", e) | ||
null | ||
} | ||
} |
This file contains 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
This file contains 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