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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cc6111b694731072d22d3426582177a180aa902423ce8c2af7faa5283dcdafc
4
- data.tar.gz: 249d9bb8b05a2741936dd99acd4ef78d12d157c37bfa8715b88b91522dca5a64
3
+ metadata.gz: cef224e6d8e6c819c7a76c4c71b06632f99f7902205a5b4ad8b199ee53907d4a
4
+ data.tar.gz: fd493858e93bcf28cf2f91ac847f4fa0ed9350f860b1309fa931fe653399e4e7
5
5
  SHA512:
6
- metadata.gz: d505c3c32b784077240277ee45a88a0c2caba292b49ab432db1742b5f8e6ce7be689ea0f0e19069c811c101946c387f4314411d25740b4391b6ae5225ffabc92
7
- data.tar.gz: ba52933fa1c49eab057d81d7e860c802cf3fae233100afe08f20ae5eeb145e226fe270fa790d2864aec66ec9e1f528dbdfba4d558de127f1a56926710db84765
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 [ ! -z $BOOTER_DKLET_RC ];then
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
- $FUNCNAME cd && rake test
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
- tmprun = options[:tmp]
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 = nil)
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
- opts = (opts||{}).merge(cmd: cmds).merge(options.slice('quiet', 'dry'))
344
- invoke :runsh, [], opts
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, Dklet::Util.tmpfile_for(str)
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
- Dklet::Util.tmpfile_for(rendered)
162
+ tmpfile_for(rendered)
159
163
  end
160
164
 
161
165
  # Dockerfile for image build
data/lib/dklet/util.rb CHANGED
@@ -4,7 +4,7 @@ require 'socket'
4
4
  module Dklet::Util
5
5
  module_function
6
6
 
7
- def tmpfile_for(str, prefix: 'kc-tmp')
7
+ def tmpfile_for(str, prefix: 'dklet-tmp')
8
8
  file = Tempfile.new(prefix)
9
9
  file.write str
10
10
  file.close # save to disk
data/lib/dklet/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Dklet
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
 
4
4
  def self.version
5
5
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dklet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruijian Cao