squared 0.5.3 → 0.5.4
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/CHANGELOG.md +38 -0
- data/README.ruby.md +17 -13
- data/lib/squared/common/shell.rb +8 -3
- data/lib/squared/common/system.rb +3 -3
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +11 -6
- data/lib/squared/workspace/project/base.rb +52 -35
- data/lib/squared/workspace/project/docker.rb +68 -52
- data/lib/squared/workspace/project/git.rb +213 -129
- data/lib/squared/workspace/project/node.rb +25 -14
- data/lib/squared/workspace/project/python.rb +40 -11
- data/lib/squared/workspace/project/ruby.rb +27 -19
- data/lib/squared/workspace/project/support/class.rb +64 -13
- data/lib/squared/workspace/repo.rb +47 -43
- metadata +2 -2
@@ -55,15 +55,15 @@ module Squared
|
|
55
55
|
commit: %w[a|author=q c|change=q m|message=q pause=b?].freeze,
|
56
56
|
inspect: %w[s|size f|format=q].freeze,
|
57
57
|
start: %w[a|attach i|interactive detach-keys=q].freeze,
|
58
|
-
stop: %w[s|signal=b t|time=i].freeze,
|
59
|
-
restart: %w[s|signal=b t|time=i].freeze,
|
58
|
+
stop: %w[s|signal=b t|time=i t|timeout=i].freeze,
|
59
|
+
restart: %w[s|signal=b t|time=i t|timeout=i].freeze,
|
60
60
|
kill: %w[s|signal=b].freeze,
|
61
61
|
stats: %w[no-trunc format|q].freeze
|
62
62
|
}.freeze,
|
63
63
|
image: {
|
64
64
|
list: %w[a|all digests no-trunc f|filter=q format=q].freeze,
|
65
65
|
push: %w[a|all-tags disable-content-trust=b? platform=b q|quiet].freeze,
|
66
|
-
rm: %w[f|force no-prune].freeze,
|
66
|
+
rm: %w[f|force no-prune platform=b].freeze,
|
67
67
|
save: %w[o|output=p platform=b].freeze
|
68
68
|
}.freeze,
|
69
69
|
network: {
|
@@ -73,8 +73,11 @@ module Squared
|
|
73
73
|
}.freeze
|
74
74
|
VAL_DOCKER = {
|
75
75
|
run: {
|
76
|
-
|
77
|
-
|
76
|
+
common: %w[source src destination dst target readonly ro].freeze,
|
77
|
+
bind: %w[bind-propagation].freeze,
|
78
|
+
volume: %w[volume-subpath volume-nocopy volume-opt].freeze,
|
79
|
+
tmpfs: %w[tmpfs-size tmpfs-mode].freeze,
|
80
|
+
image: %w[image-path].freeze
|
78
81
|
}.freeze
|
79
82
|
}.freeze
|
80
83
|
private_constant :COMPOSEFILE, :BAKEFILE, :OPT_DOCKER, :VAL_DOCKER
|
@@ -92,7 +95,7 @@ module Squared
|
|
92
95
|
end
|
93
96
|
|
94
97
|
subtasks({
|
95
|
-
'build' => %i[tag context
|
98
|
+
'build' => %i[tag context].freeze,
|
96
99
|
'compose' => %i[build run exec up].freeze,
|
97
100
|
'bake' => %i[build check].freeze,
|
98
101
|
'image' => %i[list rm push tag save].freeze,
|
@@ -125,7 +128,7 @@ module Squared
|
|
125
128
|
|
126
129
|
def populate(*, **)
|
127
130
|
super
|
128
|
-
return unless ref?(Docker.ref)
|
131
|
+
return unless ref?(Docker.ref) || @only
|
129
132
|
|
130
133
|
namespace name do
|
131
134
|
Docker.subtasks do |action, flags|
|
@@ -134,7 +137,7 @@ module Squared
|
|
134
137
|
namespace action do
|
135
138
|
flags.each do |flag|
|
136
139
|
case action
|
137
|
-
when 'build'
|
140
|
+
when 'build'
|
138
141
|
case flag
|
139
142
|
when :tag, :context
|
140
143
|
format_desc(action, flag, 'opts*', before: flag == :tag ? 'name' : 'dir')
|
@@ -142,9 +145,12 @@ module Squared
|
|
142
145
|
param = param_guard(action, flag, args: args, key: flag)
|
143
146
|
buildx(:build, args.extras, "#{flag}": param)
|
144
147
|
end
|
145
|
-
|
146
|
-
|
148
|
+
end
|
149
|
+
when 'bake'
|
150
|
+
next unless bake?
|
147
151
|
|
152
|
+
case flag
|
153
|
+
when :build
|
148
154
|
format_desc action, flag, ':?,opts*,target*,context?'
|
149
155
|
task flag do |_, args|
|
150
156
|
args = args.to_a
|
@@ -155,8 +161,6 @@ module Squared
|
|
155
161
|
end
|
156
162
|
end
|
157
163
|
when :check
|
158
|
-
next unless bake?
|
159
|
-
|
160
164
|
format_desc action, flag, 'target'
|
161
165
|
task flag, [:target] do |_, args|
|
162
166
|
target = param_guard(action, flag, args: args, key: :target)
|
@@ -164,6 +168,8 @@ module Squared
|
|
164
168
|
end
|
165
169
|
end
|
166
170
|
when 'compose'
|
171
|
+
next unless compose?
|
172
|
+
|
167
173
|
case flag
|
168
174
|
when :build, :up
|
169
175
|
format_desc action, flag, 'opts*,service*'
|
@@ -348,7 +354,7 @@ module Squared
|
|
348
354
|
when :build, :up
|
349
355
|
op.append(escape: true)
|
350
356
|
when :exec, :run
|
351
|
-
append_command
|
357
|
+
append_command flag, service, op.extras
|
352
358
|
end
|
353
359
|
run(from: from)
|
354
360
|
end
|
@@ -365,44 +371,54 @@ module Squared
|
|
365
371
|
when :run, :create, :exec
|
366
372
|
if rc && !op.arg?('mount')
|
367
373
|
run = VAL_DOCKER[:run]
|
368
|
-
|
369
|
-
|
370
|
-
delim = Regexp.new(",\\s*(?=#{both.join('|')})")
|
374
|
+
all = collect_hash VAL_DOCKER[:run]
|
375
|
+
delim = Regexp.new(",\\s*(?=#{all.join('|')})")
|
371
376
|
Array(@mounts).each do |val|
|
372
377
|
args = []
|
373
|
-
|
378
|
+
type = nil
|
374
379
|
val.split(delim).each do |opt|
|
375
380
|
k, v, q = split_option opt
|
376
|
-
next unless both.include?(k)
|
377
|
-
|
378
381
|
if k == 'type'
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
382
|
+
case v
|
383
|
+
when 'bind', 'volume', 'image', 'tmpfs'
|
384
|
+
type = v
|
385
|
+
else
|
386
|
+
raise_error("unknown type: #{v}", hint: flag)
|
387
|
+
end
|
388
|
+
elsif all.include?(k)
|
389
|
+
unless type
|
390
|
+
run.each_pair do |key, val|
|
391
|
+
if val.include?(k)
|
392
|
+
type = key.to_s unless key == :common
|
393
|
+
break
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
case k
|
398
|
+
when 'readonly', 'ro'
|
399
|
+
args << k
|
400
|
+
next
|
401
|
+
when 'source', 'src', 'destination', 'dst', 'target', 'volume-subpath', 'image-path'
|
402
|
+
v = path + v
|
403
|
+
v = shell_quote(v, option: false, force: false) if q == ''
|
404
|
+
end
|
405
|
+
args << "#{k}=#{q + v + q}"
|
406
|
+
elsif verbose
|
407
|
+
log_message(Logger::INFO, 'unrecognized option', subject: from, hint: k)
|
392
408
|
end
|
393
|
-
args << "#{k}=#{q + v + q}"
|
394
409
|
end
|
395
|
-
|
410
|
+
raise_error('missing type', hint: flag) unless type
|
411
|
+
cmd << "--mount type=#{type},#{args.join(',')}"
|
396
412
|
end
|
397
413
|
end
|
398
|
-
append_command(flag, id || tagmain, op.extras
|
414
|
+
append_command(flag, id || tagmain, op.extras)
|
399
415
|
when :update
|
400
|
-
raise_error('missing container', hint:
|
416
|
+
raise_error('missing container', hint: flag) if op.empty?
|
401
417
|
op.append(escape: true)
|
402
418
|
when :commit
|
403
419
|
latest = op.shift || tagmain
|
404
420
|
cmd << id << latest
|
405
|
-
raise_error("unknown args: #{op.join(', ')}", hint:
|
421
|
+
raise_error("unknown args: #{op.join(', ')}", hint: flag) unless op.empty?
|
406
422
|
return unless confirm_command(cmd.to_s, title: from, target: id, as: latest)
|
407
423
|
|
408
424
|
registry = option('registry') || @registry
|
@@ -445,7 +461,7 @@ module Squared
|
|
445
461
|
when :rm
|
446
462
|
status = %w[created exited dead]
|
447
463
|
end
|
448
|
-
ps = docker_output('ps -a', *status.map { |s|
|
464
|
+
ps = docker_output('ps -a', *status.map { |s| quote_option('filter', "status=#{s}") })
|
449
465
|
list_image(flag, ps, no: no, hint: "status: #{status.join(', ')}", from: from) do |img|
|
450
466
|
run(cmd.temp(img), from: from)
|
451
467
|
end
|
@@ -509,8 +525,8 @@ module Squared
|
|
509
525
|
when :push
|
510
526
|
id ||= option('tag', ignore: false) || tagmain
|
511
527
|
registry ||= op.shift || option('registry') || @registry
|
512
|
-
raise_error(id ? "unknown args: #{op.join(', ')}" : 'no id/tag given', hint:
|
513
|
-
raise_error('username/registry not provided', hint:
|
528
|
+
raise_error(id ? "unknown args: #{op.join(', ')}" : 'no id/tag given', hint: flag) unless id && op.empty?
|
529
|
+
raise_error('username/registry not provided', hint: flag) unless registry
|
514
530
|
registry.chomp!('/')
|
515
531
|
uri = shell_quote "#{registry}/#{id}"
|
516
532
|
op << uri
|
@@ -544,6 +560,14 @@ module Squared
|
|
544
560
|
super || dockerfile.exist?
|
545
561
|
end
|
546
562
|
|
563
|
+
def compose?(file = dockerfile)
|
564
|
+
COMPOSEFILE.include?(File.basename(file))
|
565
|
+
end
|
566
|
+
|
567
|
+
def bake?(file = dockerfile)
|
568
|
+
BAKEFILE.include?(File.basename(file))
|
569
|
+
end
|
570
|
+
|
547
571
|
def dockerfile(val = nil)
|
548
572
|
if val == 'Dockerfile'
|
549
573
|
@file = false
|
@@ -573,7 +597,7 @@ module Squared
|
|
573
597
|
session('docker', *cmd, main: false, options: false, **kwargs)
|
574
598
|
end
|
575
599
|
|
576
|
-
def append_command(flag, val, list, target: @session
|
600
|
+
def append_command(flag, val, list, target: @session)
|
577
601
|
if list.delete(':')
|
578
602
|
list << readline('Enter command [args]', force: true)
|
579
603
|
elsif (args = env('DOCKER_ARGS'))
|
@@ -585,7 +609,7 @@ module Squared
|
|
585
609
|
target << basic_option('name', dnsname("#{name}_%s" % rand_s(6)))
|
586
610
|
end
|
587
611
|
when :exec
|
588
|
-
raise_error('no command args', hint:
|
612
|
+
raise_error('no command args', hint: flag) if list.empty?
|
589
613
|
end
|
590
614
|
target << val << list.shift
|
591
615
|
target << list.join(' && ') unless list.empty?
|
@@ -633,7 +657,7 @@ module Squared
|
|
633
657
|
index = 0
|
634
658
|
all = option('all', prefix: 'docker')
|
635
659
|
y = from == :'image:rm' && option('y', prefix: 'docker')
|
636
|
-
pat =
|
660
|
+
pat = /\b(?:#{dnsname(name)}|#{tagname(project)}|#{tagmain.split(':', 2).first})\b/
|
637
661
|
IO.popen(session_done(cmd << '--format=json')).each do |line|
|
638
662
|
data = JSON.parse(line)
|
639
663
|
id = data['ID']
|
@@ -681,7 +705,7 @@ module Squared
|
|
681
705
|
end
|
682
706
|
yield id
|
683
707
|
end
|
684
|
-
puts log_message(Logger::INFO, 'none detected', subject:
|
708
|
+
puts log_message(Logger::INFO, 'none detected', subject: name, hint: hint || from) if !found && !y
|
685
709
|
end
|
686
710
|
rescue StandardError => e
|
687
711
|
on_error e, from
|
@@ -801,14 +825,6 @@ module Squared
|
|
801
825
|
def tagmain
|
802
826
|
tag.is_a?(Array) ? tag.first : tag
|
803
827
|
end
|
804
|
-
|
805
|
-
def compose?(file = dockerfile)
|
806
|
-
COMPOSEFILE.include?(File.basename(file))
|
807
|
-
end
|
808
|
-
|
809
|
-
def bake?(file = dockerfile)
|
810
|
-
BAKEFILE.include?(File.basename(file))
|
811
|
-
end
|
812
828
|
end
|
813
829
|
|
814
830
|
Application.implement Docker
|