dklet 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -2
- data/dklet.gemspec +1 -0
- data/dklet.rc +9 -0
- data/lib/dklet/cli.rb +40 -18
- data/lib/dklet/dsl.rb +44 -6
- data/lib/dklet/util.rb +16 -1
- data/lib/dklet/version.rb +1 -1
- data/lib/template/dklet.erb +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80c8bea6a6beb21fb1d624b3ce1c1d06e948d2f80d03bd20357307b1a4cd9de9
|
4
|
+
data.tar.gz: 145108f1c7a6c1bdb376cb54d0d738a68321c7666920e999cf65f0401e35fed5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ba973d1e510eefba8a9763f3d0dd8728267392d3222dd9905f013a460f118b305e5feb6dbb25d7fdeb0295706f5de368f04df0e1d81501d20f0fa5c914da032
|
7
|
+
data.tar.gz: d722b0c4652dba445846d7fa5b77b81cab8afd429eb403005d5d731b1e0c97c04280eda93196f17df0c30faa25015c3a85c10406e72381a98d085d61f4dcb32d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dklet (0.1.
|
4
|
+
dklet (0.1.6)
|
5
|
+
os
|
5
6
|
thor
|
6
7
|
|
7
8
|
GEM
|
@@ -9,6 +10,7 @@ GEM
|
|
9
10
|
specs:
|
10
11
|
byebug (10.0.2)
|
11
12
|
diff-lcs (1.3)
|
13
|
+
os (1.0.0)
|
12
14
|
rake (10.5.0)
|
13
15
|
rspec (3.7.0)
|
14
16
|
rspec-core (~> 3.7.0)
|
@@ -23,7 +25,7 @@ GEM
|
|
23
25
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
26
|
rspec-support (~> 3.7.0)
|
25
27
|
rspec-support (3.7.1)
|
26
|
-
thor (0.20.
|
28
|
+
thor (0.20.3)
|
27
29
|
|
28
30
|
PLATFORMS
|
29
31
|
ruby
|
data/dklet.gemspec
CHANGED
data/dklet.rc
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
if [ -z $BOOTER_DKLET_RC ];then
|
3
3
|
BOOTER_DKLET_RC=$( ruby -e "puts File.realpath('${BASH_SOURCE[0]}')")
|
4
4
|
BOOTER_DKLET_HOME=$(dirname $BOOTER_DKLET_RC)
|
5
|
+
# put exe/ into path, how to fix gem version
|
5
6
|
export PATH=$PATH:$BOOTER_DKLET_HOME/exe
|
6
7
|
else
|
7
8
|
if [ -z $FORCE_RC ]; then
|
@@ -54,6 +55,14 @@ function dklet(){
|
|
54
55
|
status|st)
|
55
56
|
type -a rundklet
|
56
57
|
;;
|
58
|
+
cli|irb)
|
59
|
+
(cd $BOOTER_DKLET_HOME && bundle install)
|
60
|
+
demo=/tmp/dklet-demo
|
61
|
+
mkdir -p $(dirname $demo)
|
62
|
+
rm -f $demo
|
63
|
+
mkdklet $demo
|
64
|
+
$demo console
|
65
|
+
;;
|
57
66
|
test|try)
|
58
67
|
demo=/tmp/dklet-demo
|
59
68
|
mkdir -p $(dirname $demo)
|
data/lib/dklet/cli.rb
CHANGED
@@ -3,12 +3,15 @@ class DockletCLI < Thor
|
|
3
3
|
#include Thor::Actions
|
4
4
|
default_command :main
|
5
5
|
|
6
|
-
|
7
|
-
class_option :
|
8
|
-
class_option :
|
9
|
-
|
10
|
-
class_option :
|
11
|
-
class_option :
|
6
|
+
# main dimension parameters
|
7
|
+
class_option :env, banner: 'app env', aliases: [:e]
|
8
|
+
class_option :release, banner: 'what app release for', aliases: [:r]
|
9
|
+
# common options
|
10
|
+
class_option :force, type: :boolean, banner: 'force do', aliases: [:f]
|
11
|
+
class_option :dry, type: :boolean, banner: 'dry run'
|
12
|
+
class_option :debug, type: :boolean, banner: 'in debug mode, more log', aliases: [:d]
|
13
|
+
class_option :verbose, type: :boolean, banner: 'show verbose info', aliases: [:V]
|
14
|
+
class_option :quiet, type: :boolean, banner: 'keep quiet', aliases: [:q]
|
12
15
|
|
13
16
|
desc 'version', 'show dklet version'
|
14
17
|
def version
|
@@ -48,12 +51,19 @@ class DockletCLI < Thor
|
|
48
51
|
|
49
52
|
desc 'runsh [CONTAINER]', 'run into container'
|
50
53
|
option :cid, banner: 'target container id or name'
|
51
|
-
option :tmp, type: :boolean,
|
54
|
+
option :tmp, type: :boolean, aliases: [:t], banner: 'allow run tmp container'
|
52
55
|
option :opts, banner: 'docker run options'
|
53
|
-
|
56
|
+
option :oneline, type: :boolean, default: true, banner: 'docker run options'
|
57
|
+
def runsh(*cmds)
|
58
|
+
if cmds.empty?
|
59
|
+
cmds = 'sh'
|
60
|
+
else
|
61
|
+
cmds = cmds.join(' ') if options[:oneline]
|
62
|
+
end
|
54
63
|
container_run(cmds)
|
55
64
|
end
|
56
65
|
map "sh" => :runsh
|
66
|
+
map "run" => :runsh
|
57
67
|
|
58
68
|
desc 'daemon', 'docker run in daemon'
|
59
69
|
option :opts, banner: 'run extra options'
|
@@ -94,7 +104,7 @@ class DockletCLI < Thor
|
|
94
104
|
|
95
105
|
desc 'clean', 'clean container artifacts'
|
96
106
|
# keep cache reused
|
97
|
-
option :image, type: :boolean,
|
107
|
+
option :image, type: :boolean, banner: 'clean user-derived images'
|
98
108
|
def clean
|
99
109
|
invoke_hooks_for(:clean, type: :before)
|
100
110
|
|
@@ -144,7 +154,7 @@ class DockletCLI < Thor
|
|
144
154
|
end
|
145
155
|
|
146
156
|
desc 'ps', 'ps related containers'
|
147
|
-
option :imaged, type: :boolean,
|
157
|
+
option :imaged, type: :boolean, banner: 'same image digest'
|
148
158
|
def ps
|
149
159
|
cmd = if options[:imaged]
|
150
160
|
"docker ps -f ancestor=#{docker_image} -a"
|
@@ -218,15 +228,27 @@ class DockletCLI < Thor
|
|
218
228
|
desc 'clear_app_volumes', 'clear app volumes'
|
219
229
|
def clear_app_volumes
|
220
230
|
if app_volumes.directory?
|
221
|
-
if options[:force] || yes?("Remove app volumes dir
|
231
|
+
if options[:force] || yes?("Remove app volumes dir: #{app_volumes} (y/n)?")
|
222
232
|
app_volumes.rmtree
|
223
233
|
end
|
224
234
|
end
|
225
235
|
end
|
226
236
|
|
237
|
+
desc '', 'reset if need'
|
238
|
+
def reset
|
239
|
+
if env =~ /^prod/
|
240
|
+
return unless (options[:force] || yes?("RESET #{full_release_name}?"))
|
241
|
+
end
|
242
|
+
system <<~Desc
|
243
|
+
#{dklet_script} clean
|
244
|
+
#{dklet_script} clear_app_volumes
|
245
|
+
#{dklet_script}
|
246
|
+
Desc
|
247
|
+
end
|
248
|
+
|
227
249
|
desc 'inspect_info', 'inspect info'
|
228
|
-
option :image, type: :boolean,
|
229
|
-
option :container, type: :boolean,
|
250
|
+
option :image, type: :boolean, aliases: ['-i'], banner: 'inspect image'
|
251
|
+
option :container, type: :boolean, aliases: ['-c'], banner: 'inspect container'
|
230
252
|
def inspect_info
|
231
253
|
cmd = nil
|
232
254
|
if options[:image]
|
@@ -252,7 +274,7 @@ class DockletCLI < Thor
|
|
252
274
|
network: netname,
|
253
275
|
voluemes_root: volumes_root,
|
254
276
|
app_volumes: app_volumes,
|
255
|
-
|
277
|
+
domains: proxy_domains,
|
256
278
|
dsl_methods: dsl_methods,
|
257
279
|
registry: registry
|
258
280
|
}
|
@@ -324,8 +346,8 @@ class DockletCLI < Thor
|
|
324
346
|
dkcmd = "docker run -t -d"
|
325
347
|
dkcmd += " --network #{netname}" if netname
|
326
348
|
dkcmd += " #{opts[:opts]}" if opts[:opts]
|
327
|
-
|
328
|
-
|
349
|
+
img = opts[:image] || docker_image
|
350
|
+
cid = `#{dkcmd} #{img} sleep 3d`.chomp
|
329
351
|
end
|
330
352
|
abort "No container found!" unless cid
|
331
353
|
|
@@ -345,7 +367,7 @@ class DockletCLI < Thor
|
|
345
367
|
Desc
|
346
368
|
end
|
347
369
|
unless opts[:quiet]
|
348
|
-
puts "==commands to run on #{cid}"
|
370
|
+
puts "==commands to run on #{'tmp' if tmprun} container #{cid.size == 64 ? cid[0..11] : cid}"
|
349
371
|
puts cmds
|
350
372
|
if opts[:debug]
|
351
373
|
puts "====by run on host"
|
@@ -357,7 +379,7 @@ class DockletCLI < Thor
|
|
357
379
|
|
358
380
|
if tmprun
|
359
381
|
system <<~Desc
|
360
|
-
docker rm -f #{cid}
|
382
|
+
docker rm -f #{cid} >/dev/null
|
361
383
|
Desc
|
362
384
|
end
|
363
385
|
end
|
data/lib/dklet/dsl.rb
CHANGED
@@ -361,6 +361,14 @@ module Dklet::DSL
|
|
361
361
|
ENV['APP_ENV'] || fetch(:default_env) || 'dev'
|
362
362
|
end
|
363
363
|
|
364
|
+
def in_dev?
|
365
|
+
env =~ /^dev/
|
366
|
+
end
|
367
|
+
|
368
|
+
def in_prod?
|
369
|
+
env =~ /^prod/
|
370
|
+
end
|
371
|
+
|
364
372
|
# 标识一次运行发布的用途, 如redis for hirails-only
|
365
373
|
def app_release
|
366
374
|
ENV['APP_RELEASE'] || 'default'
|
@@ -383,19 +391,49 @@ module Dklet::DSL
|
|
383
391
|
volumes_root.join(release_path_name)
|
384
392
|
end
|
385
393
|
|
386
|
-
##
|
387
|
-
def
|
388
|
-
|
394
|
+
## domain
|
395
|
+
def register_domain(*doms)
|
396
|
+
register :domains, doms
|
389
397
|
end
|
390
398
|
|
391
|
-
|
392
|
-
|
399
|
+
# top proxy domain part
|
400
|
+
def proxy_domain_base
|
401
|
+
ENV['PROXY_DOMAIN_BASE'] || 'lh'
|
402
|
+
end
|
403
|
+
|
404
|
+
def proxy_domains(*doms)
|
405
|
+
if doms.empty?
|
406
|
+
doms = fetch(:domains)
|
407
|
+
doms = [appname] if doms.nil? or doms.empty?
|
408
|
+
end
|
409
|
+
|
410
|
+
denv = env
|
411
|
+
denv = nil if denv =~ /^prod/
|
412
|
+
|
413
|
+
doms.map do |d|
|
414
|
+
[d, denv, proxy_domain_base].compact.join('.')
|
415
|
+
end.join(',')
|
393
416
|
end
|
394
417
|
|
395
|
-
# ref dklet/mac/
|
418
|
+
# ref dklet/mac/hostnet
|
396
419
|
def host_domain_in_container
|
397
420
|
ENV['HOST_DOMAIN_IN_CONTAINER'] || 'host.dokcer.internal'
|
398
421
|
end
|
422
|
+
|
423
|
+
# 0.0.0.0:32879
|
424
|
+
def host_with_port_for(cport, host_ip: true, only_port: false )
|
425
|
+
str = `docker port #{ops_container} #{cport}`.chomp
|
426
|
+
return if str.empty?
|
427
|
+
if only_port
|
428
|
+
return str.split(':').last
|
429
|
+
end
|
430
|
+
return str unless host_ip
|
431
|
+
str.sub('0.0.0.0', Dklet::Util.host_ip)
|
432
|
+
end
|
433
|
+
|
434
|
+
def host_port_for(cport)
|
435
|
+
host_with_port_for(cport, only_port: true)
|
436
|
+
end
|
399
437
|
end
|
400
438
|
|
401
439
|
%i(
|
data/lib/dklet/util.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'tempfile'
|
2
2
|
require 'socket'
|
3
|
+
require 'securerandom'
|
4
|
+
require 'os'
|
3
5
|
|
4
6
|
module Dklet::Util
|
5
7
|
module_function
|
@@ -20,12 +22,25 @@ module Dklet::Util
|
|
20
22
|
Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
|
21
23
|
end
|
22
24
|
|
25
|
+
def host_os
|
26
|
+
::OS
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_mac?
|
30
|
+
host_os.mac?
|
31
|
+
end
|
32
|
+
|
23
33
|
def single_line?(cmds)
|
24
|
-
cmds = cmds.chomp
|
25
34
|
return false if cmds.is_a? Array
|
35
|
+
cmds = cmds.chomp
|
26
36
|
return false if cmds =~ /\n/
|
27
37
|
return true if cmds =~ /^\s*(bash|sh)/
|
28
38
|
return false if cmds =~ /.+;/
|
29
39
|
true
|
30
40
|
end
|
41
|
+
|
42
|
+
## secure
|
43
|
+
def gen_password(len = 10)
|
44
|
+
SecureRandom.alphanumeric(len)
|
45
|
+
end
|
31
46
|
end
|
data/lib/dklet/version.rb
CHANGED
data/lib/template/dklet.erb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dklet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruijian Cao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: os
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: practical DSL for daily container life
|
70
84
|
email:
|
71
85
|
- cao7113@hotmail.com
|