docker_toolkit 0.1.23 → 0.1.24

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
  SHA256:
3
- metadata.gz: fdb91997423fc5dd86b7c26f586fe6e04e7f1a2eefadf397802537b613a52359
4
- data.tar.gz: 4d5111ad64589a5c201d49d44d76b4b037588ea708df4ac64b21d0f065c1801d
3
+ metadata.gz: 85978a9db4853009d0f8546931b9d516de42cd26170a71dcd1c8ec167ea6175a
4
+ data.tar.gz: 2a0b807b2492f6567cbaf774b249d84e24f30a9d69c8840d9045950ee129e454
5
5
  SHA512:
6
- metadata.gz: f2faa78e0a6a92b5318e04993afdf0ed54d95551130d4d8da3fc522a8c59fb261b6efe7f87445cac70ff4cc9810d7417bfb6303b196ffda15f0d2693ede1cf46
7
- data.tar.gz: ca940063d3755981f4a0d103a8ffe1e488e862f6c9adcba77b5184233ac8382cde2a5168333869e573ea703e713fa1cc42f1aa4f19e237b925ad8001ca3347fd
6
+ metadata.gz: dabbbdee8543c426eda1afec5294b26b7ea4827eb2845050357505059cb792957f4b1992aba3bb7ae1a194ea24c03744492dd982d331d9ffc00773946fb66441
7
+ data.tar.gz: d0dd1c5f840ac43d1894c5140b1f66311e5203f246052e666dd9c37625633df1e6d1ce89f8dc3b31468115433df8337f68d6ecb340df029077abbae95df37717
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docker_toolkit (0.1.23)
4
+ docker_toolkit (0.1.24)
5
5
  diplomat
6
6
  dotenv
7
7
  json
data/bin/locker.rb ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'diplomat'
5
+ require 'json'
6
+
7
+ @opts = {
8
+ url: 'http://localhost:8080',
9
+ timeout: 10,
10
+ ttl: 30*60,
11
+ }
12
+
13
+ parser = OptionParser.new do |o|
14
+ o.banner = 'Usage: locker.rb [options]'
15
+
16
+ o.on("--consul url=#{@opts[:url]}", 'Set up a custom Consul URL') do |url|
17
+ Diplomat.configure do |config|
18
+ config.url = url.strip
19
+ end
20
+ end
21
+
22
+ o.on("--lock resource", 'resource name to lock with Consul') do |resource|
23
+ @opts[:lock] = resource.strip
24
+ end
25
+
26
+ o.on("--ttl seconds=#{@opts[:ttl]}", 'TTL to set when session created') do |seconds|
27
+ @opts[:ttl] = Integer(seconds.strip)
28
+ end
29
+
30
+ o.on("--unlock session", 'session name from previous call lock') do |session|
31
+ @opts[:unlock] = session.strip
32
+ end
33
+
34
+ o.on("--timeout seconds=#{@opts[:timeout]}", 'timeout to wait lock') do |seconds|
35
+ @opts[:timeout] = Integer(seconds.strip)
36
+ end
37
+
38
+ end
39
+ parser.parse!
40
+
41
+
42
+ def lock session, locker, timeout
43
+ Timeout::timeout(timeout) do
44
+ return Diplomat::Lock.wait_to_acquire("/resource/#{locker[:resource]}/lock", session, locker.to_json, 10)
45
+ end
46
+
47
+ rescue Timeout::Error => e
48
+ return false
49
+ end
50
+
51
+
52
+ if resource = @opts[:lock]
53
+ locker = {
54
+ Name: "#{resource}_locker_#{rand(999999)}",
55
+ Behavior: 'delete',
56
+ TTL: "#{@opts[:ttl]}s",
57
+ resource: resource,
58
+ }
59
+ sessionid = Diplomat::Session.create(locker)
60
+
61
+ if lock(sessionid, locker, @opts[:timeout])
62
+ puts sessionid
63
+ exit 0
64
+ else
65
+ STDERR.puts "Failed to lock resource: #{resource}"
66
+ exit 1
67
+ end
68
+
69
+ elsif session = @opts[:unlock]
70
+ Diplomat::Session.destroy(session)
71
+ else
72
+ STDERR.puts parser.help
73
+ exit 1
74
+ end
@@ -1,5 +1,5 @@
1
1
  module DockerToolkit
2
2
 
3
- VERSION = '0.1.23'.freeze
3
+ VERSION = '0.1.24'.freeze
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Godko Ivan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-05 00:00:00.000000000 Z
12
+ date: 2018-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: diplomat
@@ -87,6 +87,7 @@ email:
87
87
  - kinnalru@gmail.com
88
88
  executables:
89
89
  - consul.rb
90
+ - locker.rb
90
91
  - merger.rb
91
92
  - terminator.rb
92
93
  - waiter.rb
@@ -102,6 +103,7 @@ files:
102
103
  - Gemfile.lock
103
104
  - README.md
104
105
  - bin/consul.rb
106
+ - bin/locker.rb
105
107
  - bin/merger.rb
106
108
  - bin/terminator.rb
107
109
  - bin/waiter.rb
@@ -161,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
163
  version: '0'
162
164
  requirements: []
163
165
  rubyforge_project:
164
- rubygems_version: 2.7.7
166
+ rubygems_version: 2.7.3
165
167
  signing_key:
166
168
  specification_version: 4
167
169
  summary: Helper scripts for work with docker and consul