bigrig 0.2.2 → 0.3.0

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: d20693edd19fd3772463838bf41ac7a525541e83
4
- data.tar.gz: 86f2dacffa8ff0ad6cba5170f6b7f5e73605dfdc
3
+ metadata.gz: 0a3826a554c69d11fbf7ad4e527cd9ec53e2ba42
4
+ data.tar.gz: 1ddc2fb0fe457a8c371c9f5f60c67342e8749566
5
5
  SHA512:
6
- metadata.gz: 65cfa236bf4374f8b9522aa852246a701125378f6653ad1692e508facc3f8485314ba00d5ceea63125c2714f3a3177ae2f5be85b4bc08743a15990bd150d79e9
7
- data.tar.gz: e7b721bd63a21e55d62bc6fe9c2df8cc1e7ffad0617cc891db53cfc0edd754e871a75bfeb840557656ce69577d1bdfb17e67cb02bf2e0098ff8cf2ee55455747
6
+ metadata.gz: e6ed6256a98e9895f8bdf61cecdc73aed139ec5c99054d693448794885ac5528209cd6e396685b91f92c8201fb3808587079f45cb9c1f688d3bff7ef34f8ba37
7
+ data.tar.gz: 40690cf035320de5b847a43fc24ccad61393f67c071d4b0c8be36eb1e48000b050b2d4528d321a5a7937f88023b05d07f217e3b9bb6eeee55efb2201098f3fac
data/CHANGELOG.md CHANGED
@@ -43,3 +43,7 @@ Add `volumes` attriute
43
43
  0.2.2
44
44
  =====
45
45
  * scanned containers no longer restart their dependencies
46
+
47
+ 0.3.0
48
+ =====
49
+ * Honor .dockerignore, if present
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bigrig (0.2.2)
4
+ bigrig (0.3.0)
5
5
  colorize (= 0.7.5)
6
6
  docker-api (= 1.20.0)
7
7
  filewatcher (= 0.4.0)
@@ -15,7 +15,6 @@ GEM
15
15
  ast (2.0.0)
16
16
  astrolabe (1.3.0)
17
17
  parser (>= 2.2.0.pre.3, < 3.0)
18
- coderay (1.1.0)
19
18
  colorize (0.7.5)
20
19
  crack (0.4.2)
21
20
  safe_yaml (~> 1.0.0)
@@ -23,12 +22,11 @@ GEM
23
22
  docker-api (1.20.0)
24
23
  excon (>= 0.38.0)
25
24
  json
26
- excon (0.45.1)
25
+ excon (0.45.2)
27
26
  filewatcher (0.4.0)
28
27
  trollop (~> 2.0)
29
28
  gli (2.12.2)
30
29
  json (1.8.2)
31
- method_source (0.8.2)
32
30
  open4 (1.3.4)
33
31
  parser (2.2.0.pre.8)
34
32
  ast (>= 1.1, < 3.0)
@@ -37,10 +35,6 @@ GEM
37
35
  Platform (>= 0.4.0)
38
36
  open4 (>= 0.4.0)
39
37
  powerpack (0.0.9)
40
- pry (0.10.1)
41
- coderay (~> 1.1.0)
42
- method_source (~> 0.8.1)
43
- slop (~> 3.4)
44
38
  rainbow (2.0.0)
45
39
  rake (10.4.2)
46
40
  rspec (3.1.0)
@@ -80,7 +74,6 @@ PLATFORMS
80
74
  DEPENDENCIES
81
75
  bigrig!
82
76
  popen4
83
- pry
84
77
  rake
85
78
  rspec
86
79
  rspec-eventually
data/bigrig.gemspec CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency('rspec')
19
19
  s.add_development_dependency('rspec-its')
20
20
  s.add_development_dependency('rubocop')
21
- s.add_development_dependency('pry')
22
21
  s.add_development_dependency('vcr', '~> 2.9.3')
23
22
  s.add_development_dependency('webmock', '~> 1.20.4')
24
23
  s.add_development_dependency('popen4')
@@ -12,7 +12,7 @@ module Bigrig
12
12
  class DockerAdapter
13
13
  class << self
14
14
  def build(path, &block)
15
- Docker::Image.build_from_tar(Docker::Util.create_dir_tar(path), {}, connection, &block).id
15
+ Docker::Image.build_from_tar(Tar.create_dir_tar(path), {}, connection, &block).id
16
16
  end
17
17
 
18
18
  def container_exists?(name)
