docker-compose-api 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf18202df3237d79dc3ef72446eec4f226d12ec0
4
- data.tar.gz: 1810eb1c15212070d375d6bf626cd8b94ab7bd81
3
+ metadata.gz: fc1811fa3ec42d62fb9fc334cff9f884794c5335
4
+ data.tar.gz: 096cdf0b16e04b3c8b6f8ec72da9673df16e1945
5
5
  SHA512:
6
- metadata.gz: 4108355ffb6c39c9424b98ce271b83f1e992d3bfd9bbc067c5d570ba1996ec946af63de1babecb8640dfa84452eb930654060c551ecee2e23025a7bfdd6cbb75
7
- data.tar.gz: da6d88fe21804f589edcbdb5287518c0b8d9f8a9e7cbec06c701b9c43c4347a6c999ec979086bfd169b4cd5cefc0c85b622c0a04dd3269f8e7fa2829e320d8ab
6
+ metadata.gz: cec2d7eb5e7b4dcf094399fb86d5693edbe738461bab5b3e1df4ae4212560d20412c8e69522008950ac67a4ad549e939f621710e846968fd0033276885206013
7
+ data.tar.gz: 388f155bbb9ca0321f43952ae214d3b304bda303dabf52f45214539b3307a025580005d1257f195ca8ab045a19bc6b6e0d334c0a3f73a2c96f08cbf588443025
@@ -0,0 +1,26 @@
1
+ ## Description
2
+
3
+ [Add feature/bug description here]
4
+
5
+ ## How to reproduce
6
+
7
+ [Add steps on how to reproduce this issue]
8
+
9
+ ## What do you expect
10
+
11
+ [Describe what do you expect to happen]
12
+
13
+ ## What happened instead
14
+
15
+ [Describe the actual results]
16
+
17
+ ## Software:
18
+
19
+ - Ruby version: [Add ruby version here]
20
+ - Docker-compose-api gem version: [Add docker-compose-api gem version here]
21
+
22
+ ## Full backtrace
23
+
24
+ ```text
25
+ [Paste full backtrace here]
26
+ ```
@@ -0,0 +1 @@
1
+ require 'docker-compose'
@@ -1,6 +1,7 @@
1
1
  require_relative 'docker-compose/models/compose'
2
2
  require_relative 'docker-compose/models/compose_container'
3
3
  require_relative 'version'
4
+ require_relative 'docker_compose_config'
4
5
 
5
6
  require 'yaml'
6
7
  require 'docker'
@@ -22,25 +23,17 @@ module DockerCompose
22
23
  raise ArgumentError, 'Compose file doesn\'t exists'
23
24
  end
24
25
 
25
- compose = Compose.new
26
+ # Parse the docker-compose config
27
+ config = DockerComposeConfig.new(filepath)
26
28
 
27
- # Create containers from compose file
28
- _compose_entries = YAML.load_file(filepath)
29
+ compose = Compose.new
29
30
 
30
- if _compose_entries
31
- _compose_entries.each do |entry|
32
- compose.add_container(create_container(entry))
33
- end
34
- end
31
+ # Load new containers
32
+ load_containers_from_config(config, compose)
35
33
 
36
34
  # Load running containers
37
35
  if do_load_running_containers
