fig-lock 0.0.3 → 0.0.4

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: 4453dbec342b8d6c9cb86dbb7e340b83f44744c5
4
- data.tar.gz: 7785f5c0d8a99c4b15f9e66559859db006583d73
3
+ metadata.gz: 5725237716eb5ccde18daf104f0192aab5735553
4
+ data.tar.gz: 6443d0bf27f86d65fa7102583c8cad1bf5f7775e
5
5
  SHA512:
6
- metadata.gz: 2d4f8ce39f1e4b620523d36987d0cce5b17e343acdbf980d305557f7c5ffba1c2ee481821b11d9792ced5de6a352149f980ca2738fe80b050355830e35c73903
7
- data.tar.gz: b39672201de01be9cdc7658ac9074069ed6f8b9273df04c2b8f7946c1a38224b810e1dcbbe9b1d3d517107b61722096dd654d3906bef4f405a888240997af3d2
6
+ metadata.gz: cb4e45b27431019a26068972b4773e423477285a726b9ef5655c6c6ae08b336d4f55e79667317bb7a8d13f49c2380a0e5a09c0e6b588acd7d59ba491255c4c51
7
+ data.tar.gz: 93f73a8de32e927eadf0b69113c69cba07fd449227804524d1b9973476c7c841c1c0fc165ab2b14d39f279686dd1337d28aa4f44cd056225fdd7c3c32c674b56
@@ -18,11 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "rest-client"
21
22
  spec.add_dependency "slop"
22
-
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
26
  spec.add_development_dependency "simplecov"
27
-
28
27
  end
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'fig/lock/docker_client'
2
3
  require 'fig/lock/log'
3
4
  require 'fig/lock/version'
4
5
 
@@ -46,10 +47,7 @@ module Fig
46
47
  def update
47
48
  log.info "Generating lock file for #{file} ..."
48
49
  hash = YAML.load(File.read(file))
49
-
50
- fetch_images(hash)
51
50
  select_latest(hash)
52
-
53
51
  File.write(lock_file, hash.to_yaml)
54
52
  end
55
53
 
@@ -67,13 +65,23 @@ module Fig
67
65
  log.info "Selecting latest tags:"
68
66
  hash.each do |k,v|
69
67
  image = v['image']
68
+ image = "#{image}:latest" unless image.index(':')
69
+ log.info "Selecting latest tag for #{image} ..."
70
70
  unless image.nil?
71
- output = `sudo docker images #{image}`
72
- fail "Unable to list image: #{image}.\n\tExit code:#{$?.exitstatus}\n\tOutput:#{output}" unless $?.exitstatus.zero?
73
- tag = output.split("\n")[1].split(' ')[1]
74
- tagged_image = "#{image}:#{tag}"
75
- log.info "Resolved: #{tagged_image}"
76
- v['image'] = tagged_image
71
+ # Fetch tags
72
+ tags = docker_client.tags(image)
73
+ latest = tags['latest']
74
+ fail "Image #{image} has no latest tag" if latest.nil?
75
+
76
+ # Figure out which one corresponds to "latest"
77
+ version = tags.detect{|k,v|
78
+ v == latest && k != 'latest'
79
+ }
80
+ version = version[0] if version
81
+ fail "No matching version found for hash #{latest}" unless version
82
+
83
+ # Update hash
84
+ v['image'] = "#{image[0..image.rindex(':')-1]}:#{version}"
77
85
  end
78
86
  end
79
87
  end
@@ -84,7 +92,6 @@ module Fig
84
92
  hash.each do |k,v|
85
93
  image = v['image']
86
94
  if image
87
- image = "#{image}:latest" unless image.index(':')
88
95
  log.info "Fetching #{image} ..."
89
96
  system "sudo docker pull #{image}"
90
97
  fail "Unable to fetch image: #{image}.\n\tExit code:#{$?.exitstatus}" unless $?.exitstatus.zero?
@@ -98,6 +105,10 @@ module Fig
98
105
  fail("file must be specified") unless hash[:file]
99
106
  end
100
107
  end
108
+
109
+ def docker_client
110
+ @docker_client ||= DockerClient.new
111
+ end
101
112
  end
102
113
 
103
114
  # Default values for parameters
@@ -114,4 +125,6 @@ module Fig
114
125
  end
115
126
  end
116
127
  end
128
+
129
+
117
130
  end
