Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Add support for Docker Compose API v2 #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion src/main/scala/com/tapad/docker/DockerCommands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ trait DockerCommands {
Process(s"docker-machine ip $machineName").!!.trim
}

def getDockerContainerId(instanceName: String, serviceName: String): String = {
def getDockerContainerIdLegacy(instanceName: String, serviceName: String): String = {
//Docker replaces '/' with '_' in the identifier string so search for replaced version
Process(s"""docker ps --all --filter=name=${instanceName.replace('/', '_')}_${serviceName}_ --format=\"{{.ID}}\"""").!!.trim().replaceAll("\"", "")
}

def getDockerContainerId(instanceName: String, serviceName: String): String = {
// support for V2 Docker Compose API https://github.com/docker/compose#about-update-and-backward-compatibility
Process(s"""docker ps --all --filter=name=${instanceName.replace('/', '_')}-${serviceName}-1 --format=\"{{.ID}}\"""").!!.trim().replaceAll("\"", "")
}

def getDockerContainerInfo(containerId: String): String = {
Process(s"docker inspect --type=container $containerId").!!
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/com/tapad/docker/DockerComposePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,15 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo
if (verbose)
print(s"Waiting for container Id to be available for service '$serviceName' time remaining: ${deadline.timeLeft.toSeconds}")

val containerIdLegacy = getDockerContainerIdLegacy(instanceName, serviceName)
val containerId = getDockerContainerId(instanceName, serviceName)
val finalContainerId = if (containerIdLegacy.isEmpty) containerId else containerIdLegacy

if (containerId.isEmpty) {
if (finalContainerId.isEmpty) {
Thread.sleep(2000)
tryGetContainerId(state, instanceName, serviceName, deadline)
} else {
Some(containerId)
Some(finalContainerId)
}
}
case false => None
Expand Down