@@ -0,0 +1,27 @@
1
+ # This thing's pretty stupid, but it should be good enough for the majority
2
+ # of cases
3
+ #
4
+ # Right not it breaks with ^, $, [, ], and \\
5
+ module Bigrig
6
+ class GoMatcher
7
+ ESCAPES = ['.', '(', ')']
8
+ REPLACES = {
9
+ /^\/?/ => '',
10
+ /^/ => '^',
11
+ /$/ => '/',
12
+ '?' => '[^/]',
13
+ '+' => '\\\\+',
14
+ '*' => '[^/]+'
15
+ }
16
+
17
+ def initialize(glob)
18
+ ESCAPES.each { |e| glob.gsub! e, "\\#{e}" }
19
+ REPLACES.each { |k, v| glob.gsub! k, v }
20
+ @regex = %r{#{glob}} # rubocop:disable Style/RegexpLiteral
21
+ end
22
+
23
+ def matches?(path)
24
+ @regex.match("#{path}/") != nil
25
+ end
26
+ end
27
+ end
data/lib/bigrig/tar.rb ADDED
@@ -0,0 +1,48 @@
1
+ module Bigrig
2
+ class Tar
3
+ class << self
4
+ def create_dir_tar(directory)
5
+ tempfile = create_temp_file
6
+ directory += '/' unless directory.end_with?('/')
7
+
8
+ create_relative_dir_tar(directory, tempfile)
9
+
10
+ File.new(tempfile.path, 'r')
11
+ end
12
+
13
+ def create_relative_dir_tar(directory, output)
14
+ ignore_matchers = read_docker_ignore(directory).map { |x| GoMatcher.new x }
15
+
16
+ Gem::Package::TarWriter.new(output) do |tar|
17
+ Find.find(directory) do |prefixed_file_name|
18
+ unprefixed_file_name = prefixed_file_name[directory.length..-1]
19
+ ignore_matchers.detect { |x| x.matches? unprefixed_file_name } && next
20
+ add_file tar, prefixed_file_name, unprefixed_file_name
21
+ end
22
+ end
23
+ end
24
+
25
+ def add_file(tar, prefixed_file_name, unprefixed_file_name)
26
+ stat = File.stat(prefixed_file_name)
27
+
28
+ stat.file? || return
29
+ tar.add_file_simple(
30
+ unprefixed_file_name, stat.mode, stat.size
31
+ ) do |tar_file|
32
+ IO.copy_stream(File.open(prefixed_file_name, 'rb'), tar_file)
33
+ end
34
+ end
35
+
36
+ def create_temp_file
37
+ tempfile_name = Dir::Tmpname.create('out') {}
38
+ File.open(tempfile_name, 'wb+')
39
+ end
40
+
41
+ def read_docker_ignore(directory)
42
+ File.read(File.join directory, '.dockerignore').split "\n"
43
+ rescue Errno::ENOENT
44
+ []
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Bigrig
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/bigrig.rb CHANGED
@@ -2,9 +2,11 @@ require 'bigrig/actions'
2
2
  require 'bigrig/descriptor'
3
3
  require 'bigrig/dependency_graph'
4
4
  require 'bigrig/docker_adapter'
5
+ require 'bigrig/go_matcher'
5
6
  require 'bigrig/log_tailer'
6
7
  require 'bigrig/models'
7
8
  require 'bigrig/output_parser'
9
+ require 'bigrig/tar'
8
10
  require 'bigrig/runner'
9
11
  require 'bigrig/version'
10
12
 
@@ -1,4 +1,3 @@
1
- require 'pry'
2
1
  module Bigrig
3
2
  describe DockerAdapter do
4
3
 
@@ -0,0 +1,76 @@
1
+ module Bigrig
2
+ describe GoMatcher do
3
+ it 'treats leading slash as optional' do
4
+ expect(GoMatcher.new('/test').matches? 'test').to be true
5
+ expect(GoMatcher.new('test').matches? 'test').to be true
6
+ end
7
+
8
+ it 'ignores unmatched trailing portion of the path' do
9
+ expect(GoMatcher.new('test').matches? 'test/123').to be true
10
+ expect(GoMatcher.new('test').matches? 'test123/123').to be false
11
+ end
12
+
13
+ it 'matches subdirectories' do
14
+ expect(GoMatcher.new('test/123').matches? 'test/123').to be true
15
+ end
16
+
17
+ it 'escapes regex characters' do
18
+ expect(GoMatcher.new('...').matches? '...').to be true
19
+ expect(GoMatcher.new('...').matches? 'abc').to be false
20
+ expect(GoMatcher.new('(').matches? '(').to be true
21
+ expect(GoMatcher.new(')').matches? ')').to be true
22
+ expect(GoMatcher.new('+').matches? '+').to be true
23
+ expect(GoMatcher.new('{').matches? '{').to be true
24
+ expect(GoMatcher.new('}').matches? '}').to be true
25
+ end
26
+
27
+ describe '*' do
28
+ it 'matches any sequence of non-Separator characters' do
29
+ expect(GoMatcher.new('test/*/123').matches? 'test/321/123').to be true
30
+ expect(GoMatcher.new('*/*/123').matches? 'test/321/123').to be true
31
+ expect(GoMatcher.new('*/*/*').matches? 'test/321/123').to be true
32
+
33
+ expect(GoMatcher.new('*/123').matches? 'test/321/123').to be false
34
+ end
35
+ end
36
+
37
+ describe '?' do
38
+ it 'matches any single non-Separator character' do
39
+ expect(GoMatcher.new('/?est').matches? 'test').to be true
40
+ end
41
+ end
42
+
43
+ describe '[]' do
44
+ it 'matches a range of characters' do
45
+ expect(GoMatcher.new('[t]est').matches? 'test').to be true
46
+ expect(GoMatcher.new('[123t]est').matches? 'test').to be true
47
+ expect(GoMatcher.new('[a-z]est').matches? 'test').to be true
48
+ expect(GoMatcher.new('[b]est').matches? 'test').to be false
49
+ end
50
+ end
51
+
52
+ describe '[^]' do
53
+ it 'negates a range of characters' do
54
+ expect(GoMatcher.new('[^t]est').matches? 'test').to be false
55
+ end
56
+ end
57
+
58
+ describe 'c' do
59
+ it %{matches character c (c != '\\', '-', ']')} do
60
+ expect(GoMatcher.new('t').matches? 't').to be true
61
+ expect(GoMatcher.new('t').matches? 'test').to be false
62
+ end
63
+ end
64
+
65
+ describe '\\\\c' do
66
+ it 'matches character c' do
67
+ expect(GoMatcher.new('\\[').matches? '[').to be true
68
+ expect(GoMatcher.new('\\-').matches? '-').to be true
69
+ end
70
+
71
+ it 'matches \\' do
72
+ expect(GoMatcher.new('\\\\').matches? '\\').to be true
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,10 @@
1
+ module Bigrig
2
+ describe Tar do
3
+ it 'honors the .dockerignore' do
4
+ expect(Tar).to_not receive(:add_file).with anything, anything, 'ignoreme/ignore'
5
+ expect(Tar).to_not receive(:add_file).with anything, anything, 'ignoreme2/ignore'
6
+ expect(Tar).to receive(:add_file).with anything, anything, 'Dockerfile'
7
+ Bigrig::Tar.create_dir_tar 'spec/data/build'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,2 @@
1
+ ignoreme
2
+ ignoreme2
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigrig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name Here
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: pry
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: vcr
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -221,6 +207,7 @@ files:
221
207
  - lib/bigrig/dependency_graph.rb
222
208
  - lib/bigrig/descriptor.rb
223
209
  - lib/bigrig/docker_adapter.rb
210
+ - lib/bigrig/go_matcher.rb
224
211
  - lib/bigrig/log_tailer.rb
225
212
  - lib/bigrig/models.rb
226
213
  - lib/bigrig/models/application.rb
@@ -228,6 +215,7 @@ files:
228
215
  - lib/bigrig/models/container.rb
229
216
  - lib/bigrig/output_parser.rb
230
217
  - lib/bigrig/runner.rb
218
+ - lib/bigrig/tar.rb
231
219
  - lib/bigrig/version.rb
232
220
  - spec/bigrig/actions/destroy_action_spec.rb
233
221
  - spec/bigrig/actions/dev_action_spec.rb
@@ -237,15 +225,19 @@ files:
237
225
  - spec/bigrig/dependency_graph_spec.rb
238
226
  - spec/bigrig/descriptor_spec.rb
239
227
  - spec/bigrig/docker_adapter_spec.rb
228
+ - spec/bigrig/go_matcher_spec.rb
240
229
  - spec/bigrig/log_tailer_spec.rb
241
230
  - spec/bigrig/models/application_spec.rb
242
231
  - spec/bigrig/models/container_spec.rb
243
232
  - spec/bigrig/output_parser_spec.rb
233
+ - spec/bigrig/tar_spec.rb
244
234
  - spec/bigrig_spec.rb
245
235
  - spec/data/adds_volume.json
246
236
  - spec/data/adds_volumes_from.json
247
237
  - spec/data/addscontainer.json
238
+ - spec/data/build/.dockerignore
248
239
  - spec/data/build/Dockerfile
240
+ - spec/data/build/ignoreme/ignore
249
241
  - spec/data/build/test
250
242
  - spec/data/dev.json
251
243
  - spec/data/duplicate.json