squared 0.4.17 → 0.4.19
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 +118 -58
- data/README.md +648 -1286
- data/lib/squared/common/base.rb +1 -1
- data/lib/squared/common/format.rb +7 -4
- data/lib/squared/common/prompt.rb +1 -1
- data/lib/squared/common/shell.rb +8 -2
- data/lib/squared/common/system.rb +1 -1
- data/lib/squared/config.rb +3 -3
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +17 -7
- data/lib/squared/workspace/project/base.rb +28 -23
- data/lib/squared/workspace/project/docker.rb +71 -58
- data/lib/squared/workspace/project/git.rb +139 -118
- data/lib/squared/workspace/project/node.rb +22 -19
- data/lib/squared/workspace/project/python.rb +2 -2
- data/lib/squared/workspace/project/ruby.rb +53 -37
- data/lib/squared/workspace/project/support/class.rb +55 -8
- data/lib/squared/workspace/repo.rb +73 -37
- data/squared.gemspec +2 -2
- metadata +4 -5
- data/README.ruby.md +0 -725
data/lib/squared/common/base.rb
CHANGED
@@ -141,11 +141,11 @@ module Squared
|
|
141
141
|
def apply_style(data, key, args, empty: true)
|
142
142
|
return if data.is_a?(::Symbol) && (data = __get__(:theme)[data]).nil?
|
143
143
|
|
144
|
-
set = ->(k, v) { data[k] = check_style(v, empty: empty) }
|
144
|
+
set = ->(k, v) { data[k.to_sym] = check_style(v, empty: empty) }
|
145
145
|
if key.is_a?(::Hash)
|
146
146
|
key.each { |k, v| set.call(k, v || args) }
|
147
147
|
else
|
148
|
-
set.call(key
|
148
|
+
set.call(key, args)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
@@ -157,7 +157,8 @@ module Squared
|
|
157
157
|
when Logger::WARN then :warn
|
158
158
|
when Logger::ERROR then :error
|
159
159
|
when Logger::FATAL then :fatal
|
160
|
-
else :unknown
|
160
|
+
else :unknown
|
161
|
+
end
|
161
162
|
else
|
162
163
|
level.to_s.downcase.to_sym
|
163
164
|
end
|
@@ -194,7 +195,7 @@ module Squared
|
|
194
195
|
end
|
195
196
|
end
|
196
197
|
|
197
|
-
def
|
198
|
+
def log_console(*args, pipe: 1)
|
198
199
|
return if args.first == false && args.size == 1
|
199
200
|
|
200
201
|
if pipe.is_a?(Pathname)
|
@@ -211,6 +212,8 @@ module Squared
|
|
211
212
|
(pipe == 2 ? $stderr : $stdout).puts(*args)
|
212
213
|
end
|
213
214
|
|
215
|
+
alias puts_oe log_console
|
216
|
+
|
214
217
|
module_function
|
215
218
|
|
216
219
|
def message(*args, hint: nil, empty: false, space: ARG[:SPACE])
|
data/lib/squared/common/shell.rb
CHANGED
@@ -92,10 +92,16 @@ module Squared
|
|
92
92
|
ret.join(join.is_a?(::String) ? join : ' ')
|
93
93
|
end
|
94
94
|
|
95
|
-
def
|
95
|
+
def shell_bin(name, env: true)
|
96
|
+
key = name.upcase
|
97
|
+
shell_quote((env && ENV["PATH_#{key}"]) || PATH[key] || PATH[key.to_sym] || name,
|
98
|
+
option: false, force: false)
|
99
|
+
end
|
100
|
+
|
101
|
+
def fill_option(val, **kwargs)
|
96
102
|
return "-#{val}" if val.match?(/\A(?:[a-z]\d*|\d)\z/i)
|
97
103
|
|
98
|
-
shell_escape(val.start_with?('-') ? val : "--#{val}",
|
104
|
+
shell_escape(val.start_with?('-') ? val : "--#{val}", **kwargs)
|
99
105
|
end
|
100
106
|
|
101
107
|
def quote_option(flag, val, option: true, double: false, merge: false)
|
data/lib/squared/config.rb
CHANGED
@@ -94,10 +94,10 @@ module Squared
|
|
94
94
|
def build
|
95
95
|
return unless enabled?
|
96
96
|
|
97
|
-
namespace
|
97
|
+
namespace task_name(name) do |ns|
|
98
98
|
@mime.each do |type, items|
|
99
99
|
items.each do |command, file, opts|
|
100
|
-
next if Rake::Task.task_defined?("#{ns}:#{command}:#{type}")
|
100
|
+
next if Rake::Task.task_defined?("#{ns.scope.path}:#{command}:#{type}")
|
101
101
|
|
102
102
|
namespace command do
|
103
103
|
unless (data = @@mime_obj[type])
|
@@ -196,7 +196,7 @@ module Squared
|
|
196
196
|
private
|
197
197
|
|
198
198
|
def puts(*args)
|
199
|
-
|
199
|
+
log_console(*args, pipe: pipe)
|
200
200
|
end
|
201
201
|
|
202
202
|
def log
|
data/lib/squared/version.rb
CHANGED
@@ -95,9 +95,15 @@ module Squared
|
|
95
95
|
@kind = Support.hashlist
|
96
96
|
@extensions = []
|
97
97
|
@envname = env_key(@main).freeze
|
98
|
-
@pipe = env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home)
|
98
|
+
@pipe = $DEBUG ? 2 : env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home)
|
99
99
|
@exception = env_bool exception
|
100
|
-
@verbose =
|
100
|
+
@verbose = if $VERBOSE.nil?
|
101
|
+
false
|
102
|
+
elsif verbose.nil?
|
103
|
+
@pipe != 0
|
104
|
+
else
|
105
|
+
env_bool(verbose, verbose.is_a?(String) ? @pipe != 0 : verbose, index: true)
|
106
|
+
end
|
101
107
|
@warning = @verbose != false
|
102
108
|
@closed = false
|
103
109
|
if common
|
@@ -423,7 +429,7 @@ module Squared
|
|
423
429
|
ret << proj if proj
|
424
430
|
end
|
425
431
|
end
|
426
|
-
return (group || ref ? ret : ret
|
432
|
+
return (group || ref ? ret : ret.first) unless block_given?
|
427
433
|
|
428
434
|
ret.each(&blk)
|
429
435
|
self
|
@@ -678,6 +684,10 @@ module Squared
|
|
678
684
|
{ exception: exception, warning: warning }
|
679
685
|
end
|
680
686
|
|
687
|
+
def size
|
688
|
+
@project.size
|
689
|
+
end
|
690
|
+
|
681
691
|
def to_s
|
682
692
|
(home? ? home : root).to_s
|
683
693
|
end
|
@@ -800,8 +810,8 @@ module Squared
|
|
800
810
|
format_desc key
|
801
811
|
task key do
|
802
812
|
unless failed.empty? && group.empty?
|
803
|
-
puts
|
804
|
-
subject: 'failed placement', hint: false)
|
813
|
+
puts(log_message(Logger::ERROR, *(failed + group.map { |val| val.action }.flatten),
|
814
|
+
subject: 'failed placement', hint: false), pipe: 2)
|
805
815
|
end
|
806
816
|
cols = level.flatten(1).map(&:size).max
|
807
817
|
level.each_with_index do |grp, n|
|
@@ -817,8 +827,8 @@ module Squared
|
|
817
827
|
end
|
818
828
|
end
|
819
829
|
|
820
|
-
def puts(*args)
|
821
|
-
|
830
|
+
def puts(*args, **kwargs)
|
831
|
+
log_console(*args, pipe: kwargs[:pipe] || pipe)
|
822
832
|
end
|
823
833
|
|
824
834
|
def script_command(task, val, group, ref, on, &blk)
|
@@ -21,7 +21,7 @@ module Squared
|
|
21
21
|
VAR_SET = %i[parent global script index envname desc dependfile dependindex theme archive env dev prod graph
|
22
22
|
pass only exclude].freeze
|
23
23
|
BLK_SET = %i[run depend doc lint test copy clean].freeze
|
24
|
-
SEM_VER = /\b(\d+)(?:(\.)(\d+))?(?:(\.)(\d+))
|
24
|
+
SEM_VER = /\b(\d+)(?:(\.)(\d+))?(?:(\.)(\d+))?[-.]?(\S+)?\b/.freeze
|
25
25
|
URI_SCHEME = %r{\A([a-z][a-z\d+-.]*)://[^@:\[\]\\^<>|\s]}i.freeze
|
26
26
|
TASK_METADATA = Rake::TaskManager.record_task_metadata
|
27
27
|
private_constant :VAR_SET, :BLK_SET, :SEM_VER, :URI_SCHEME, :TASK_METADATA
|
@@ -262,9 +262,9 @@ module Squared
|
|
262
262
|
-1
|
263
263
|
elsif h.any? { |val| e.include?(val) }
|
264
264
|
1
|
265
|
-
elsif e.any? { |val| f.include?(val) }
|
265
|
+
elsif e.any? { |val| f.include?(val) } # rubocop:disable Lint/DuplicateBranch
|
266
266
|
-1
|
267
|
-
elsif f.any? { |val| e.include?(val) }
|
267
|
+
elsif f.any? { |val| e.include?(val) } # rubocop:disable Lint/DuplicateBranch
|
268
268
|
1
|
269
269
|
elsif @index >= 0 && (i = other.instance_variable_get(:@index)) >= 0
|
270
270
|
@index <=> i
|
@@ -313,7 +313,7 @@ module Squared
|
|
313
313
|
flags.each do |flag|
|
314
314
|
case action
|
315
315
|
when 'graph'
|
316
|
-
|
316
|
+
break unless graph?
|
317
317
|
|
318
318
|
format_desc action, flag, '(-)project*'
|
319
319
|
task flag do |_, args|
|
@@ -455,13 +455,13 @@ module Squared
|
|
455
455
|
if args.first.is_a?(Struct)
|
456
456
|
f, blk = args.first.to_a
|
457
457
|
args[0] = instance_eval(&blk) || f
|
458
|
-
return unless args
|
458
|
+
return unless args.first
|
459
459
|
end
|
460
460
|
if args.all? { |val| val.is_a?(Array) }
|
461
461
|
cmd = []
|
462
462
|
var = {}
|
463
463
|
args.each do |val|
|
464
|
-
next instance_exec(*val[1..-1], &val
|
464
|
+
next instance_exec(*val[1..-1], &val.first) if val.first.is_a?(Proc)
|
465
465
|
|
466
466
|
a, b, c, d, e = val
|
467
467
|
case b
|
@@ -948,7 +948,7 @@ module Squared
|
|
948
948
|
def log
|
949
949
|
return @log unless @log.is_a?(Array)
|
950
950
|
|
951
|
-
@log = Logger.new(enabled? ? @log
|
951
|
+
@log = Logger.new(enabled? ? @log.first : nil, **@log.last)
|
952
952
|
end
|
953
953
|
|
954
954
|
def allref
|
@@ -989,8 +989,8 @@ module Squared
|
|
989
989
|
|
990
990
|
private
|
991
991
|
|
992
|
-
def puts(*args)
|
993
|
-
|
992
|
+
def puts(*args, **kwargs)
|
993
|
+
log_console(*args, pipe: kwargs[:pipe] || pipe)
|
994
994
|
end
|
995
995
|
|
996
996
|
def run(cmd = @session, var = nil, exception: self.exception, sync: true, from: nil, banner: true, chdir: path,
|
@@ -999,10 +999,8 @@ module Squared
|
|
999
999
|
warn log_message(Logger::WARN, 'no command given', subject: project, hint: from || 'unknown', pass: true)
|
1000
1000
|
return
|
1001
1001
|
end
|
1002
|
-
i = interactive && !(@session && option('y'))
|
1003
1002
|
cmd = cmd.target if cmd.is_a?(OptionPartition)
|
1004
|
-
|
1005
|
-
if i
|
1003
|
+
if interactive && (!@session || !option('y'))
|
1006
1004
|
title, y = case interactive
|
1007
1005
|
when Array
|
1008
1006
|
interactive
|
@@ -1011,10 +1009,10 @@ module Squared
|
|
1011
1009
|
else
|
1012
1010
|
['Run', 'Y']
|
1013
1011
|
end
|
1014
|
-
|
1015
|
-
|
1016
|
-
end
|
1012
|
+
yn = y == 'Y' ? 'Y/n' : 'y/N'
|
1013
|
+
exit 1 unless confirm("#{title}? [#{sub_style(cmd.to_s, styles: theme[:inline])}] [#{yn}] ", y)
|
1017
1014
|
end
|
1015
|
+
cmd = session_done cmd
|
1018
1016
|
log&.info cmd
|
1019
1017
|
on :first, from
|
1020
1018
|
begin
|
@@ -1231,12 +1229,12 @@ module Squared
|
|
1231
1229
|
end
|
1232
1230
|
|
1233
1231
|
def session(*cmd, prefix: cmd.first, main: true, path: true, options: true)
|
1234
|
-
prefix = stripext
|
1235
|
-
if path && (val =
|
1232
|
+
prefix = stripext prefix.to_s
|
1233
|
+
if path && (val = shell_bin(prefix))
|
1236
1234
|
cmd[0] = shell_quote(val, force: false)
|
1237
1235
|
end
|
1238
1236
|
ret = JoinSet.new(cmd.flatten(1))
|
1239
|
-
if options && (val = env("#{prefix}_OPTIONS"))
|
1237
|
+
if options && (val = env("#{prefix.upcase}_OPTIONS"))
|
1240
1238
|
split_escape(val).each { |opt| ret.last(fill_option(opt), /\A(--?[^ =]+)[ =].+\z/m) }
|
1241
1239
|
end
|
1242
1240
|
main ? @session = ret : ret
|
@@ -1420,9 +1418,9 @@ module Squared
|
|
1420
1418
|
unless items.empty?
|
1421
1419
|
pad = items.size.to_s.size
|
1422
1420
|
items.each_with_index do |val, i|
|
1423
|
-
next unless matchany?(val
|
1421
|
+
next unless matchany?(val.first, reg)
|
1424
1422
|
|
1425
|
-
out << "#{i.succ.to_s.rjust(pad)}. #{each ? each.call(val) : val
|
1423
|
+
out << "#{i.succ.to_s.rjust(pad)}. #{each ? each.call(val) : val.first}"
|
1426
1424
|
end
|
1427
1425
|
end
|
1428
1426
|
sub = [headerstyle]
|
@@ -1779,7 +1777,14 @@ module Squared
|
|
1779
1777
|
return -1 if b.empty?
|
1780
1778
|
return 1 if a.empty?
|
1781
1779
|
|
1782
|
-
a, b = [a.first, b.first].map!
|
1780
|
+
a, b = [a.first, b.first].map! do |c|
|
1781
|
+
begin
|
1782
|
+
d = Integer(c[5]).to_s
|
1783
|
+
rescue StandardError
|
1784
|
+
d = c[5] ? '-1' : '0'
|
1785
|
+
end
|
1786
|
+
[c[0], c[2], c[4] || '0', d]
|
1787
|
+
end
|
1783
1788
|
a.each_with_index do |c, index|
|
1784
1789
|
next if c == (d = b[index])
|
1785
1790
|
|
@@ -2098,8 +2103,8 @@ module Squared
|
|
2098
2103
|
val != action && invoked_sync?(val)
|
2099
2104
|
end
|
2100
2105
|
|
2101
|
-
def success?(ret)
|
2102
|
-
ret == true && stdout? && banner?
|
2106
|
+
def success?(ret, display = true)
|
2107
|
+
ret == true && display && stdout? && banner?
|
2103
2108
|
end
|
2104
2109
|
|
2105
2110
|
def banner?
|
@@ -4,7 +4,7 @@ module Squared
|
|
4
4
|
module Workspace
|
5
5
|
module Project
|
6
6
|
class Docker < Base
|
7
|
-
COMPOSEFILE = %w[compose.yaml compose.yml docker-compose.yaml
|
7
|
+
COMPOSEFILE = %w[compose.yaml compose.yml docker-compose.yaml docker-compose.yml].freeze
|
8
8
|
BAKEFILE = %w[docker-bake.json docker-bake.hcl docker-bake.override.json docker-bake.override.hcl].freeze
|
9
9
|
DIR_DOCKER = (COMPOSEFILE + BAKEFILE).freeze
|
10
10
|
OPT_DOCKER = {
|
@@ -12,56 +12,57 @@ module Squared
|
|
12
12
|
tlskey=p].freeze,
|
13
13
|
buildx: {
|
14
14
|
common: %w[builder=b D|debug],
|
15
|
-
build: %w[
|
16
|
-
network=b no-cache-filter=b o|output=q platform=b
|
17
|
-
target=b ulimit=q].freeze,
|
18
|
-
bake: %w[
|
19
|
-
shared: %w[check no-cache allow=q call=b? f|file=p progress=b provenance=q
|
15
|
+
build: %w[add-host=q annotation=q attest=q build-arg=qq build-context=qq cache-from=q cache-to=q
|
16
|
+
cgroup-parent=b ent=q iidfile=p label=q a-file=p network=b no-cache-filter=b o|output=q platform=b
|
17
|
+
q|quiet secret=qq shm-size=b ssh=qq t|tag=b target=b ulimit=q].freeze,
|
18
|
+
bake: %w[print list=q set=q].freeze,
|
19
|
+
shared: %w[check load no-cache pull push allow=q call=b? f|file=p metadata-file=p progress=b provenance=q
|
20
|
+
sbom=q].freeze
|
20
21
|
}.freeze,
|
21
22
|
compose: {
|
22
|
-
common: %w[all-resources compatibility dry-run ansi|b env-file=p f|file=p parallel=
|
23
|
+
common: %w[all-resources compatibility dry-run ansi|b env-file=p f|file=p parallel=n profile=b progress=b
|
23
24
|
project-directory=p p|project-name=e].freeze,
|
24
|
-
build: %w[check no-cache pull push with-dependencies q|quiet build-arg=qq builder=b m|memory=b
|
25
|
-
ssh=qq].freeze,
|
26
|
-
exec: %w[
|
27
|
-
run: %w[build
|
28
|
-
|
29
|
-
u|user=e v|volume=q w|workdir=q].freeze,
|
30
|
-
up: %w[
|
31
|
-
d|detach
|
32
|
-
quiet-pull remove-orphans V|renew-anon-volumes timestamps wait w|watch attach=b
|
33
|
-
no-attach=b pull=b scale=i t|timeout=i wait-timeout=i].freeze
|
25
|
+
build: %w[check no-cache print pull push with-dependencies q|quiet build-arg=qq builder=b m|memory=b
|
26
|
+
provenance=q sbom=q ssh=qq].freeze,
|
27
|
+
exec: %w[d|detach privileged e|env=qq index=i T|no-TTY=b? user=e w|workdir=q].freeze,
|
28
|
+
run: %w[build d|detach no-deps q|quiet quiet-build quiet-pull remove-orphans rm P|service-ports use-aliases
|
29
|
+
cap-add=b cap-drop=b q e|env=qq env-from-file=p i|interactive=b? l|label=q name=b T|no-TTY=b?
|
30
|
+
p|publish=e pull=b u|user=e v|volume=q w|workdir=q].freeze,
|
31
|
+
up: %w[abort-on-container-exit abort-on-container-failure always-recreate-deps attach-dependencies build
|
32
|
+
d|detach force-recreate menu no-build no-color no-deps no-log-prefix no-recreate no-start quiet-build
|
33
|
+
quiet-pull remove-orphans V|renew-anon-volumes timestamps wait w|watch y|yes attach=b
|
34
|
+
exit-code-from=b no-attach=b pull=b scale=i t|timeout=i wait-timeout=i].freeze,
|
35
|
+
down: %w[remove-orphans v|volumes rmi=b t|timeout=i].freeze
|
34
36
|
}.freeze,
|
35
37
|
container: {
|
36
38
|
create: %w[init i|interactive no-healthcheck oom-kill-disable privileged P|publish-all q|quiet read-only
|
37
|
-
rm runtime t|tty use-api-socket io-maxbandwidth=b io-maxiops=b add-host=q annotation=q
|
38
|
-
|
39
|
-
|
39
|
+
rm runtime t|tty use-api-socket io-maxbandwidth=b io-maxiops=b add-host=q annotation=q a|attach=b
|
40
|
+
blkio-weight=i blkio-weight-device=i cap-add=b cap-drop=b cgroup-parent=b cgroupns=b cidfile=p
|
41
|
+
device=q device-cgroup-rule=q device-read-bps=q device-read-iops=q device-write-bps=q
|
40
42
|
device-write-iops=q disable-content-trust=b? dns=e dns-option=e dns-search=e domainname=b
|
41
|
-
entrypoint=q e|env=qq env-file=p expose=e gpus=q group-add=b health-cmd=q health-interval=b
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
volume-driver=b volumes-from=b w|workdir=q].freeze,
|
43
|
+
entrypoint=q e|env=qq env-file=p expose=e gpus=q group-add=b health-cmd=q health-interval=b ip6=e
|
44
|
+
ipc=b isolation=b kernel-memory=b l|label=q label-file=p link=b link-local-ip=b log-driver=b
|
45
|
+
log-opt=q mac-address=e m|memory=b memory-reservation=b memory-swap=n memory-swappiness=n
|
46
|
+
mount=qq name=b network=b network-alias=b oom-score-adj=b pid=b pids-limit=n platform=b
|
47
|
+
p|publish=e pull=b restart=b runtime=b security-opt=q shm-size=b stop-signal=b stop-timeout=i
|
48
|
+
storage-opt=q sysctl=q tmpfs=q ulimit=q u|user=b userns=b uts=b v|volume=q volume-driver=b
|
49
|
+
volumes-from=b w|workdir=q].freeze,
|
49
50
|
run: %w[d|detach detach-keys=q sig-proxy=b?].freeze,
|
50
|
-
exec: %w[d|detach i|interactive privileged t|tty detach-keys=q e|env=qq env-file=p user=e
|
51
|
-
w|workdir=q].freeze,
|
52
51
|
update: %w[blkio-weight=i cpu-period=i cpu-quota=i cpu-rt-period=i cpu-rt-runtime=i c|cpu-shares=i cpus=f
|
53
52
|
cpuset-cpus=b cpuset-mems=b m|memory=b memory-reservation=b memory-swap=b pids-limit=n
|
54
53
|
restart=q].freeze,
|
54
|
+
exec: %w[d|detach i|interactive privileged t|tty detach-keys=q e|env=qq env-file=p user=e
|
55
|
+
w|workdir=q].freeze,
|
55
56
|
commit: %w[a|author=q c|change=q m|message=q pause=b?].freeze,
|
56
57
|
inspect: %w[s|size f|format=q].freeze,
|
57
58
|
start: %w[a|attach i|interactive detach-keys=q].freeze,
|
58
59
|
stop: %w[s|signal=b t|time=i t|timeout=i].freeze,
|
59
60
|
restart: %w[s|signal=b t|time=i t|timeout=i].freeze,
|
60
61
|
kill: %w[s|signal=b].freeze,
|
61
|
-
stats: %w[no-trunc format|q].freeze
|
62
|
+
stats: %w[a|all no-stream no-trunc format|q].freeze
|
62
63
|
}.freeze,
|
63
64
|
image: {
|
64
|
-
list: %w[a|all digests no-trunc f|filter=q format=q].freeze,
|
65
|
+
list: %w[a|all q|quiet digests no-trunc tree f|filter=q format=q].freeze,
|
65
66
|
push: %w[a|all-tags disable-content-trust=b? platform=b q|quiet].freeze,
|
66
67
|
rm: %w[f|force no-prune platform=b].freeze,
|
67
68
|
save: %w[o|output=p platform=b].freeze
|
@@ -96,7 +97,7 @@ module Squared
|
|
96
97
|
|
97
98
|
subtasks({
|
98
99
|
'build' => %i[tag context].freeze,
|
99
|
-
'compose' => %i[build run exec up].freeze,
|
100
|
+
'compose' => %i[build run exec up down].freeze,
|
100
101
|
'bake' => %i[build check].freeze,
|
101
102
|
'image' => %i[list rm push tag save].freeze,
|
102
103
|
'container' => %i[run create exec update commit inspect diff start stop restart pause unpause top stats kill
|
@@ -147,11 +148,11 @@ module Squared
|
|
147
148
|
end
|
148
149
|
end
|
149
150
|
when 'bake'
|
150
|
-
|
151
|
+
break unless bake?
|
151
152
|
|
152
153
|
case flag
|
153
154
|
when :build
|
154
|
-
format_desc action, flag, '
|
155
|
+
format_desc action, flag, 'opts*,target*,context?|:'
|
155
156
|
task flag do |_, args|
|
156
157
|
args = args.to_a
|
157
158
|
if args.first == ':'
|
@@ -168,10 +169,10 @@ module Squared
|
|
168
169
|
end
|
169
170
|
end
|
170
171
|
when 'compose'
|
171
|
-
|
172
|
+
break unless compose?
|
172
173
|
|
173
174
|
case flag
|
174
|
-
when :build, :up
|
175
|
+
when :build, :up, :down
|
175
176
|
format_desc action, flag, 'opts*,service*'
|
176
177
|
task flag do |_, args|
|
177
178
|
compose! flag, args.to_a
|
@@ -222,7 +223,8 @@ module Squared
|
|
222
223
|
format_desc(action, flag, case flag
|
223
224
|
when :rm, :save then 'id*,opts*'
|
224
225
|
when :tag then 'version?'
|
225
|
-
else 'opts*,args*'
|
226
|
+
else 'opts*,args*'
|
227
|
+
end)
|
226
228
|
task flag do |_, args|
|
227
229
|
args = args.to_a
|
228
230
|
if args.empty? && flag != :list
|
@@ -259,12 +261,11 @@ module Squared
|
|
259
261
|
|
260
262
|
ret = docker_session
|
261
263
|
if from == :run
|
262
|
-
|
263
|
-
when 1, 2
|
264
|
+
if bake?(n = filetype)
|
264
265
|
ret << 'buildx' << 'bake'
|
265
266
|
append_file n
|
266
267
|
from = :bake
|
267
|
-
|
268
|
+
elsif compose?(n)
|
268
269
|
ret << 'compose' << 'build'
|
269
270
|
append_file n
|
270
271
|
from = :compose
|
@@ -337,7 +338,7 @@ module Squared
|
|
337
338
|
op.push(val)
|
338
339
|
end
|
339
340
|
end
|
340
|
-
op.append(args, escape: true)
|
341
|
+
op.append(args, escape: true, strip: /^:/)
|
341
342
|
contextdir context if context
|
342
343
|
end
|
343
344
|
end
|
@@ -350,15 +351,14 @@ module Squared
|
|
350
351
|
op = OptionPartition.new(opts, OPT_DOCKER[:compose][:common], cmd, project: self)
|
351
352
|
append_file filetype unless op.arg?('f', 'file')
|
352
353
|
op << flag
|
353
|
-
op.parse(OPT_DOCKER[:compose][
|
354
|
-
from = :"compose:#{flag}"
|
354
|
+
op.parse(OPT_DOCKER[:compose].fetch(flag, []))
|
355
355
|
case flag
|
356
|
-
when :build, :up
|
357
|
-
op.append(escape: true)
|
356
|
+
when :build, :up, :down
|
357
|
+
op.append(escape: true, strip: /^:/)
|
358
358
|
when :exec, :run
|
359
359
|
append_command flag, service, op.extras
|
360
360
|
end
|
361
|
-
run(from:
|
361
|
+
run(from: :"compose:#{flag}")
|
362
362
|
end
|
363
363
|
|
364
364
|
def container(flag, opts = [], id: nil)
|
@@ -390,10 +390,10 @@ module Squared
|
|
390
390
|
elsif all.include?(k)
|
391
391
|
unless type
|
392
392
|
run.each_pair do |key, val|
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
393
|
+
next unless val.include?(k)
|
394
|
+
|
395
|
+
type = key.to_s unless key == :common
|
396
|
+
break
|
397
397
|
end
|
398
398
|
end
|
399
399
|
case k
|
@@ -416,7 +416,7 @@ module Squared
|
|
416
416
|
append_command(flag, id || tagmain, op.extras)
|
417
417
|
when :update
|
418
418
|
raise_error('missing container', hint: flag) if op.empty?
|
419
|
-
op.append(escape: true)
|
419
|
+
op.append(escape: true, strip: /^:/)
|
420
420
|
when :commit
|
421
421
|
latest = op.shift || tagmain
|
422
422
|
cmd << id << latest
|
@@ -469,7 +469,7 @@ module Squared
|
|
469
469
|
end
|
470
470
|
return
|
471
471
|
else
|
472
|
-
op.append(escape: true)
|
472
|
+
op.append(escape: true, strip: /^:/)
|
473
473
|
end
|
474
474
|
end
|
475
475
|
run(from: from)
|
@@ -546,7 +546,7 @@ module Squared
|
|
546
546
|
|
547
547
|
def network(flag, opts = [], target: nil)
|
548
548
|
cmd, opts = docker_session('network', flag, opts: opts)
|
549
|
-
op = OptionPartition.new(opts, OPT_DOCKER[:network][
|
549
|
+
op = OptionPartition.new(opts, OPT_DOCKER[:network].fetch(flag, []), cmd, project: self)
|
550
550
|
op.clear
|
551
551
|
from = :"network:#{flag}"
|
552
552
|
list_image(flag, docker_output('ps -a'), from: from) do |img|
|
@@ -563,10 +563,14 @@ module Squared
|
|
563
563
|
end
|
564
564
|
|
565
565
|
def compose?(file = dockerfile)
|
566
|
+
return file == 3 || file == 4 if file.is_a?(Numeric)
|
567
|
+
|
566
568
|
COMPOSEFILE.include?(File.basename(file))
|
567
569
|
end
|
568
570
|
|
569
571
|
def bake?(file = dockerfile)
|
572
|
+
return file == 1 || file == 2 if file.is_a?(Numeric)
|
573
|
+
|
570
574
|
BAKEFILE.include?(File.basename(file))
|
571
575
|
end
|
572
576
|
|
@@ -618,13 +622,22 @@ module Squared
|
|
618
622
|
end
|
619
623
|
|
620
624
|
def append_file(type, target: @session)
|
621
|
-
return
|
625
|
+
return if ENV['COMPOSE_FILE'] && compose?(type)
|
622
626
|
|
627
|
+
unless @file.is_a?(Array)
|
628
|
+
case type
|
629
|
+
when 2, 4
|
630
|
+
return
|
631
|
+
when 3
|
632
|
+
return unless COMPOSEFILE.map { |val| path + val }.select(&:exist?).size > 1
|
633
|
+
end
|
634
|
+
end
|
623
635
|
files = Array(@file).map { |val| quote_option('file', path + val) }
|
624
636
|
if target.is_a?(Set)
|
625
|
-
target.
|
637
|
+
opts = target.to_a.insert(2, *files)
|
638
|
+
target.clear.merge(opts)
|
626
639
|
else
|
627
|
-
target.
|
640
|
+
target.insert(2, *files)
|
628
641
|
end
|
629
642
|
end
|
630
643
|
|
@@ -789,7 +802,7 @@ module Squared
|
|
789
802
|
bake?(val) ? 1 : 2
|
790
803
|
when '.yml', '.yaml'
|
791
804
|
if compose?(val)
|
792
|
-
path.children.
|
805
|
+
@only&.include?('compose') || path.children.none? { |file| bake?(file) } ? 3 : 1
|
793
806
|
else
|
794
807
|
4
|
795
808
|
end
|