docker-compose-api 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  [![Build Status](https://travis-ci.org/mauricioklein/docker-compose-api.svg?branch=develop)](https://travis-ci.org/mauricioklein/docker-compose-api)
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
+ [![Gem Version](https://badge.fury.io/rb/docker-compose-api.svg)](https://badge.fury.io/rb/docker-compose-api)
4
5
 
5
6
  # Docker Compose Api
6
7
 
@@ -8,6 +9,14 @@ Docker Compose API provides an easy way to parse docker compose files and lift t
8
9
 
9
10
  ## Instalation
10
11
 
12
+ Install the gem in whole environment
13
+
14
+ ```ruby
15
+ gem install docker-compose-api
16
+ ```
17
+
18
+ ... or using Bundler
19
+
11
20
  ```ruby
12
21
  # Add the line below on your Gemfile...
13
22
  gem 'docker-compose-api', git: 'https://github.com/mauricioklein/docker-compose-api'
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "simplecov"
25
26
  end
@@ -30,7 +30,7 @@ class Compose
30
30
 
31
31
  links.each do |link|
32
32
  dependency_container = @containers[link]
33
- container.dependencies << dependency_container
33
+ container.add_dependency(dependency_container)
34
34
  end
35
35
  end
36
36
  end
@@ -3,7 +3,7 @@ require_relative 'compose_port'
3
3
  require_relative '../utils/compose_utils'
4
4
 
5
5
  class ComposeContainer
6
- attr_reader :attributes, :dependencies
6
+ attr_reader :attributes
7
7
 
8
8
  def initialize(hash_attributes)
9
9
  @attributes = {
@@ -18,6 +18,7 @@ class ComposeContainer
18
18
  }.reject{ |key, value| value.nil? }
19
19
 
20
20
  # Docker client variables
21
+ @internal_image = nil
21
22
  @container = nil
22
23
  @dependencies = []
23
24
  end
@@ -34,13 +35,14 @@ class ComposeContainer
34
35
 
35
36
  # Build or pull image
36
37
  if @attributes.key?(:image)
37
- if image_exists
38
- Docker::Image.get(@attributes[:image])
39
- else
40
- Docker::Image.create('fromImage' => @attributes[:image])
38
+ @internal_image = @attributes[:image]
39
+
40
+ unless image_exists(@internal_image)
41
+ Docker::Image.create('fromImage' => @internal_image)
41
42
  end
42
43
  elsif @attributes.key?(:build)
43
- Docker::Image.build_from_dir(@attributes[:build])
44
+ @internal_image = SecureRandom.hex # Random name for image
45
+ Docker::Image.build_from_dir(@attributes[:build], {t: @internal_image})
44
46
  end
45
47
  end
46
48
 
@@ -70,7 +72,7 @@ class ComposeContainer
70
72
  end
71
73
 
72
74
  container_config = {
73
- Image: @attributes[:image],
75
+ Image: @internal_image,
74
76
  Cmd: @attributes[:command],
75
77
  Env: @attributes[:environment],
76
78
  Volumes: @attributes[:volumes],
@@ -105,8 +107,8 @@ class ComposeContainer
105
107
  #
106
108
  # Check if a given image already exists in host
107
109
  #
108
- def image_exists
109
- Docker::Image.exist?(@attributes[:image])
110
+ def image_exists(image_name)
111
+ Docker::Image.exist?(image_name)
110
112
  end
111
113
 
112
114
  public
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module DockerCompose
2
2
  def self.version
3
- "1.0.0"
3
+ "1.0.1"
4
4
  end
5
5
  end
@@ -0,0 +1,2 @@
1
+ FROM ubuntu
2
+ CMD ["sleep", "1000"]
@@ -44,7 +44,7 @@ describe ComposeContainer do
44
44
  end
45
45
 
46
46
  context 'Start container' do
47
- it 'should start/stop a container' do
47
+ it 'should start/stop a container from image' do
48
48
  attributes = {
49
49
  image: 'ubuntu:latest',
50
50
  links: ['links:links'],
@@ -64,6 +64,24 @@ describe ComposeContainer do
64
64
  expect(entry.running?).to be false
65
65
  end
66
66
 
67
+ it 'should start/stop a container from build' do
68
+ attributes = {
69
+ build: File.expand_path('spec/docker-compose/fixtures/'),
70
+ links: ['links:links'],
71
+ volumes: {'/tmp' => {}}
72
+ }
73
+
74
+ entry = ComposeContainer.new(attributes)
75
+
76
+ #Start container
77
+ entry.start
78
+ expect(entry.running?).to be true
79
+
80
+ # Stop container
81
+ entry.stop
82
+ expect(entry.running?).to be false
83
+ end
84
+
67
85
  it 'should not start a container without either image and build commands' do
68
86
  attributes = {
69
87
  links: ['links:links'],
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
+ require 'simplecov'
3
4
  require 'codeclimate-test-reporter'
5
+
6
+ SimpleCov.start
4
7
  CodeClimate::TestReporter.start
5
8
 
6
9
  require 'docker-compose'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-compose-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: A simple ruby client for docker-compose api
63
79
  email:
64
80
  - mauricio.klein.msk@gmail.com
@@ -80,6 +96,7 @@ files:
80
96
  - lib/docker-compose/utils/compose_utils.rb
81
97
  - lib/version.rb
82
98
  - spec/docker-compose/docker_compose_spec.rb
99
+ - spec/docker-compose/fixtures/Dockerfile
83
100
  - spec/docker-compose/fixtures/sample1.yaml
84
101
  - spec/docker-compose/models/compose_container_spec.rb
85
102
  - spec/docker-compose/utils/compose_utils_spec.rb
@@ -111,6 +128,7 @@ specification_version: 3
111
128
  summary: A simple ruby client for docker-compose api
112
129
  test_files:
113
130
  - spec/docker-compose/docker_compose_spec.rb
131
+ - spec/docker-compose/fixtures/Dockerfile
114
132
  - spec/docker-compose/fixtures/sample1.yaml
115
133
  - spec/docker-compose/models/compose_container_spec.rb
116
134
  - spec/docker-compose/utils/compose_utils_spec.rb