small-ops 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/bin/fige +89 -0
  2. metadata +3 -1
data/bin/fige ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'small-setup'
4
+ require 'yaml'
5
+
6
+ yml = YAML.load_file('fig.yml')
7
+
8
+ env = {
9
+ 'PREFIX'=>@prefix,
10
+ 'HOST'=>@host,
11
+ 'ETCD'=>@etcd
12
+ }
13
+
14
+ @containers=[]
15
+
16
+ yml.keys.each {|k|
17
+
18
+ if !yml[k].has_key? "name" then
19
+ yml[k]['name'] = yml[k]['image'].gsub(/[^\/]+\//,'')
20
+ end
21
+
22
+ if !yml[k].has_key? "environment" then
23
+ yml[k]['environment'] = {}
24
+ end
25
+
26
+ env.keys.each{ |ke|
27
+ yml[k]['environment'][ke] = env[ke]
28
+ }
29
+
30
+ if @prefix.length >= 1 then
31
+ yml[k]['name'] = "#{@prefix}_#{yml[k]['name']}"
32
+ end
33
+
34
+ cmd = "docker run -d "
35
+ cmd << " --name #{yml[k]['name']} "
36
+
37
+ if yml[k].has_key? "ports" then
38
+ yml[k]['ports'].each {|p|
39
+ cmd << " -p #{p} "
40
+ }
41
+ end
42
+
43
+ if yml[k].has_key? "links" then
44
+ yml[k]['links'].each {|l|
45
+ cmd << " --link #{l} "
46
+ }
47
+ end
48
+
49
+ if yml[k].has_key? "volumes" then
50
+ yml[k]['volumes'].each {|v|
51
+ cmd << " -v #{v} "
52
+ }
53
+ end
54
+
55
+ if yml[k].has_key? "environment" then
56
+ yml[k]['environment'].keys.each {|ke|
57
+ cmd << " -e \"#{ke}=#{yml[k]['environment'][ke].gsub('"','\"')}\" "
58
+ }
59
+ end
60
+
61
+ cmd << " -t #{yml[k]['image']} "
62
+
63
+ if yml[k].has_key? "command" then
64
+ cmd << " #{yml[k]["command"]} "
65
+ end
66
+
67
+ cid = `#{cmd}`
68
+ @containers.push(cid)
69
+ puts "#{yml[k]['name']} = #{cid}"
70
+
71
+ }
72
+
73
+ puts `docker ps`
74
+
75
+ if @foreground then
76
+ def stop()
77
+ @containers.each {|cid|
78
+ puts `docker stop #{cid}`
79
+ puts `docker rm #{cid}`
80
+ }
81
+ exit
82
+ end
83
+ trap('SIGINT') do stop() end
84
+ trap('SIGTERM') do stop() end
85
+ while true do
86
+ sleep 5
87
+ end
88
+ end
89
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: small-ops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -17,6 +17,7 @@ executables:
17
17
  - docker2etcd
18
18
  - etcd2env
19
19
  - etcd2conf
20
+ - fige
20
21
  extensions: []
21
22
  extra_rdoc_files: []
22
23
  files:
@@ -24,6 +25,7 @@ files:
24
25
  - bin/docker2etcd
25
26
  - bin/etcd2env
26
27
  - bin/etcd2conf
28
+ - bin/fige
27
29
  homepage: https://github.com/
28
30
  licenses:
29
31
  - MIT