squared 0.4.5 → 0.4.7
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 +83 -0
- data/README.ruby.md +44 -37
- data/lib/squared/common/class.rb +2 -5
- data/lib/squared/common/format.rb +6 -2
- data/lib/squared/common/shell.rb +4 -4
- data/lib/squared/common/system.rb +2 -2
- data/lib/squared/common/utils.rb +8 -2
- data/lib/squared/config.rb +3 -3
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +9 -9
- data/lib/squared/workspace/project/base.rb +134 -211
- data/lib/squared/workspace/project/docker.rb +59 -53
- data/lib/squared/workspace/project/git.rb +161 -156
- data/lib/squared/workspace/project/node.rb +60 -34
- data/lib/squared/workspace/project/python.rb +141 -88
- data/lib/squared/workspace/project/ruby.rb +87 -71
- data/lib/squared/workspace/project/support/class.rb +197 -0
- data/lib/squared/workspace/project/support.rb +3 -0
- data/lib/squared/workspace/project.rb +1 -0
- data/lib/squared/workspace/series.rb +1 -1
- metadata +4 -2
@@ -270,7 +270,7 @@ module Squared
|
|
270
270
|
append_context
|
271
271
|
when :bake, :compose
|
272
272
|
if (val = option(from == :bake ? 'target' : 'service', ignore: false))
|
273
|
-
ret.merge(split_escape(val).map { |s| shell_escape(s) })
|
273
|
+
ret.merge(split_escape(val).map! { |s| shell_escape(s) })
|
274
274
|
end
|
275
275
|
end
|
276
276
|
ret
|
@@ -278,45 +278,44 @@ module Squared
|
|
278
278
|
|
279
279
|
def buildx(flag, opts = [], tag: nil, context: nil)
|
280
280
|
cmd, opts = docker_session('buildx', opts: opts)
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
out = option_sanitize(opts, list).first
|
281
|
+
op = OptionPartition.new(opts, OPT_DOCKER[:buildx][:common], cmd, project: self)
|
282
|
+
op << flag
|
283
|
+
op.parse(OPT_DOCKER[:buildx][flag == :bake ? :bake : :build] + OPT_DOCKER[:buildx][:shared])
|
285
284
|
case flag
|
286
285
|
when :build, :context
|
287
286
|
append_tag(tag || option('tag', ignore: false) || @tag)
|
288
287
|
append_context context
|
289
288
|
when :bake
|
290
|
-
unless
|
291
|
-
args =
|
292
|
-
|
289
|
+
unless op.empty?
|
290
|
+
args = op.dup
|
291
|
+
op.extras.clear
|
293
292
|
if Dir.exist?(args.last)
|
294
293
|
if projectpath?(val = args.pop)
|
295
294
|
context = val
|
296
295
|
else
|
297
|
-
|
296
|
+
op.extras << val
|
298
297
|
end
|
299
298
|
end
|
300
|
-
|
299
|
+
op.append(args, escape: true)
|
301
300
|
contextdir(context) if context
|
302
301
|
end
|
303
302
|
end
|
304
|
-
|
303
|
+
op.clear(pass: false)
|
305
304
|
run(from: :"buildx:#{flag}")
|
306
305
|
end
|
307
306
|
|
308
307
|
def composex(flag, opts = [], service: nil)
|
309
308
|
cmd, opts = docker_session('compose', opts: opts)
|
310
|
-
|
311
|
-
append_file filetype unless
|
312
|
-
|
313
|
-
|
309
|
+
op = OptionPartition.new(opts, OPT_DOCKER[:compose][:common], cmd, project: self)
|
310
|
+
append_file filetype unless op.arg?('f', 'file')
|
311
|
+
op << flag
|
312
|
+
op.parse(OPT_DOCKER[:compose][flag])
|
314
313
|
from = :"compose:#{flag}"
|
315
314
|
case flag
|
316
315
|
when :build, :up
|
317
|
-
|
316
|
+
op.append(escape: true)
|
318
317
|
when :exec, :run
|
319
|
-
append_command(flag, service,
|
318
|
+
append_command(flag, service, op.extras, from: from)
|
320
319
|
end
|
321
320
|
run(from: from)
|
322
321
|
end
|
@@ -324,12 +323,12 @@ module Squared
|
|
324
323
|
def container(flag, opts = [], id: nil)
|
325
324
|
cmd, opts = docker_session('container', flag, opts: opts)
|
326
325
|
list = OPT_DOCKER[:container].fetch(flag, [])
|
327
|
-
list
|
328
|
-
|
326
|
+
list.concat(OPT_DOCKER[:container][:update]) if flag == :run
|
327
|
+
op = OptionPartition.new(opts, list, cmd, project: self, args: flag == :run || flag == :exec)
|
329
328
|
from = :"container:#{flag}"
|
330
329
|
case flag
|
331
330
|
when :run, :exec
|
332
|
-
if flag == :run && !
|
331
|
+
if flag == :run && !op.arg?('mount')
|
333
332
|
run = VAL_DOCKER[:run]
|
334
333
|
both = run[:bind] + run[:tmpfs]
|
335
334
|
diff = run[:bind].reject { |val| run[:tmpfs].include?(val) }
|
@@ -361,14 +360,14 @@ module Squared
|
|
361
360
|
cmd << "--mount type=#{tmpfs ? 'tmpfs' : 'bind'},#{args.join(',')}"
|
362
361
|
end
|
363
362
|
end
|
364
|
-
append_command(flag, id.to_s.empty? ? tagmain : id,
|
363
|
+
append_command(flag, id.to_s.empty? ? tagmain : id, op.extras, from: from)
|
365
364
|
when :update
|
366
|
-
raise_error('missing container', hint: from) if
|
367
|
-
|
365
|
+
raise_error('missing container', hint: from) if op.empty?
|
366
|
+
op.append(escape: true)
|
368
367
|
when :commit
|
369
|
-
latest =
|
368
|
+
latest = op.shift || tagmain
|
370
369
|
cmd << id << latest
|
371
|
-
raise_error("unknown args: #{
|
370
|
+
raise_error("unknown args: #{op.join(', ')}", hint: from) unless op.empty?
|
372
371
|
return unless confirm_command(cmd.to_s, title: from, target: id, as: latest)
|
373
372
|
|
374
373
|
registry = option('registry') || @registry
|
@@ -386,7 +385,7 @@ module Squared
|
|
386
385
|
opts << '--quiet' unless verbose
|
387
386
|
return image(:push, opts, id: latest, registry: registry)
|
388
387
|
else
|
389
|
-
if
|
388
|
+
if op.empty?
|
390
389
|
status = []
|
391
390
|
no = true
|
392
391
|
case flag
|
@@ -411,13 +410,13 @@ module Squared
|
|
411
410
|
when :rm
|
412
411
|
status = %w[created exited dead]
|
413
412
|
end
|
414
|
-
ps = docker_output('ps -a', *status.map { |s| "--filter
|
413
|
+
ps = docker_output('ps -a', *status.map { |s| "--filter='status=#{s}'" })
|
415
414
|
list_image(flag, ps, no: no, hint: "status: #{status.join(', ')}", from: from) do |img|
|
416
415
|
run(cmd.temp(img), from: from)
|
417
416
|
end
|
418
417
|
return
|
419
418
|
else
|
420
|
-
|
419
|
+
op.append(escape: true)
|
421
420
|
end
|
422
421
|
end
|
423
422
|
run(from: from)
|
@@ -425,11 +424,11 @@ module Squared
|
|
425
424
|
|
426
425
|
def image(flag, opts = [], sync: true, id: nil, registry: nil)
|
427
426
|
cmd, opts = docker_session('image', flag, opts: opts)
|
428
|
-
|
427
|
+
op = OptionPartition.new(opts, OPT_DOCKER[:image][flag], cmd, project: self)
|
429
428
|
from = :"image:#{flag}"
|
430
429
|
case flag
|
431
430
|
when :list
|
432
|
-
if opts.size ==
|
431
|
+
if opts.size == op.size
|
433
432
|
index = 0
|
434
433
|
name = nil
|
435
434
|
opts.reverse_each { |opt| break opts.delete(opt) if (name = opt[/^name=["']?(.+?)["']?$/, 1]) }
|
@@ -443,28 +442,30 @@ module Squared
|
|
443
442
|
end
|
444
443
|
return
|
445
444
|
else
|
446
|
-
|
445
|
+
op.clear
|
447
446
|
end
|
448
447
|
when :rm
|
449
448
|
if id
|
450
|
-
|
451
|
-
elsif !out.empty?
|
452
|
-
out.each { |val| run(cmd.temp(val), sync: sync, from: from) }
|
453
|
-
return
|
449
|
+
op << id
|
454
450
|
else
|
455
|
-
|
456
|
-
|
451
|
+
if op.empty?
|
452
|
+
list_image(flag, docker_output('image', 'ls', '-a'), from: from) do |val|
|
453
|
+
puts val
|
454
|
+
image(:rm, opts, sync: sync, id: val)
|
455
|
+
end
|
456
|
+
else
|
457
|
+
op.each { |val| run(cmd.temp(val), sync: sync, from: from) }
|
457
458
|
end
|
458
459
|
return
|
459
460
|
end
|
460
461
|
when :push
|
461
462
|
id ||= option('tag', ignore: false) || tagmain
|
462
|
-
registry ||=
|
463
|
-
raise_error(id ? "unknown args: #{
|
463
|
+
registry ||= op.shift || option('registry') || @registry
|
464
|
+
raise_error(id ? "unknown args: #{op.join(', ')}" : 'no id/tag given', hint: from) unless id && op.empty?
|
464
465
|
raise_error('username/registry not provided', hint: from) unless registry
|
465
466
|
registry.chomp!('/')
|
466
467
|
uri = shell_quote("#{registry}/#{id}")
|
467
|
-
|
468
|
+
op << uri
|
468
469
|
img = docker_output 'image', 'tag', id, uri
|
469
470
|
return unless confirm_command(img.to_s, cmd.to_s, target: id, as: registry, title: from)
|
470
471
|
|
@@ -475,7 +476,8 @@ module Squared
|
|
475
476
|
|
476
477
|
def network(flag, opts = [], target: nil)
|
477
478
|
cmd, opts = docker_session('network', flag, opts: opts)
|
478
|
-
|
479
|
+
op = OptionPartition.new(opts, OPT_DOCKER[:network][flag], cmd, project: self)
|
480
|
+
op.clear
|
479
481
|
from = :"network:#{flag}"
|
480
482
|
list_image(flag, docker_output('ps -a'), from: from) do |img|
|
481
483
|
puts 'Success' if run(cmd.temp(target, img), from: from) == true && stdout? && banner?
|
@@ -510,10 +512,9 @@ module Squared
|
|
510
512
|
def docker_session(*cmd, opts: nil)
|
511
513
|
return session('docker', *cmd) unless opts
|
512
514
|
|
513
|
-
|
514
|
-
|
515
|
-
ret
|
516
|
-
[ret, opts]
|
515
|
+
op = OptionPartition.new(opts, OPT_DOCKER[:common], project: self)
|
516
|
+
ret = session('docker', *op.to_a, *cmd)
|
517
|
+
[ret, op.extras]
|
517
518
|
end
|
518
519
|
|
519
520
|
def docker_output(*cmd, **kwargs)
|
@@ -523,7 +524,7 @@ module Squared
|
|
523
524
|
def append_command(flag, val, list, target: @session, from: nil)
|
524
525
|
case flag
|
525
526
|
when :run
|
526
|
-
unless session_arg?('name')
|
527
|
+
unless session_arg?('name', target: target)
|
527
528
|
require 'random/formatter'
|
528
529
|
target << basic_option('name', dnsname("#{name}_#{Random.new.alphanumeric(6)}"))
|
529
530
|
end
|
@@ -537,18 +538,23 @@ module Squared
|
|
537
538
|
def append_file(type, target: @session)
|
538
539
|
return unless type == 2 || type == 4 || @file.is_a?(Array)
|
539
540
|
|
540
|
-
|
541
|
+
files = as_a(@file).map { |val| quote_option('file', basepath(val)) }
|
542
|
+
if target.is_a?(Set)
|
543
|
+
target.merge(files)
|
544
|
+
else
|
545
|
+
target.concat(files)
|
546
|
+
end
|
541
547
|
end
|
542
548
|
|
543
549
|
def append_context(ctx = nil, target: @session)
|
544
|
-
if @file.is_a?(String) && !session_arg?('f', 'file') && !bake?
|
550
|
+
if @file.is_a?(String) && !session_arg?('f', 'file', target: target) && !bake? && !compose?
|
545
551
|
target << quote_option('file', dockerfile)
|
546
552
|
end
|
547
553
|
target << contextdir(ctx || context)
|
548
554
|
end
|
549
555
|
|
550
556
|
def append_tag(val, target: @session)
|
551
|
-
ver = option('version', ignore: false)
|
557
|
+
ver = option('version', target: target, ignore: false)
|
552
558
|
list = case val
|
553
559
|
when String
|
554
560
|
val.split(',')
|
@@ -587,7 +593,7 @@ module Squared
|
|
587
593
|
a = sub_style(ee, styles: theme[:inline])
|
588
594
|
b = "Execute #{sub_style(flag, styles: theme[:active])} on #{a}#{ee == id ? '' : " (#{id})"}"
|
589
595
|
c, d = no ? ['y/N', 'N'] : ['Y/n', 'Y']
|
590
|
-
e = time_format(
|
596
|
+
e = time_format(time_since(data['CreatedAt']), pass: ['ms'])
|
591
597
|
f = sub_style(ARG[:BORDER][0], styles: theme[:inline])
|
592
598
|
g = ' ' * (cc + 1)
|
593
599
|
h = "#{sub_style(bb.rjust(cc), styles: theme[:current])} #{f} "
|
@@ -660,7 +666,7 @@ module Squared
|
|
660
666
|
end
|
661
667
|
|
662
668
|
def tagname(val)
|
663
|
-
val = val.split(':').map { |s| charname(s.sub(/^\W+/, '')) }
|
669
|
+
val = val.split(':').map! { |s| charname(s.sub(/^\W+/, '')) }
|
664
670
|
ret = val.join(':')
|
665
671
|
ret = val.first if val.size > 1 && ret.size > 128
|
666
672
|
ret[0..127]
|
@@ -678,11 +684,11 @@ module Squared
|
|
678
684
|
tag.is_a?(Array) ? tag.first : tag
|
679
685
|
end
|
680
686
|
|
681
|
-
def compose?(file)
|
687
|
+
def compose?(file = dockerfile)
|
682
688
|
COMPOSEFILE.include?(File.basename(file))
|
683
689
|
end
|
684
690
|
|
685
|
-
def bake?(file)
|
691
|
+
def bake?(file = dockerfile)
|
686
692
|
BAKEFILE.include?(File.basename(file))
|
687
693
|
end
|
688
694
|
end
|