infopen-docker 0.2.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94ca42d731e85d57fc86dc7447df2d4378fd2ebb
4
+ data.tar.gz: efcb13e191ab8baab287f4823e6347597470898d
5
+ SHA512:
6
+ metadata.gz: 567575d1a903d37e6e3ca8d0ae99b44c2a3b76bbbed9e344af7a524e1e9a674c9d5af3450931b19883bfb2add1f5b7abdaae17d2eea5197032698adc4915466b
7
+ data.tar.gz: 9f2018241d4bb0255f203e65a7e67ff9b03ecb1ccc2d3d6f62fafaa6879937124dffc31cae07e0c8f9c61bfc078158591125969c99c91cee560dc05a91385727
@@ -0,0 +1,72 @@
1
+ ##
2
+ # This module contains tests about docker images and containers lifecycle
3
+
4
+ module Infopen::Docker::Lifecycle
5
+
6
+ require 'docker'
7
+ include Infopen::Docker::Error
8
+
9
+
10
+ ##
11
+ # Remove image and its containers.
12
+ #
13
+ # Raise an ArgumentError if bad param number
14
+ #
15
+ # Raise an Infopen::Docker::ArgumentError if param is not a
16
+ # Docker::Image instance
17
+ #
18
+ # Raise an Infopen::Docker::ImageError if image not exists
19
+
20
+ def self.remove_image_and_its_containers(image_obj)
21
+
22
+ # Check param
23
+ unless image_obj.is_a?(Docker::Image)
24
+ raise ArgumentError, "Expected a Docker::Image, got: #{image_obj}."
25
+ end
26
+
27
+ # Get and remove all containers linked to image
28
+ get_containers_from_image_id(image_obj.id).each do |container|
29
+ Docker::Container.get(container.id).remove(:force => true)
30
+ end
31
+
32
+ # Remove image
33
+ image_obj.remove(:force => true)
34
+ end
35
+
36
+
37
+ ##
38
+ # Get all containers created with image id param.
39
+ #
40
+ # It's a private module method.
41
+ #
42
+ # Raise an ArgumentError if bad param number
43
+ #
44
+ # Raise an Infopen::Docker::ArgumentError if param is not a
45
+ # Docker::Image instance
46
+ #
47
+ # Raise an Infopen::Docker::ImageError if image not exists
48
+
49
+ def self.get_containers_from_image_id (image_id)
50
+
51
+ # Check param type
52
+ unless image_id.is_a?(String) and image_id.length != 0
53
+ raise ArgumentError, "Expected not empty string, got: #{image_id}."
54
+ end
55
+
56
+ # Check image is valid
57
+ begin
58
+ image = Docker::Image.get(image_id)
59
+ rescue Docker::Error::NotFoundError
60
+ raise ImageError, "Image #{image_id} not exists."
61
+ end
62
+
63
+ Docker::Container.all(:all => true).select { |container|
64
+ container
65
+ .info['Image']
66
+ .start_with?(image.id)
67
+ }
68
+ end
69
+ private_class_method :get_containers_from_image_id
70
+
71
+ end
72
+
@@ -0,0 +1,22 @@
1
+ ##
2
+ # This module reference error classes for this gem
3
+
4
+ module Infopen::Docker::Error
5
+
6
+ ##
7
+ # Default error, not raised but can be used to catch gem specific errors
8
+
9
+ class InfopenDockerError < StandardError; end
10
+
11
+ ##
12
+ # Used in case of methods argument errors
13
+
14
+ class ArgumentError < InfopenDockerError; end
15
+
16
+ ##
17
+ # Used if docker image not exists
18
+
19
+ class ImageError < InfopenDockerError; end
20
+
21
+ end
22
+
@@ -0,0 +1,12 @@
1
+ # This module manage common docker tasks
2
+
3
+ module Infopen
4
+
5
+ module Infopen::Docker
6
+
7
+ require 'errors/errors'
8
+ require 'docker/lifecycle'
9
+ end
10
+
11
+ end
12
+
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infopen-docker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Chaussier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.4'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 10.4.2
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '10.4'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 10.4.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.4'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.4.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.4'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.4.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: docker-api
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.24'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.24.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.24'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.24.0
73
+ description: Used to add common functions for Dockerfile tests
74
+ email: a.chaussier@infopen.pro
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - lib/docker/lifecycle.rb
80
+ - lib/errors/errors.rb
81
+ - lib/infopen-docker.rb
82
+ homepage: https://github.com/infOpen/ruby-gem-infopen-docker
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.2.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Docker common functions
106
+ test_files: []