docker-spec 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/docker/spec.rb +44 -28
- data/lib/docker/spec/docker.rb +27 -25
- data/lib/docker/spec/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b8fbb164e0c9e54f85c058ec942ef0bb1c3933a
|
4
|
+
data.tar.gz: 5aa7c913127434f13c0e88a1cc86ca038ced9ee0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd1d7db5d4a15c0a72fc63a2ef340e70dbb57ccd29daaa8a3e5d56dc4d428180f777beba5f2302ea9a1f12bd02cd193b402c32de82375bb90fa0a2ec05aa77c2
|
7
|
+
data.tar.gz: 2d6788a53853f3a1149a4917b6cc3c0eacaac1ba70ea600181b41dd3c74424c906a9260f0edb6270c095c501a3b33b52e4774b8a8019372035ab1f489e84a37a
|
data/lib/docker/spec.rb
CHANGED
@@ -10,27 +10,36 @@ require 'colorize'
|
|
10
10
|
require 'yaml'
|
11
11
|
require 'logger'
|
12
12
|
require 'moneta'
|
13
|
-
require
|
13
|
+
require 'base64'
|
14
|
+
require 'singleton'
|
14
15
|
require 'pp'
|
15
16
|
|
16
17
|
# Documentation
|
17
|
-
|
18
|
+
class DockerSpec
|
19
|
+
|
20
|
+
include Singleton
|
21
|
+
|
22
|
+
attr_accessor :config, :test_failed
|
23
|
+
|
18
24
|
CONTAINER_RUN_WAIT_TIMEOUT = 60
|
19
25
|
CONFIG_FILE = 'docker_spec.yml'
|
20
26
|
ROOT_DIR = 'root'
|
21
27
|
DOCKER_AUTH_FILE = '~/.docker/config.json'
|
22
28
|
STDOUT.sync = true
|
23
29
|
|
24
|
-
def
|
30
|
+
def run
|
31
|
+
@config = nil
|
32
|
+
@test_failed = false
|
33
|
+
|
25
34
|
load_config
|
26
35
|
build_root if @config[:build_root]
|
27
|
-
build_docker_image
|
28
|
-
|
36
|
+
build_docker_image if @config[:build_image]
|
37
|
+
rspec_configure
|
29
38
|
end
|
30
39
|
|
31
|
-
def
|
32
|
-
@config[:push_container] =
|
33
|
-
|
40
|
+
def push
|
41
|
+
@config[:push_container] = get_config(:push_container, 'DOCKER_SPEC_PUSH_CONTAINER',
|
42
|
+
'Push new tag? ')
|
34
43
|
if @config[:push_container]
|
35
44
|
|
36
45
|
@config[:tag_db] ||
|
@@ -81,7 +90,7 @@ module DockerSpec
|
|
81
90
|
end
|
82
91
|
end
|
83
92
|
|
84
|
-
def
|
93
|
+
def load_config
|
85
94
|
File.exist?(CONFIG_FILE) || fail('Could not load docker_spec.yml')
|
86
95
|
@config = YAML.load(File.read(CONFIG_FILE)) ||
|
87
96
|
fail('docker_spec.yml is not a valid yml file')
|
@@ -90,21 +99,24 @@ module DockerSpec
|
|
90
99
|
@config[:account] || fail('account is not defined in docker_spec.yml')
|
91
100
|
@config[:image_name] = format '%s/%s', @config[:account], @config[:name]
|
92
101
|
@config[:container_name] = format 'docker_spec-%s', @config[:name]
|
93
|
-
@config[:
|
94
|
-
|
95
|
-
@config[:
|
96
|
-
|
102
|
+
@config[:build_image] = get_config(:build_image, 'DOCKER_SPEC_BUILD_',
|
103
|
+
'Build docker image? ')
|
104
|
+
@config[:build_root] = get_config(:build_root, 'DOCKER_SPEC_BUILD_ROOT',
|
105
|
+
'Rebuild root filesystem? ') if @config[:build_image]
|
106
|
+
@config[:clear_cache] = get_config(:clear_cache, 'DOCKER_SPEC_CLEAR_CACHE',
|
107
|
+
'Clear docker cache? ') if @config[:build_image]
|
97
108
|
@config
|
98
109
|
end
|
99
110
|
|
100
|
-
def
|
111
|
+
def build_root
|
101
112
|
system 'bash -ec \'sudo chown root:root -R root &&' \
|
102
113
|
'(cd root && sudo tar zcf ../root.tar.gz .) && ' \
|
103
114
|
'sudo chown -R `id -u`:`id -g` root.tar.gz root\'' \
|
104
115
|
if Dir.exist?(ROOT_DIR)
|
105
116
|
end
|
106
117
|
|
107
|
-
def
|
118
|
+
def build_docker_image
|
119
|
+
puts
|
108
120
|
# Rebuild the cache filesystem
|
109
121
|
build_args = ''
|
110
122
|
build_args += ' --no-cache' if @config[:clear_cache]
|
@@ -118,26 +130,30 @@ module DockerSpec
|
|
118
130
|
fail("#{build_cmd} failed") if status.exitstatus != 0
|
119
131
|
end
|
120
132
|
|
121
|
-
def
|
133
|
+
def rspec_configure
|
122
134
|
set :backend, :docker
|
123
135
|
|
124
136
|
RSpec.configure do |rc|
|
125
137
|
rc.fail_fast = true
|
126
138
|
|
139
|
+
rc.after(:each) do |test|
|
140
|
+
DockerSpec.instance.test_failed = true if test.exception
|
141
|
+
end
|
142
|
+
|
127
143
|
rc.before(:suite) do
|
128
|
-
DockerSpec.delete_container
|
129
|
-
DockerSpec.start_container
|
144
|
+
DockerSpec.instance.delete_container
|
145
|
+
DockerSpec.instance.start_container
|
130
146
|
end
|
131
147
|
|
132
148
|
rc.after(:suite) do
|
133
|
-
DockerSpec.clean_up
|
134
|
-
DockerSpec.push
|
149
|
+
DockerSpec.instance.clean_up
|
150
|
+
DockerSpec.instance.push unless DockerSpec.instance.test_failed
|
135
151
|
end
|
136
152
|
end
|
137
|
-
docker_tests
|
153
|
+
Docker::Spec::docker_tests
|
138
154
|
end
|
139
155
|
|
140
|
-
def
|
156
|
+
def start_container
|
141
157
|
# Run the container with options
|
142
158
|
opts = {}
|
143
159
|
opts['HostConfig'] = { 'NetworkMode' => @config[:network_mode] } \
|
@@ -160,7 +176,7 @@ module DockerSpec
|
|
160
176
|
set :docker_container, container.id
|
161
177
|
end
|
162
178
|
|
163
|
-
def
|
179
|
+
def delete_container
|
164
180
|
filters = { name: [@config[:container_name]] }.to_json
|
165
181
|
Docker::Container.all(all: true, filters: filters).each do |c|
|
166
182
|
c.kill
|
@@ -168,10 +184,10 @@ module DockerSpec
|
|
168
184
|
end
|
169
185
|
end
|
170
186
|
|
171
|
-
def
|
187
|
+
def clean_up
|
172
188
|
# Keep container running
|
173
|
-
@config[:keep_running] =
|
174
|
-
|
189
|
+
@config[:keep_running] = get_config(:keep_running, 'DOCKER_SPEC_KEEP_RUNNING',
|
190
|
+
"\nKeep container running? ")
|
175
191
|
if @config[:keep_running]
|
176
192
|
puts "\nINFO: To connect to a running container: \n\n" \
|
177
193
|
"docker exec -ti #{@config[:container_name]} bash"
|
@@ -180,14 +196,14 @@ module DockerSpec
|
|
180
196
|
end
|
181
197
|
end
|
182
198
|
|
183
|
-
def
|
199
|
+
def get_config(key, envvar, question)
|
184
200
|
value = to_boolean(ENV[envvar])
|
185
201
|
value = @config[key] if value.nil?
|
186
202
|
value = agree(question, 'n') if value.nil?
|
187
203
|
value
|
188
204
|
end
|
189
205
|
|
190
|
-
def
|
206
|
+
def to_boolean(str)
|
191
207
|
str == 'true' unless str.nil?
|
192
208
|
end
|
193
209
|
end
|
data/lib/docker/spec/docker.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module Docker
|
2
|
+
module Spec
|
3
|
+
def self.docker_tests
|
4
|
+
describe 'Running a docker container' do
|
5
|
+
before(:all) do
|
6
|
+
@config = DockerSpec.instance.config
|
7
|
+
@image = Docker::Image.all.detect do |i|
|
8
|
+
i.info['RepoTags'].include?(@config[:image_name] + ':latest')
|
9
|
+
end
|
10
|
+
@container = Docker::Container.all.select do |c|
|
11
|
+
c.info["Names"] == [ "/" + @config[:container_name] ]
|
12
|
+
end.first
|
8
13
|
end
|
9
|
-
@container = Docker::Container.all.select do |c|
|
10
|
-
c.info["Names"] == [ "/" + @config[:container_name] ]
|
11
|
-
end.first
|
12
|
-
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
it 'should be available' do
|
16
|
+
expect(@image).to_not be_nil
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
it 'should have state running' do
|
20
|
+
expect(@container.json['State']['Running']).to be true
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
it 'Should stay running' do
|
24
|
+
expect(@container.json['State']['Running']).to be true
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
it 'Should not have exit processes' do
|
28
|
+
expect(@container.logs(stdout: true)).to_not match(/exit/)
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
it 'Services supervisor should be running' do
|
32
|
+
expect(process('supervisord')).to be_running
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
data/lib/docker/spec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Breinlinger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|