Skip to content

Commit

Permalink
Merge #206 - Fixed container name matching for containers with multip…
Browse files Browse the repository at this point in the history
…le names.

- Filter out technical names when loading the current container resource.
- Made container name matching more strict.
- Fixed container name matching for containers with multiple names.
  • Loading branch information
Tom Duffield committed Oct 24, 2014
1 parent 2520194 commit 383cc5f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions providers/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,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)
Expand All @@ -166,13 +166,12 @@ def container_image_matches?(image)
end

def container_name_matches?(names)
return false unless names && new_resource.container_name
return true if names.split(',').include?(new_resource.container_name)
false
return false unless 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 && names.split(',').include?(new_resource.container_name)
return container_name_matches?(names) if new_resource.container_name
true
end

Expand Down Expand Up @@ -242,6 +241,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
Expand Down

0 comments on commit 383cc5f

Please sign in to comment.