dockerkit 0.1.9 → 0.2.0
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.
- checksums.yaml +4 -4
- data/lib/concerns/dkcomposer_task.rb +141 -0
- data/lib/dockerkit/version.rb +1 -1
- data/lib/dockerkit.rb +5 -4
- data/lib/ext.rb +10 -0
- data/lib/templates/stack.dk.rb +13 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8bb1f3647305e3a620cecf5bcdce1ae2d2ccadb
|
4
|
+
data.tar.gz: d7bb0c78407e7542ad906045ec9f14d1ae6f7f05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93557fb4dd9f3c9709c6980d991f0f47f2f2a97b65dbc5ffd714c838eb8aed56bd91358cf7968198c4fb05fae81613411ddfd084d640cfeefba333d5782a92ab
|
7
|
+
data.tar.gz: 85d3854fdb004bef2e5e8821a4981a4c958bba6a0395b2107bda79598d40c54e7ad194a0fa1c330302fe4a402646f83cd9f998f8e20fb5fa1352dcfc243230e6
|
@@ -0,0 +1,141 @@
|
|
1
|
+
module DkComposerTasks
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
module ClassMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
included do
|
7
|
+
desc 'lsa [KEYWORD] [-I loadpath] ', <<-LONG
|
8
|
+
'list all applications which app name match the patten'
|
9
|
+
example:
|
10
|
+
dk lsa #list all apps
|
11
|
+
dk lsa test #search all apps which's name include string test;
|
12
|
+
dk lsa -I somepath #list all apps include with your specific path
|
13
|
+
LONG
|
14
|
+
method_option :loadpaths, type: :array, aliases: 'I'
|
15
|
+
def lsa(keyword = nil)
|
16
|
+
auto_load(options[:loadpaths])
|
17
|
+
ret = DkComposer::STACK.select { |_k, v| /#{keyword}/ =~ v.name.to_s }
|
18
|
+
print_table ret.to_table(:name, :shortdesc)
|
19
|
+
ret
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'lsi [KEYWORD] [-I loadpath] ', <<-LONG
|
23
|
+
'list all images which name match the patten'
|
24
|
+
example:
|
25
|
+
dk lsi #list all images
|
26
|
+
dk lsi test #search all images which's name include string test;
|
27
|
+
dk lsi test -f #search all images which's name include string test and only output dockerfile;
|
28
|
+
dk lsi -I somepath #list all images include with your specific path
|
29
|
+
LONG
|
30
|
+
method_option :loadpaths, type: :array, aliases: 'I'
|
31
|
+
method_option :dockerfile, type: :boolean, aliases: 'f'
|
32
|
+
|
33
|
+
def lsi(keyword = nil)
|
34
|
+
auto_load(options[:loadpaths])
|
35
|
+
ret = DkComposer::IMAGE.select { |k, v| /#{keyword}/ =~ k.to_s && v && /:latest$/ !~ k.to_s }
|
36
|
+
if options[:dockerfile]
|
37
|
+
|
38
|
+
ret.each do |k, v|
|
39
|
+
puts ["#-------------image:#{k}--------------",
|
40
|
+
v.to_docker_file,
|
41
|
+
''].join("\n")
|
42
|
+
end
|
43
|
+
else
|
44
|
+
print_table ret.to_table(:name, :tag, :from, :use, :repos, :shortdesc)
|
45
|
+
end
|
46
|
+
ret
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'image [name] [build,pull,push]', <<-LONG
|
50
|
+
'image actions'
|
51
|
+
example:
|
52
|
+
dk image #list all apps and ask one for image
|
53
|
+
dk image test param1 param2 #list all apps which's name include string test and ask one for image and pass the params in;
|
54
|
+
dk image -I somepath #list all apps and ask one for image and include with your specific path
|
55
|
+
LONG
|
56
|
+
method_option :loadpaths, type: :array, aliases: 'I'
|
57
|
+
|
58
|
+
def image(*params)
|
59
|
+
name, action, = params
|
60
|
+
auto_load(options[:loadpaths])
|
61
|
+
ret = DkComposer::IMAGE.select { |k, v| /#{name}/ =~ k.to_s && v && /:latest$/ !~ k.to_s }
|
62
|
+
return say('There is no image avaliable'.red) if ret.empty?
|
63
|
+
img = if ret.count > 1
|
64
|
+
ask_and_select(ret, :name, :tag, :from, :use, :repos, :shortdesc)
|
65
|
+
else
|
66
|
+
print_table ret.to_table(:name, :tag, :from, :use, :repos, :shortdesc)
|
67
|
+
ret.to_a.first.last
|
68
|
+
end
|
69
|
+
return unless img
|
70
|
+
actions = %w[pull build push]
|
71
|
+
action = ask('pls input a correct action to the image', limited_to: actions.unshift('q')) if action.nil? || !actions.include?(action.to_s)
|
72
|
+
return if action == 'q'
|
73
|
+
say(img.send(action.to_sym))
|
74
|
+
end
|
75
|
+
|
76
|
+
desc 'up [KEYWORD]', <<-LONG
|
77
|
+
'up application which app name match the patten'
|
78
|
+
example:
|
79
|
+
dk up #list all apps and ask one for up
|
80
|
+
dk up test param1 param2 #list all apps which's name include string test and ask one for up and pass the params in;
|
81
|
+
dk up -I somepath #list all apps and ask one for up and include with your specific path
|
82
|
+
LONG
|
83
|
+
method_option :loadpaths, type: :array, aliases: 'I'
|
84
|
+
|
85
|
+
def up(*params)
|
86
|
+
name, params = params
|
87
|
+
if name && name.start_with?('-')
|
88
|
+
params ||= []
|
89
|
+
params.unshift name
|
90
|
+
name = nil
|
91
|
+
end
|
92
|
+
auto_load(options[:loadpaths])
|
93
|
+
ret = DkComposer::STACK.select { |_k, v| /#{keyword}/ =~ v.name.to_s }
|
94
|
+
return say('There is no app avaliable'.red) if ret.empty?
|
95
|
+
app = if ret.count > 1
|
96
|
+
ask_and_select(ret)
|
97
|
+
else
|
98
|
+
ret.to_a.first.last
|
99
|
+
end
|
100
|
+
return unless app
|
101
|
+
app.run *params
|
102
|
+
end
|
103
|
+
|
104
|
+
desc 'create appname', <<-LONG
|
105
|
+
'create application with name'
|
106
|
+
example:
|
107
|
+
dk create test #create an app with name 'test'
|
108
|
+
LONG
|
109
|
+
def create(name)
|
110
|
+
auto_load(options[:loadpaths])
|
111
|
+
@opt = { name: name }
|
112
|
+
ret = DkComposer::SERVICE
|
113
|
+
print_table ret.to_table(:name, :shortdesc, :longdesc)
|
114
|
+
answers = multi_ask('Add a service into the app,input the service name', limited_to: ret.keys.map(&:to_s).unshift(''))
|
115
|
+
@opt[:services] = answers.uniq
|
116
|
+
template("#{self.class.source_root}/templates/stack.dk.rb", "#{name}.dk.rb")
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def ask_and_select(h, *cols)
|
122
|
+
cols = %i[name shortdesc] if cols.empty?
|
123
|
+
print_table h.to_table(*cols, with_index: true)
|
124
|
+
say('which app you want to up?'.blue)
|
125
|
+
answer = ask('(q=QUIT;n=)', limited_to: ['q', *('1'..h.count.to_s).to_a])
|
126
|
+
return nil if answer == 'q'
|
127
|
+
h.to_a[answer.to_i - 1].last
|
128
|
+
end
|
129
|
+
|
130
|
+
def auto_load(loadpaths = [])
|
131
|
+
loadpaths ||= []
|
132
|
+
loadpaths.unshift '.'
|
133
|
+
loadpaths.concat(ENV['DK_LOAD_PATH'].split(':')).uniq!
|
134
|
+
loadpaths.each do |path|
|
135
|
+
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
136
|
+
dk_pattern = "#{path}/*.dk.rb"
|
137
|
+
Dir[dk_pattern].each { |dkfile| require dkfile }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/lib/dockerkit/version.rb
CHANGED
data/lib/dockerkit.rb
CHANGED
@@ -10,7 +10,8 @@ require 'models/base'
|
|
10
10
|
require 'models/alias'
|
11
11
|
require 'models/container'
|
12
12
|
require 'models/image'
|
13
|
-
|
13
|
+
require 'ext'
|
14
|
+
require 'dkcomposer'
|
14
15
|
# Dir[File.dirname(__FILE__) + '/models/*.rb'].each { |file| require file }
|
15
16
|
Dir[File.dirname(__FILE__) + '/concerns/*.rb'].each { |file| require file }
|
16
17
|
|
@@ -27,7 +28,7 @@ module Dockerkit
|
|
27
28
|
include Thor::Actions
|
28
29
|
include ContainerTasks
|
29
30
|
include ImageTasks
|
30
|
-
|
31
|
+
include DkComposerTasks
|
31
32
|
source_root File.dirname(__FILE__)
|
32
33
|
|
33
34
|
desc 'alias [NAME] [CMD]', <<-LONG
|
@@ -131,11 +132,11 @@ module Dockerkit
|
|
131
132
|
!File.exist?(file)
|
132
133
|
end
|
133
134
|
|
134
|
-
def multi_ask(question)
|
135
|
+
def multi_ask(question, **opt)
|
135
136
|
ret = []
|
136
137
|
answer = 'start'
|
137
138
|
until answer.empty?
|
138
|
-
answer = ask("#{question.red},(
|
139
|
+
answer = ask("#{question.red},(null input to end the question)", opt).chomp
|
139
140
|
ret.push answer unless answer.empty?
|
140
141
|
end
|
141
142
|
ret
|
data/lib/ext.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
class Hash
|
2
|
+
def to_table(*headers, **opts)
|
3
|
+
data = each_with_index.map do |(_key, item), index|
|
4
|
+
ret = headers.map { |field| item.send(field) }
|
5
|
+
ret[0] = "[#{index + 1}] #{ret[0]}" if opts[:with_index]
|
6
|
+
ret
|
7
|
+
end.uniq
|
8
|
+
data.unshift(headers.map(&:upcase))
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
desc '<%=@opt[:name]%> image', ''
|
2
|
+
image(:"<%= @opt[:name] %>")
|
3
|
+
|
4
|
+
desc '<%=@opt[:name]%> service', ''
|
5
|
+
service(:"<%=@opt[:name]%>") do
|
6
|
+
image :"<%=@opt[:name]%>"
|
7
|
+
end
|
8
|
+
|
9
|
+
desc '<%=@opt[:name]%> stack', ''
|
10
|
+
stack(:"<%=@opt[:name]%>", version: '2.1') do
|
11
|
+
service(:"<%=@opt[:name]%>")
|
12
|
+
<%=@opt[:services].map{|s| "service(:#{s})"}.join("\n")%>
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockerkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shaoyang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: dkcomposer
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: activesupport
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,15 +164,18 @@ files:
|
|
150
164
|
- lib/alias.yml
|
151
165
|
- lib/concerns/constants.rb
|
152
166
|
- lib/concerns/container_tasks.rb
|
167
|
+
- lib/concerns/dkcomposer_task.rb
|
153
168
|
- lib/concerns/image_tasks.rb
|
154
169
|
- lib/dockerkit.rb
|
155
170
|
- lib/dockerkit/version.rb
|
171
|
+
- lib/ext.rb
|
156
172
|
- lib/models/alias.rb
|
157
173
|
- lib/models/base.rb
|
158
174
|
- lib/models/container.rb
|
159
175
|
- lib/models/image.rb
|
160
176
|
- lib/templates/Dockerfile
|
161
177
|
- lib/templates/docker-compose.yml
|
178
|
+
- lib/templates/stack.dk.rb
|
162
179
|
homepage: http://github.com/yushaoyang
|
163
180
|
licenses:
|
164
181
|
- MIT
|