38
- Docker::Container
39
- .all(all: true)
40
- .select {|c| c.info['Names'].last.match(/\A\/#{ComposeUtils.dir_name}\w*/) }
41
- .each do |container|
42
- compose.add_container(load_running_container(container))
43
- end
36
+ load_running_containers(compose)
44
37
  end
45
38
 
46
39
  # Perform containers linkage
@@ -49,6 +42,25 @@ module DockerCompose
49
42
  compose
50
43
  end
51
44
 
45
+ def self.load_containers_from_config(config, compose)
46
+ compose_entries = config.services
47
+
48
+ if compose_entries
49
+ compose_entries.each do |entry|
50
+ compose.add_container(create_container(entry))
51
+ end
52
+ end
53
+ end
54
+
55
+ def self.load_running_containers(compose)
56
+ Docker::Container
57
+ .all(all: true)
58
+ .select {|c| c.info['Names'].last.match(/\A\/#{ComposeUtils.dir_name}\w*/) }
59
+ .each do |container|
60
+ compose.add_container(load_running_container(container))
61
+ end
62
+ end
63
+
52
64
  def self.create_container(attributes)
53
65
  ComposeContainer.new({
54
66
  label: attributes[0],
@@ -83,5 +95,8 @@ module DockerCompose
83
95
  ComposeContainer.new(container_args, container)
84
96
  end
85
97
 
86
- private_class_method :create_container, :load_running_container
98
+ private_class_method :load_containers_from_config,
99
+ :create_container,
100
+ :load_running_containers,
101
+ :load_running_container
87
102
  end
@@ -98,8 +98,15 @@ module ComposeUtils
98
98
 
99
99
  port_entry.each do |key, value|
100
100
  container_port = key.gsub(/\D/, '').to_i
101
- host_ip = value.first['HostIp']
102
- host_port = value.first['HostPort']
101
+ # Ports that are EXPOSEd but not published won't have a Host IP/Port,
102
+ # only a Container Port.
103
+ if value.nil?
104
+ host_ip = ''
105
+ host_port = ''
106
+ else
107
+ host_ip = value.first['HostIp']
108
+ host_port = value.first['HostPort']
109
+ end
103
110
 
104
111
  entries << "#{container_port}:#{host_ip}:#{host_port}"
105
112
  end
@@ -0,0 +1,39 @@
1
+ # Support multiple versions for docker-compose configs.
2
+ class DockerComposeConfig
3
+ attr_reader :version, :services, :volumes, :networks
4
+
5
+ def initialize(filepath)
6
+ parse_docker_compose_config(filepath)
7
+ end
8
+
9
+ # Parse the docker-compose config
10
+ def parse_docker_compose_config(filepath)
11
+ config = YAML.load_file(filepath)
12
+
13
+ unless config
14
+ STDERR.puts "Empty YAML file: #{filepath}"
15
+ config = YAML.load('{}')
16
+ end
17
+
18
+ case (config['version'])
19
+ when 2,'2'
20
+ parse_version_2(config)
21
+ else
22
+ parse_version_1(config)
23
+ end
24
+ end
25
+
26
+ def parse_version_2(config)
27
+ @version = 2
28
+ @services = config['services']
29
+ @volumes = config['volumes']
30
+ @networks = config['networks']
31
+ end
32
+
33
+ def parse_version_1(config)
34
+ @version = 1
35
+ @services = config
36
+ @volumes = nil
37
+ @networks = nil
38
+ end
39
+ end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module DockerCompose
2
2
  def self.version
3
- "1.1.0"
3
+ "1.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.shared_examples 'a docker config' do
4
+ it 'should have the correct version info' do
5
+ expect(config.version).to eq config_version
6
+ end
7
+
8
+ it 'should read a YAML file correctly' do
9
+ expect(config.services.length).to eq(num_services)
10
+ end
11
+ end
12
+
13
+ describe DockerComposeConfig do
14
+ context 'Handles version 2 config' do
15
+ config_file = File.expand_path('spec/docker-compose/fixtures/compose_2.yaml')
16
+
17
+ it_behaves_like 'a docker config' do
18
+ let(:config_version) { 2 }
19
+ let(:num_services) { 3 }
20
+ let(:config) { DockerComposeConfig.new(config_file) }
21
+ end
22
+ end
23
+
24
+ context 'Handles version 1 config' do
25
+ config_file = File.expand_path('spec/docker-compose/fixtures/compose_1.yaml')
26
+
27
+ it_behaves_like 'a docker config' do
28
+ let(:config_version) { 1 }
29
+ let(:num_services) { 3 }
30
+ let(:config) { DockerComposeConfig.new(config_file) }
31
+ end
32
+ end
33
+
34
+ context 'Handles empty files' do
35
+ config_file = File.expand_path('spec/docker-compose/fixtures/empty_compose.yml')
36
+
37
+ it_behaves_like 'a docker config' do
38
+ let(:config_version) { 1 }
39
+ let(:num_services) { 0 }
40
+ let(:config) { DockerComposeConfig.new(config_file) }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,37 @@
1
+ version: 2
2
+
3
+ services:
4
+ busybox1:
5
+ image: busybox
6
+ container_name: busybox-container
7
+ ports:
8
+ - "3000"
9
+ - "8000:8000"
10
+ - "127.0.0.1:8001:8001"
11
+ expose:
12
+ - "5000"
13
+ links:
14
+ - busybox2
15
+ command: ping busybox2
16
+ environment:
17
+ - MYENV1=variable1
18
+ volumes:
19
+ - "/tmp/test:/tmp:ro"
20
+ labels:
21
+ - com.example.foo=bar
22
+
23
+ busybox2:
24
+ image: busybox
25
+ expose:
26
+ - "6000"
27
+ command: ping localhost
28
+ environment:
29
+ MYENV2: variable2
30
+ labels:
31
+ com.example.foo: bar
32
+
33
+ busybox3:
34
+ image: busybox
35
+ links:
36
+ - busybox2:bb2
37
+ command: ping localhost
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.0
4
+ version: 1.1.1
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-02-25 00:00:00.000000000 Z
11
+ date: 2016-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/ISSUE_TEMPLATE.md"
76
77
  - ".gitignore"
77
78
  - ".rspec"
78
79
  - ".travis.yml"
@@ -80,15 +81,19 @@ files:
80
81
  - LICENSE.txt
81
82
  - README.md
82
83
  - docker-compose-api.gemspec
84
+ - lib/docker-compose-api.rb
83
85
  - lib/docker-compose.rb
84
86
  - lib/docker-compose/models/compose.rb
85
87
  - lib/docker-compose/models/compose_container.rb
86
88
  - lib/docker-compose/models/compose_port.rb
87
89
  - lib/docker-compose/utils/compose_utils.rb
90
+ - lib/docker_compose_config.rb
88
91
  - lib/version.rb
92
+ - spec/docker-compose/docker_compose_config_spec.rb
89
93
  - spec/docker-compose/docker_compose_spec.rb
90
94
  - spec/docker-compose/fixtures/Dockerfile
91
95
  - spec/docker-compose/fixtures/compose_1.yaml
96
+ - spec/docker-compose/fixtures/compose_2.yaml
92
97
  - spec/docker-compose/fixtures/empty_compose.yml
93
98
  - spec/docker-compose/models/compose_container_spec.rb
94
99
  - spec/docker-compose/models/compose_spec.rb
@@ -119,9 +124,11 @@ signing_key:
119
124
  specification_version: 4
120
125
  summary: A simple ruby client for docker-compose api
121
126
  test_files:
127
+ - spec/docker-compose/docker_compose_config_spec.rb
122
128
  - spec/docker-compose/docker_compose_spec.rb
123
129
  - spec/docker-compose/fixtures/Dockerfile
124
130
  - spec/docker-compose/fixtures/compose_1.yaml
131
+ - spec/docker-compose/fixtures/compose_2.yaml
125
132
  - spec/docker-compose/fixtures/empty_compose.yml
126
133
  - spec/docker-compose/models/compose_container_spec.rb
127
134
  - spec/docker-compose/models/compose_spec.rb