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 +4 -4
- data/Gemfile.lock +1 -1
- data/bin/locker.rb +74 -0
- data/lib/docker_toolkit/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85978a9db4853009d0f8546931b9d516de42cd26170a71dcd1c8ec167ea6175a
|
4
|
+
data.tar.gz: 2a0b807b2492f6567cbaf774b249d84e24f30a9d69c8840d9045950ee129e454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dabbbdee8543c426eda1afec5294b26b7ea4827eb2845050357505059cb792957f4b1992aba3bb7ae1a194ea24c03744492dd982d331d9ffc00773946fb66441
|
7
|
+
data.tar.gz: d0dd1c5f840ac43d1894c5140b1f66311e5203f246052e666dd9c37625633df1e6d1ce89f8dc3b31468115433df8337f68d6ecb340df029077abbae95df37717
|
data/Gemfile.lock
CHANGED
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
|
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.
|
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-
|
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.
|
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
|