From acc8296916648a5187378200581fdaa2aabe8d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Pervill=C3=A9?= Date: Fri, 29 Aug 2014 17:11:31 +0200 Subject: [PATCH 1/3] Fixed container name matching for containers with multiple names. --- providers/container.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/container.rb b/providers/container.rb index 8d66087729..ab6cd99f5a 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -151,11 +151,11 @@ def container_image_matches?(image) def container_name_matches?(names) return false unless names - new_resource.container_name && new_resource.container_name == names + new_resource.container_name && names.split(',').include?(new_resource.container_name) end def container_name_matches_if_exists?(names) - return false if new_resource.container_name && new_resource.container_name != names + return container_name_matches?(names) if new_resource.container_name true end From cac59af37714e53aa2786797580b5262cc824793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Pervill=C3=A9?= Date: Fri, 29 Aug 2014 17:14:47 +0200 Subject: [PATCH 2/3] Made container name matching more strict. --- providers/container.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/container.rb b/providers/container.rb index ab6cd99f5a..27776b2918 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -128,7 +128,7 @@ def container_matches?(ps) return false unless container_image_matches?(ps['image']) return false unless container_command_matches_if_exists?(ps['command']) return false unless container_name_matches_if_exists?(ps['names']) - true + false end def container_command_matches_if_exists?(command) From 50b73cc7b21c5211a723f8cc6e132f8aec058eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Pervill=C3=A9?= Date: Fri, 29 Aug 2014 17:20:40 +0200 Subject: [PATCH 3/3] Filter out technical names when loading the current container resource. --- providers/container.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/providers/container.rb b/providers/container.rb index 27776b2918..6999b0aab4 100644 --- a/providers/container.rb +++ b/providers/container.rb @@ -225,6 +225,10 @@ def docker_containers end ps[name.to_s] = line[start..finish - 1].strip end + # Filter out technical names (eg. 'my-app/db'), which appear in ps['names'] + # when a container has at least another container linking to it. If these + # names are not filtered they will pollute current_resource.container_name. + ps['names'] = ps['names'].split(',').grep( /\A[^\/]+\Z/ ).join(',') # technical names always contain a '/' ps end end