@@ -0,0 +1,39 @@
1
+ require 'base64'
2
+ require 'json'
3
+ require 'rest-client'
4
+ require 'fig/lock/version'
5
+
6
+ module Fig
7
+ class Lock::DockerClient
8
+
9
+ attr_reader :cfg
10
+
11
+ def initialize(file="#{ENV['HOME']}/.dockercfg")
12
+ @cfg = JSON.parse(File.read(file))
13
+ end
14
+
15
+ def tags(repo)
16
+ array = repo.split('/')
17
+ registry = array[0]
18
+ repo = array[1]
19
+ name = array[2]
20
+ if name.index(':')
21
+ name = name.split(':')[0]
22
+ end
23
+
24
+ resource = base(registry)['v1']['repositories'][repo][name]['tags']
25
+ JSON.parse(resource.get.body)
26
+ end
27
+
28
+ def base(registry)
29
+ config = cfg[registry]
30
+ if config
31
+ auth = Base64.decode64(config['auth'])
32
+ RestClient::Resource.new("https://#{auth}@#{registry}")
33
+ else
34
+ RestClient::Resource.new("https://#{registry}")
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module Fig
2
2
  class Lock
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -0,0 +1,52 @@
1
+ $:.unshift(File.join(__dir__, '..', '..', '..', 'spec'))
2
+ require 'json'
3
+ require 'fig/spec_helper'
4
+
5
+ class Fig::Lock
6
+ describe DockerClient do
7
+
8
+ context 'with basic auth' do
9
+ let (:auth) {
10
+ {'some.repo.com' => {'auth'=> Base64.encode64('user:password')}}
11
+ }
12
+
13
+ it 'should retrieve tags' do
14
+ expect(ENV).to receive(:[]).with('HOME'){'/path/to/home'}
15
+ expect(File).to receive(:read).with('/path/to/home/.dockercfg'){auth.to_json}
16
+ expect(RestClient::Resource).to receive(:new).with('https://user:password@some.repo.com'){resource}
17
+ client = DockerClient.new
18
+ expect(client.tags('some.repo.com/repo/name:latest')).to eq tags
19
+ end
20
+ end
21
+
22
+ context 'without basic auth' do
23
+ let (:auth) { {} }
24
+
25
+ it 'should retrieve tags' do
26
+ expect(ENV).to receive(:[]).with('HOME'){'/path/to/home'}
27
+ expect(File).to receive(:read).with('/path/to/home/.dockercfg'){auth.to_json}
28
+ expect(RestClient::Resource).to receive(:new).with('https://some.repo.com'){resource}
29
+ client = DockerClient.new
30
+ expect(client.tags('some.repo.com/repo/name:latest')).to eq tags
31
+ end
32
+
33
+ end
34
+
35
+ private
36
+
37
+ def resource
38
+ @resource ||= double('resource').tap do |r|
39
+ allow(r).to receive_message_chain(:[], :[], :[], :[], :[], :get, :body){tags.to_json}
40
+ end
41
+ end
42
+
43
+ def tags
44
+ {
45
+ 'latest' => 'some_hash',
46
+ 'some_other_tag' => 'some_hash'
47
+ }
48
+ end
49
+
50
+ end
51
+ end
52
+
@@ -1,14 +1,4 @@
1
- $:.unshift(File.join(__dir__, '..', '..', 'lib'))
2
-
3
- RSpec.configure do |config|
4
- require 'simplecov'
5
- SimpleCov.add_filter 'vendor'
6
- SimpleCov.add_filter 'spec'
7
- SimpleCov.start
8
- end
9
-
10
-
11
- require 'fig/lock'
1
+ require 'spec_helper'
12
2
 
13
3
  module Fig
14
4
 
@@ -45,6 +35,7 @@ module Fig
45
35
  allow(File).to receive(:directory?).with('fig.yml'){false}
46
36
  allow(File).to receive(:read).with('fig.yml'){yaml}
47
37
  allow(File).to receive(:read).with('fig.lock'){yaml}
38
+ allow(Lock::DockerClient).to receive(:new){docker_client}
48
39
  end
49
40
 
50
41
  it 'should install' do
@@ -65,11 +56,7 @@ module Fig
65
56
 
66
57
  it 'should update' do
67
58
  lock = Fig::Lock.new(registry: 'some.docker.com', file:'fig.yml')
68
-
69
- expect(lock).to receive(:system).with('sudo docker pull some.docker.com/atlas/api'){true}
70
- expect(lock).to receive(:`).with('sudo docker images some.docker.com/atlas/api'){docker_image_output}
71
59
  expect(File).to receive(:write).with('fig.lock', expected_fig_lock)
72
-
73
60
  lock.update
74
61
  end
75
62
 
@@ -95,6 +82,14 @@ web:
95
82
  image: some.docker.com/atlas/api
96
83
  eos
97
84
  end
85
+
86
+ def docker_client
87
+ @docker_client ||= double('docker-client', tags: tags)
88
+ end
89
+
90
+ def tags
91
+ @tags ||= {'latest'=>'hash', '20140611142604'=>'hash'}
92
+ end
98
93
  end
99
94
  end
100
95
  end
@@ -0,0 +1,13 @@
1
+ $:.unshift(File.join(__dir__), '..', '..', 'lib')
2
+ $:.unshift(File.join(__dir__), '..', '..', 'spec')
3
+
4
+ require 'rspec'
5
+
6
+ RSpec.configure do |config|
7
+ require 'simplecov'
8
+ SimpleCov.add_filter 'vendor'
9
+ SimpleCov.add_filter 'spec'
10
+ SimpleCov.start
11
+ end
12
+
13
+ require 'fig/lock'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fig-lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Shea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: slop
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -97,9 +111,12 @@ files:
97
111
  - fig-lock.gemspec
98
112
  - lib/fig/lock.rb
99
113
  - lib/fig/lock/cli.rb
114
+ - lib/fig/lock/docker_client.rb
100
115
  - lib/fig/lock/log.rb
101
116
  - lib/fig/lock/version.rb
117
+ - spec/fig/lock/docker_client_spec.rb
102
118
  - spec/fig/lock_spec.rb
119
+ - spec/fig/spec_helper.rb
103
120
  homepage: ''
104
121
  licenses:
105
122
  - MIT
@@ -125,4 +142,6 @@ signing_key:
125
142
  specification_version: 4
126
143
  summary: Generates fig.lock files from fig.yml files
127
144
  test_files:
145
+ - spec/fig/lock/docker_client_spec.rb
128
146
  - spec/fig/lock_spec.rb
147
+ - spec/fig/spec_helper.rb