docker-compose-api 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc1811fa3ec42d62fb9fc334cff9f884794c5335
4
- data.tar.gz: 096cdf0b16e04b3c8b6f8ec72da9673df16e1945
3
+ metadata.gz: 8cebb75c2cb0cf0603887ddbbce8ccb0f3093591
4
+ data.tar.gz: ff991c3a6144e7cf4f9c8de8dad49c6bb823ba27
5
5
  SHA512:
6
- metadata.gz: cec2d7eb5e7b4dcf094399fb86d5693edbe738461bab5b3e1df4ae4212560d20412c8e69522008950ac67a4ad549e939f621710e846968fd0033276885206013
7
- data.tar.gz: 388f155bbb9ca0321f43952ae214d3b304bda303dabf52f45214539b3307a025580005d1257f195ca8ab045a19bc6b6e0d334c0a3f73a2c96f08cbf588443025
6
+ metadata.gz: 80c07bfaa7c3dbe956150baf4be1c6b6b860fd751946808f77b42aee9ce5e98ee61d4c14455f60426e33c9fd9edb2e2e33d93236ca3a17b0ca2d1e306a83e8e0
7
+ data.tar.gz: 5bfbf79737a2ee0a8bd8146556f9640a3b6c400cfd8ed6a23ce59632eda567917a3cbb2498bca6ea71aad8abc948973bf11ee687791cb1507926c0bd442aef21
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .byebug_history
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![Code Climate](https://codeclimate.com/github/mauricioklein/docker-compose-api/badges/gpa.svg)](https://codeclimate.com/github/mauricioklein/docker-compose-api)
3
3
  [![Test Coverage](https://codeclimate.com/github/mauricioklein/docker-compose-api/badges/coverage.svg)](https://codeclimate.com/github/mauricioklein/docker-compose-api/coverage)
4
4
  [![Gem Version](https://badge.fury.io/rb/docker-compose-api.svg)](https://badge.fury.io/rb/docker-compose-api)
5
+ [![Dependency Status](https://gemnasium.com/badges/github.com/mauricioklein/docker-compose-api.svg)](https://gemnasium.com/github.com/mauricioklein/docker-compose-api)
5
6
 
6
7
  # Docker Compose Api
7
8
 
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.7"
24
24
  spec.add_development_dependency "rspec", "~> 3.3"
25
25
  spec.add_development_dependency "simplecov", "~> 0.10"
26
+ spec.add_development_dependency "byebug", "~> 8.2"
26
27
  end
@@ -89,7 +89,9 @@ module DockerCompose
89
89
  volumes: info['Config']['Volumes'],
90
90
  command: info['Config']['Cmd'].join(' '),
91
91
  environment: info['Config']['Env'],
92
- labels: info['Config']['Labels']
92
+ labels: info['Config']['Labels'],
93
+
94
+ loaded_from_environment: true
93
95
  }
94
96
 
95
97
  ComposeContainer.new(container_args, container)
@@ -50,7 +50,7 @@ class Compose
50
50
  @containers.each_value do |container|
51
51
  links = container.attributes[:links]
52
52
 
53
- next if links.nil?
53
+ next if (container.loaded_from_environment? or links.nil?)
54
54
 
55
55
  links.each do |service, label|
56
56
  dependency_container = @containers[service]
@@ -101,6 +101,7 @@ class Compose
101
101
  #
102
102
  def delete(labels = [])
103
103
  call_container_method(:delete, labels)
104
+ delete_containers_entries(labels)
104
105
  end
105
106
 
106
107
  private
@@ -118,4 +119,14 @@ class Compose
118
119
 
119
120
  true
120
121
  end
122
+
123
+ def delete_containers_entries(labels = [])
124
+ labels = @containers.keys if labels.empty?
125
+
126
+ labels.each do |label|
127
+ @containers.delete(label)
128
+ end
129
+
130
+ true
131
+ end
121
132
  end
@@ -9,6 +9,7 @@ class ComposeContainer
9
9
  def initialize(hash_attributes, docker_container = nil)
10
10
  @attributes = {
11
11
  label: hash_attributes[:label],
12
+ loaded_from_environment: hash_attributes[:loaded_from_environment] || false,
12
13
  name: hash_attributes[:full_name] || ComposeUtils.generate_container_name(hash_attributes[:name], hash_attributes[:label]),
13
14
  image: ComposeUtils.format_image(hash_attributes[:image]),
14
15
  build: hash_attributes[:build],
@@ -26,6 +27,14 @@ class ComposeContainer
26
27
  @dependencies = []
27
28
  end
28
29
 
30
+ #
31
+ # Returns true if is a container loaded from
32
+ # environment instead compose file (i.e. a running container)
33
+ #
34
+ def loaded_from_environment?
35
+ attributes[:loaded_from_environment]
36
+ end
37
+
29
38
  private
30
39
 
31
40
  #
@@ -11,7 +11,6 @@ class DockerComposeConfig
11
11
  config = YAML.load_file(filepath)
12
12
 
13
13
  unless config
14
- STDERR.puts "Empty YAML file: #{filepath}"
15
14
  config = YAML.load('{}')
16
15
  end
17
16
 
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module DockerCompose
2
2
  def self.version
3
- "1.1.1"
3
+ "1.1.2"
4
4
  end
5
5
  end
@@ -2,8 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe DockerCompose do
4
4
  context 'Without memory' do
5
- before(:all) do
5
+ before(:each) {
6
6
  @compose = DockerCompose.load(File.expand_path('spec/docker-compose/fixtures/compose_1.yaml'))
7
+ }
8
+
9
+ after(:each) do
10
+ @compose.delete
7
11
  end
8
12
 
9
13
  it 'should be able to access gem version' do
@@ -60,9 +64,7 @@ describe DockerCompose do
60
64
 
61
65
  # Delete containers
62
66
  @compose.delete
63
- @compose.containers.values.each do |container|
64
- expect(container.exist?).to be false
65
- end
67
+ expect(@compose.containers.empty?).to be true
66
68
  end
67
69
  end
68
70
 
@@ -297,17 +299,12 @@ describe DockerCompose do
297
299
  @compose.containers['busybox3']
298
300
  ])
299
301
  end
300
-
301
- after(:all) do
302
- @compose.delete
303
- end
304
302
  end
305
303
 
306
304
  context 'With memory' do
307
305
  before(:all) do
308
306
  @compose1 = DockerCompose.load(File.expand_path('spec/docker-compose/fixtures/compose_1.yaml'), false)
309
307
  @compose1.start
310
-
311
308
  @compose2 = DockerCompose.load(File.expand_path('spec/docker-compose/fixtures/empty_compose.yml'), true)
312
309
  end
313
310
 
@@ -319,12 +316,16 @@ describe DockerCompose do
319
316
  docker_containers_compose1 = @compose1.containers.values.select { |c| c.container }
320
317
  docker_containers_compose2 = @compose2.containers.values.select { |c| c.container }
321
318
 
322
- # Check that both composes have the same containers (based on its names)
319
+ # Check that both @composes have the same containers (based on its names)
323
320
  docker_containers_compose2.each_index do |index|
324
321
  expect(docker_containers_compose2[index].attributes['Name']).to eq(docker_containers_compose1[index].attributes['Name'])
325
322
  end
326
323
  end
327
324
 
325
+ it 'expect last container from @compose2 to be assigned as loaded from environment' do
326
+ expect(@compose2.containers.values.last.loaded_from_environment?).to be true
327
+ end
328
+
328
329
  after(:all) do
329
330
  @compose1.delete
330
331
  end
@@ -122,15 +122,20 @@ describe ComposeContainer do
122
122
  end
123
123
 
124
124
  context 'From Dockerfile' do
125
- before(:all) do
126
- attributes = {
125
+ before(:all) {
126
+ @attributes = {
127
127
  label: 'foobar',
128
128
  build: File.expand_path('spec/docker-compose/fixtures/'),
129
129
  links: ['links:links'],
130
130
  volumes: ['/tmp']
131
131
  }
132
132
 
133
- @entry = ComposeContainer.new(attributes)
133
+ @entry = ComposeContainer.new(@attributes)
134
+ }
135
+
136
+ after(:all) do
137
+ Docker::Image.get(@entry.internal_image).remove(force: true)
138
+ @entry.delete
134
139
  end
135
140
 
136
141
  it 'should start/stop a container' do
@@ -154,11 +159,6 @@ describe ComposeContainer do
154
159
  @entry.stop
155
160
  expect(@entry.running?).to be false
156
161
  end
157
-
158
- after(:all) do
159
- Docker::Image.get(@entry.internal_image).remove(force: true)
160
- @entry.delete
161
- end
162
162
  end
163
163
 
164
164
  context 'Without image or Dockerfile' do
@@ -31,6 +31,14 @@ describe Compose do
31
31
  image: 'busybox:latest',
32
32
  command: 'ping -c 3 localhost'
33
33
  }
34
+
35
+ @attributes_container_from_environment = {
36
+ label: 'container_from_environment',
37
+ image: 'busybox:latest',
38
+ links: ['container3'],
39
+ command: 'ping -c 3 localhost',
40
+ loaded_from_environment: true
41
+ }
34
42
  end
35
43
 
36
44
  context 'Without dependencies' do
@@ -57,11 +65,12 @@ describe Compose do
57
65
  @compose = Compose.new
58
66
  @compose.add_container(ComposeContainer.new(@attributes_container2))
59
67
  @compose.add_container(ComposeContainer.new(@attributes_container3))
68
+ @compose.add_container(ComposeContainer.new(@attributes_container_from_environment))
60
69
  @compose.link_containers
61
70
  end
62
71
 
63
72
  it 'should have 2 containers' do
64
- expect(@compose.containers.length).to eq(2)
73
+ expect(@compose.containers.length).to eq(3)
65
74
  end
66
75
 
67
76
  it 'container2 should depend on container3' do
@@ -71,6 +80,11 @@ describe Compose do
71
80
  expect(container2.dependencies.include?(container3)).to be true
72
81
  expect(container3.dependencies.empty?).to be true
73
82
  end
83
+
84
+ it 'container loaded from environment should not have dependencies' do
85
+ container_from_environment = @compose.containers[@attributes_container_from_environment[:label]]
86
+ expect(container_from_environment.dependencies.empty?).to be true
87
+ end
74
88
  end
75
89
 
76
90
  it 'should increment label when already exists' do
@@ -53,22 +53,35 @@ describe ComposeUtils do
53
53
  end
54
54
 
55
55
  context 'Format ports from running containers' do
56
- before(:all) do
57
- @hash_attr = {
58
- '8000/tcp' => [{
59
- 'HostIp' => '0.0.0.0',
60
- 'HostPort' => '4444'
61
- }]
56
+ context 'filled port attributes' do
57
+ let(:hash_attr) {
58
+ {
59
+ '8000/tcp' => [{
60
+ 'HostIp' => '0.0.0.0',
61
+ 'HostPort' => '4444'
62
+ }]
63
+ }
62
64
  }
63
- @expected_format = ['8000:0.0.0.0:4444']
65
+ let(:expected_format) { ['8000:0.0.0.0:4444'] }
66
+
67
+ it 'should format ports correctly' do
68
+ expect(ComposeUtils.format_ports_from_running_container(hash_attr)).to eq(expected_format)
69
+ end
64
70
  end
65
71
 
66
- it 'should format ports correctly' do
67
- expect(ComposeUtils.format_ports_from_running_container(@hash_attr)).to eq(@expected_format)
72
+ context 'port without value' do
73
+ let(:hash_attr) { {'8000/tcp' => nil} }
74
+ let(:expected_format) { ['8000::'] }
75
+
76
+ it 'should format ports correctly' do
77
+ expect(ComposeUtils.format_ports_from_running_container(hash_attr)).to eq(expected_format)
78
+ end
68
79
  end
69
80
 
70
- it 'should return an empty array when ports are nil' do
71
- expect(ComposeUtils.format_ports_from_running_container(nil)).to eq([])
81
+ context 'nil port' do
82
+ it 'should return an empty array when ports are nil' do
83
+ expect(ComposeUtils.format_ports_from_running_container(nil)).to eq([])
84
+ end
72
85
  end
73
86
  end
74
87
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
+ require 'byebug'
3
4
  require 'simplecov'
4
5
  require 'codeclimate-test-reporter'
5
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-compose-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio S. Klein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-05 00:00:00.000000000 Z
11
+ date: 2016-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '8.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '8.2'
69
83
  description: A simple ruby client for docker-compose api
70
84
  email:
71
85
  - mauricio.klein.msk@gmail.com
@@ -119,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
133
  version: '0'
120
134
  requirements: []
121
135
  rubyforge_project:
122
- rubygems_version: 2.4.5
136
+ rubygems_version: 2.6.4
123
137
  signing_key:
124
138
  specification_version: 4
125
139
  summary: A simple ruby client for docker-compose api