dklet 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -19
- data/dklet.rc +22 -9
- data/lib/dklet/cli.rb +38 -38
- data/lib/dklet/dsl.rb +6 -2
- data/lib/dklet/util.rb +1 -1
- data/lib/dklet/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cef224e6d8e6c819c7a76c4c71b06632f99f7902205a5b4ad8b199ee53907d4a
|
4
|
+
data.tar.gz: fd493858e93bcf28cf2f91ac847f4fa0ed9350f860b1309fa931fe653399e4e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 147dbf5105f07740e17891439964cfdf12fef2626dda6bc97f50390362fa7c68cc21a600c33643adf66da4d5a9dd0cba1002239bb3b42d9648be031089538d71
|
7
|
+
data.tar.gz: 8d28fbee29f3aacbdf1c0655ac83e591686b807b287fb6776803fd3df67ebd15322be7c3591ae4739355165c93416ae084b908af2ea8df3a13a3eb4aba66f399
|
data/Rakefile
CHANGED
@@ -4,22 +4,3 @@ require "rspec/core/rake_task"
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
6
|
task :default => :spec
|
7
|
-
|
8
|
-
desc 'test dklet gem'
|
9
|
-
task :test do
|
10
|
-
app_path = 'tmp/hidklet'
|
11
|
-
result = system <<~Desc
|
12
|
-
mkdir -p #{File.dirname(app_path)}
|
13
|
-
rm -f #{app_path}
|
14
|
-
mkdklet #{app_path}
|
15
|
-
#{app_path} help
|
16
|
-
#{app_path} # main task
|
17
|
-
#{app_path} clean --image
|
18
|
-
Desc
|
19
|
-
|
20
|
-
if result
|
21
|
-
puts 'everything ok'
|
22
|
-
else
|
23
|
-
puts 'something wrong'
|
24
|
-
end
|
25
|
-
end
|
data/dklet.rc
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
|
-
if [
|
2
|
+
if [ -z $BOOTER_DKLET_RC ];then
|
3
|
+
BOOTER_DKLET_RC=$( ruby -e "puts File.realpath('${BASH_SOURCE[0]}')")
|
4
|
+
BOOTER_DKLET_HOME=$(dirname $BOOTER_DKLET_RC)
|
5
|
+
export PATH=$PATH:$BOOTER_DKLET_HOME/exe
|
6
|
+
else
|
3
7
|
if [ -z $FORCE_RC ]; then
|
4
8
|
echo Warning: has sourced $BOOTER_DKLET_RC!
|
5
9
|
return 1
|
6
10
|
fi
|
7
11
|
fi
|
8
|
-
BOOTER_DKLET_RC=$( ruby -e "puts File.realpath('${BASH_SOURCE[0]}')")
|
9
|
-
BOOTER_DKLET_HOME=$(dirname $BOOTER_DKLET_RC)
|
10
|
-
|
11
|
-
export PATH=$PATH:$BOOTER_DKLET_HOME/exe
|
12
12
|
|
13
13
|
function dklet(){
|
14
14
|
tp=${1:-cd}
|
@@ -42,10 +42,10 @@ function dklet(){
|
|
42
42
|
gem)
|
43
43
|
gem query dklet -l
|
44
44
|
;;
|
45
|
-
gemrelease)
|
45
|
+
gemrelease|release)
|
46
46
|
$FUNCNAME cd && rake release
|
47
47
|
;;
|
48
|
-
gemup)
|
48
|
+
gemup|install)
|
49
49
|
$FUNCNAME cd && rake install:local --trace
|
50
50
|
;;
|
51
51
|
gemdown)
|
@@ -54,8 +54,21 @@ function dklet(){
|
|
54
54
|
status|st)
|
55
55
|
type -a rundklet
|
56
56
|
;;
|
57
|
-
test)
|
58
|
-
|
57
|
+
test|try)
|
58
|
+
demo=/tmp/dklet-demo
|
59
|
+
mkdir -p $(dirname $demo)
|
60
|
+
rm -f $demo
|
61
|
+
mkdklet $demo
|
62
|
+
$demo help
|
63
|
+
$demo build
|
64
|
+
$demo inspect_info
|
65
|
+
$demo clean --image
|
66
|
+
echo ==demo file at: $demo
|
67
|
+
;;
|
68
|
+
demo)
|
69
|
+
demo=/tmp/dklet-demo
|
70
|
+
[ -f $demo ] || $FUNCNAME test
|
71
|
+
cat $demo
|
59
72
|
;;
|
60
73
|
*)
|
61
74
|
$FUNCNAME help
|
data/lib/dklet/cli.rb
CHANGED
@@ -30,6 +30,7 @@ class DockletCLI < Thor
|
|
30
30
|
desc 'console', 'get ruby console'
|
31
31
|
def console
|
32
32
|
pp registry
|
33
|
+
require 'byebug'
|
33
34
|
byebug
|
34
35
|
puts "=ok"
|
35
36
|
end
|
@@ -50,41 +51,7 @@ class DockletCLI < Thor
|
|
50
51
|
option :opts, banner: 'docker run options'
|
51
52
|
option :tmp, type: :boolean, default: false, banner: 'allow run tmp container'
|
52
53
|
def runsh(cid = ops_container)
|
53
|
-
|
54
|
-
if tmprun
|
55
|
-
dkcmd = "docker run -t -d"
|
56
|
-
dkcmd += " --network #{netname}" if netname
|
57
|
-
dkcmd += " #{options[:opts]}" if options[:opts]
|
58
|
-
cid = `#{dkcmd} #{docker_image} sleep 3d`.chomp
|
59
|
-
puts "==run tmp container: #{cid}" unless options[:quiet]
|
60
|
-
end
|
61
|
-
|
62
|
-
abort "No container found!" unless cid
|
63
|
-
|
64
|
-
cmd = options[:cmd] || 'sh'
|
65
|
-
puts "run : #{cmd}" unless options[:quiet]
|
66
|
-
|
67
|
-
if cmd == 'sh' # simple case
|
68
|
-
cmds = <<~Desc
|
69
|
-
docker exec -it #{options[:opts]} #{cid} #{cmd}
|
70
|
-
Desc
|
71
|
-
else
|
72
|
-
tfile = Dklet::Util.tmpfile_for cmd
|
73
|
-
dst_file = "/tmp/dklet-#{File.basename(tfile)}-#{rand(10000)}"
|
74
|
-
# todo user permissions for pg
|
75
|
-
cmds = <<~Desc
|
76
|
-
docker cp --archive #{tfile} #{cid}:#{dst_file}
|
77
|
-
docker exec -it #{options[:opts]} #{cid} sh -c 'sh #{dst_file} && rm -f #{dst_file}'
|
78
|
-
Desc
|
79
|
-
end
|
80
|
-
puts cmds unless options[:quiet]
|
81
|
-
system cmds unless options[:dry]
|
82
|
-
|
83
|
-
if tmprun
|
84
|
-
system <<~Desc
|
85
|
-
docker rm -f #{cid}
|
86
|
-
Desc
|
87
|
-
end
|
54
|
+
container_run(options[:cmd], options.merge(cid: cid))
|
88
55
|
end
|
89
56
|
map "sh" => :runsh
|
90
57
|
|
@@ -338,10 +305,43 @@ class DockletCLI < Thor
|
|
338
305
|
klass.new.invoke(task, args, options)
|
339
306
|
end
|
340
307
|
|
341
|
-
def container_run(cmds, opts =
|
308
|
+
def container_run(cmds, opts = {})
|
309
|
+
cid = opts[:cid] || ops_container
|
310
|
+
tmprun = opts[:tmp]
|
311
|
+
if tmprun
|
312
|
+
dkcmd = "docker run -t -d"
|
313
|
+
dkcmd += " --network #{netname}" if netname
|
314
|
+
dkcmd += " #{opts[:opts]}" if opts[:opts]
|
315
|
+
cid = `#{dkcmd} #{docker_image} sleep 3d`.chomp
|
316
|
+
puts "==run tmp container: #{cid}" unless opts[:quiet]
|
317
|
+
end
|
318
|
+
abort "No container found!" unless cid
|
319
|
+
|
342
320
|
cmds = cmds.join("\n") if cmds.is_a?(Array)
|
343
|
-
|
344
|
-
|
321
|
+
cmd = cmds || 'sh'
|
322
|
+
puts "run : #{cmd}" unless opts[:quiet]
|
323
|
+
|
324
|
+
if cmd == 'sh' # simple case
|
325
|
+
cmds = <<~Desc
|
326
|
+
docker exec -it #{opts[:opts]} #{cid} #{cmd}
|
327
|
+
Desc
|
328
|
+
else
|
329
|
+
tfile = tmpfile_for(cmd)
|
330
|
+
dst_file = "/tmp/dklet-#{File.basename(tfile)}-#{rand(10000)}"
|
331
|
+
# todo user permissions for pg
|
332
|
+
cmds = <<~Desc
|
333
|
+
docker cp --archive #{tfile} #{cid}:#{dst_file}
|
334
|
+
docker exec -it #{opts[:opts]} #{cid} sh -c 'sh #{dst_file} && rm -f #{dst_file}'
|
335
|
+
Desc
|
336
|
+
end
|
337
|
+
puts cmds unless opts[:quiet]
|
338
|
+
system cmds unless opts[:dry]
|
339
|
+
|
340
|
+
if tmprun
|
341
|
+
system <<~Desc
|
342
|
+
docker rm -f #{cid}
|
343
|
+
Desc
|
344
|
+
end
|
345
345
|
end
|
346
346
|
|
347
347
|
# encapsulate run commands behaviors in system
|
data/lib/dklet/dsl.rb
CHANGED
@@ -128,9 +128,13 @@ module Dklet::DSL
|
|
128
128
|
pname = script_path.basename.to_s
|
129
129
|
"#{pname}_#{name}"
|
130
130
|
end
|
131
|
+
|
132
|
+
def tmpfile_for(str)
|
133
|
+
Dklet::Util.tmpfile_for(str)
|
134
|
+
end
|
131
135
|
|
132
136
|
def set_file_for(name, str)
|
133
|
-
register name,
|
137
|
+
register name, tmpfile_for(str)
|
134
138
|
end
|
135
139
|
|
136
140
|
def file_for(name)
|
@@ -155,7 +159,7 @@ module Dklet::DSL
|
|
155
159
|
return unless tmpl
|
156
160
|
erb = ERB.new(tmpl, nil, '%<>')
|
157
161
|
rendered = erb.result(in_binding)
|
158
|
-
|
162
|
+
tmpfile_for(rendered)
|
159
163
|
end
|
160
164
|
|
161
165
|
# Dockerfile for image build
|
data/lib/dklet/util.rb
CHANGED
data/lib/dklet/version.rb
CHANGED