dapp 0.6.1 → 0.6.2
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/bin/dapp +3 -3
- data/config/en/common.yml +19 -4
- data/config/en/net_status.yml +13 -4
- data/lib/dapp.rb +48 -16
- data/lib/dapp/application.rb +75 -40
- data/lib/dapp/application/path.rb +3 -2
- data/lib/dapp/application/stages.rb +59 -0
- data/lib/dapp/artifact.rb +22 -0
- data/lib/dapp/build/stage/after_install_artifact.rb +13 -0
- data/lib/dapp/build/stage/after_setup_artifact.rb +17 -0
- data/lib/dapp/build/stage/artifact_base.rb +80 -0
- data/lib/dapp/build/stage/artifact_default.rb +62 -0
- data/lib/dapp/build/stage/base.rb +47 -12
- data/lib/dapp/build/stage/before_install.rb +6 -5
- data/lib/dapp/build/stage/before_install_artifact.rb +13 -0
- data/lib/dapp/build/stage/before_setup.rb +7 -8
- data/lib/dapp/build/stage/before_setup_artifact.rb +13 -0
- data/lib/dapp/build/stage/build_artifact.rb +32 -0
- data/lib/dapp/build/stage/docker_instructions.rb +4 -22
- data/lib/dapp/build/stage/from.rb +7 -8
- data/lib/dapp/build/stage/ga_archive.rb +1 -1
- data/lib/dapp/build/stage/ga_archive_dependencies.rb +1 -1
- data/lib/dapp/build/stage/ga_artifact_patch.rb +21 -0
- data/lib/dapp/build/stage/ga_base.rb +6 -29
- data/lib/dapp/build/stage/ga_dependencies_base.rb +4 -13
- data/lib/dapp/build/stage/ga_latest_patch.rb +2 -2
- data/lib/dapp/build/stage/import_artifact.rb +69 -0
- data/lib/dapp/build/stage/install/ga_post_install_patch.rb +1 -1
- data/lib/dapp/build/stage/install/ga_post_install_patch_dependencies.rb +1 -1
- data/lib/dapp/build/stage/install/ga_pre_install_patch_dependencies.rb +1 -7
- data/lib/dapp/build/stage/install/install.rb +12 -7
- data/lib/dapp/build/stage/mod/logging.rb +10 -7
- data/lib/dapp/build/stage/setup/chef_cookbooks.rb +3 -4
- data/lib/dapp/build/stage/setup/ga_post_setup_patch.rb +1 -1
- data/lib/dapp/build/stage/setup/ga_pre_setup_patch.rb +2 -2
- data/lib/dapp/build/stage/setup/ga_pre_setup_patch_dependencies.rb +2 -8
- data/lib/dapp/build/stage/setup/setup.rb +12 -7
- data/lib/dapp/builder/base.rb +13 -1
- data/lib/dapp/builder/chef.rb +125 -79
- data/lib/dapp/builder/chef/cookbook_metadata.rb +1 -1
- data/lib/dapp/builder/shell.rb +2 -3
- data/lib/dapp/cli.rb +3 -3
- data/lib/dapp/cli/base.rb +0 -2
- data/lib/dapp/cli/bp.rb +0 -4
- data/lib/dapp/cli/build.rb +3 -7
- data/lib/dapp/cli/cleanup.rb +0 -2
- data/lib/dapp/cli/list.rb +0 -2
- data/lib/dapp/cli/mrproper.rb +22 -0
- data/lib/dapp/cli/push.rb +4 -3
- data/lib/dapp/cli/run.rb +0 -2
- data/lib/dapp/cli/spush.rb +0 -2
- data/lib/dapp/cli/stage_image.rb +24 -0
- data/lib/dapp/cli/stages.rb +7 -5
- data/lib/dapp/cli/stages/cleanup_local.rb +28 -0
- data/lib/dapp/cli/stages/cleanup_repo.rb +24 -0
- data/lib/dapp/cli/stages/{flush.rb → flush_local.rb} +4 -6
- data/lib/dapp/cli/stages/{cleanup.rb → flush_repo.rb} +4 -6
- data/lib/dapp/cli/stages/pull.rb +28 -0
- data/lib/dapp/cli/stages/push.rb +24 -0
- data/lib/dapp/config/application.rb +185 -44
- data/lib/dapp/config/artifact.rb +10 -50
- data/lib/dapp/config/directive/artifact.rb +77 -0
- data/lib/dapp/config/directive/build_dir.rb +9 -0
- data/lib/dapp/config/directive/chef.rb +95 -0
- data/lib/dapp/config/directive/docker/artifact.rb +26 -0
- data/lib/dapp/config/directive/docker/base.rb +91 -0
- data/lib/dapp/config/directive/git_artifact.rb +59 -0
- data/lib/dapp/config/directive/shell/artifact.rb +38 -0
- data/lib/dapp/config/directive/shell/base.rb +85 -0
- data/lib/dapp/config/directive/tmp_dir.rb +36 -0
- data/lib/dapp/config/main.rb +1 -7
- data/lib/dapp/core_ext/hash.rb +21 -0
- data/lib/dapp/docker_registry/base.rb +60 -5
- data/lib/dapp/docker_registry/mod/request.rb +2 -14
- data/lib/dapp/git_artifact.rb +32 -23
- data/lib/dapp/git_repo/base.rb +1 -1
- data/lib/dapp/image/argument.rb +3 -3
- data/lib/dapp/image/docker.rb +13 -16
- data/lib/dapp/image/scratch.rb +29 -0
- data/lib/dapp/image/stage.rb +33 -23
- data/lib/dapp/lock/base.rb +18 -11
- data/lib/dapp/lock/file.rb +18 -16
- data/lib/dapp/prctl.rb +1 -0
- data/lib/dapp/project.rb +22 -9
- data/lib/dapp/project/command/bp.rb +2 -5
- data/lib/dapp/project/command/build.rb +1 -2
- data/lib/dapp/project/command/cleanup.rb +9 -7
- data/lib/dapp/project/command/common.rb +37 -12
- data/lib/dapp/project/command/mrproper.rb +57 -0
- data/lib/dapp/project/command/push.rb +8 -2
- data/lib/dapp/project/command/run.rb +1 -1
- data/lib/dapp/project/command/stage_image.rb +15 -0
- data/lib/dapp/project/command/stages/cleanup_local.rb +100 -0
- data/lib/dapp/project/command/stages/cleanup_repo.rb +65 -0
- data/lib/dapp/project/command/stages/common.rb +48 -0
- data/lib/dapp/project/command/stages/flush_local.rb +24 -0
- data/lib/dapp/project/command/stages/flush_repo.rb +22 -0
- data/lib/dapp/project/command/stages/pull.rb +26 -0
- data/lib/dapp/project/command/stages/push.rb +22 -0
- data/lib/dapp/project/dappfile.rb +3 -1
- data/lib/dapp/project/deps/base.rb +52 -0
- data/lib/dapp/project/deps/gitartifact.rb +36 -0
- data/lib/dapp/project/lock.rb +20 -13
- data/lib/dapp/project/logging/base.rb +20 -3
- data/lib/dapp/project/logging/i18n.rb +25 -0
- data/lib/dapp/project/logging/paint.rb +47 -0
- data/lib/dapp/project/logging/process.rb +17 -10
- data/lib/dapp/project/shellout/base.rb +74 -0
- data/lib/dapp/project/shellout/streaming.rb +49 -0
- data/lib/dapp/project/shellout/system.rb +72 -0
- data/lib/dapp/project/ssh_agent.rb +8 -9
- data/lib/dapp/version.rb +1 -1
- metadata +48 -17
- data/lib/dapp/build/stage/artifact.rb +0 -40
- data/lib/dapp/build/stage/mod/artifact.rb +0 -79
- data/lib/dapp/config/chef.rb +0 -51
- data/lib/dapp/config/docker.rb +0 -82
- data/lib/dapp/config/git_artifact.rb +0 -51
- data/lib/dapp/config/shell.rb +0 -64
- data/lib/dapp/helper/i18n.rb +0 -20
- data/lib/dapp/helper/paint.rb +0 -27
- data/lib/dapp/helper/shellout.rb +0 -63
- data/lib/dapp/helper/streaming.rb +0 -47
- data/lib/dapp/project/command/stages_cleanup.rb +0 -72
- data/lib/dapp/project/command/stages_flush.rb +0 -20
- data/lib/dapp/project/paint.rb +0 -16
@@ -0,0 +1,29 @@
|
|
1
|
+
module Dapp
|
2
|
+
# Image
|
3
|
+
module Image
|
4
|
+
# Stage
|
5
|
+
class Scratch < Stage
|
6
|
+
def initialize(**_kwargs)
|
7
|
+
super
|
8
|
+
@from_archives = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_archive(*archives)
|
12
|
+
@from_archives.concat(archives.flatten)
|
13
|
+
end
|
14
|
+
|
15
|
+
def build!(**_kwargs)
|
16
|
+
build_from_command = if from_archives.empty?
|
17
|
+
"#{project.tar_path} c --files-from /dev/null"
|
18
|
+
else
|
19
|
+
"#{project.cat_path} #{from_archives.join(' ')}"
|
20
|
+
end
|
21
|
+
@built_id = project.system_shellout!("#{build_from_command} | docker import #{prepared_change} - ").stdout.strip
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
attr_accessor :from_archives
|
27
|
+
end # Stage
|
28
|
+
end # Image
|
29
|
+
end # Dapp
|
data/lib/dapp/image/stage.rb
CHANGED
@@ -6,59 +6,69 @@ module Dapp
|
|
6
6
|
include Argument
|
7
7
|
|
8
8
|
def initialize(name:, project:, built_id: nil, from: nil)
|
9
|
-
@bash_commands = []
|
10
|
-
@options = {}
|
11
|
-
@change_options = {}
|
12
|
-
@service_change_options = {}
|
13
9
|
@container_name = "#{name[/[[^:].]*/]}.#{SecureRandom.hex(4)}"
|
14
10
|
@built_id = built_id
|
15
|
-
super(name: name, project: project, from: from)
|
16
|
-
end
|
17
11
|
|
18
|
-
|
19
|
-
|
12
|
+
@bash_commands = []
|
13
|
+
@options = {}
|
14
|
+
@change_options = {}
|
15
|
+
@service_change_options = {}
|
16
|
+
|
17
|
+
super(name: name, project: project, from: from)
|
20
18
|
end
|
21
19
|
|
22
20
|
def built_id
|
23
21
|
@built_id ||= id
|
24
22
|
end
|
25
23
|
|
26
|
-
def build!
|
27
|
-
run!
|
24
|
+
def build!
|
25
|
+
run!
|
28
26
|
@built_id = commit!
|
29
27
|
ensure
|
30
|
-
shellout("docker rm #{container_name}")
|
28
|
+
project.shellout("docker rm #{container_name}")
|
31
29
|
end
|
32
30
|
|
33
|
-
def export!(name
|
31
|
+
def export!(name)
|
34
32
|
image = self.class.new(name: name, project: project, built_id: built_id)
|
35
|
-
image.tag!
|
36
|
-
image.push!
|
33
|
+
image.tag!
|
34
|
+
image.push!
|
37
35
|
image.untag!
|
38
36
|
end
|
39
37
|
|
40
|
-
def
|
38
|
+
def import!(name)
|
39
|
+
image = self.class.new(name: name, project: project)
|
40
|
+
image.pull!
|
41
|
+
@built_id = image.built_id
|
42
|
+
tag!
|
43
|
+
image.untag!
|
44
|
+
end
|
45
|
+
|
46
|
+
def tag!
|
41
47
|
project.log_warning(desc: { code: :another_image_already_tagged, context: 'warning' }) if !(existed_id = id).nil? && built_id != existed_id
|
42
|
-
shellout!("docker tag #{built_id} #{name}"
|
48
|
+
project.shellout!("docker tag #{built_id} #{name}")
|
43
49
|
cache_reset
|
44
50
|
end
|
45
51
|
|
52
|
+
def labels
|
53
|
+
raise Error::Build, code: :image_not_exist, data: { name: name } if built_id.nil?
|
54
|
+
self.class.image_config_option(image_id: built_id, option: 'labels')
|
55
|
+
end
|
56
|
+
|
46
57
|
protected
|
47
58
|
|
48
59
|
attr_reader :container_name
|
49
60
|
|
50
|
-
def run!
|
61
|
+
def run!
|
51
62
|
raise Error::Build, code: :built_id_not_defined if from.built_id.nil?
|
52
|
-
shellout!("docker run #{prepared_options} #{from.built_id} -ec '#{prepared_bash_command}'",
|
53
|
-
log_verbose: log_verbose, log_time: log_time)
|
63
|
+
project.shellout!("docker run #{prepared_options} #{from.built_id} -ec '#{prepared_bash_command}'", log_verbose: true)
|
54
64
|
rescue Error::Shellout => _e
|
55
|
-
raise unless introspect_error || introspect_before_error
|
56
|
-
built_id = introspect_error ? commit! : from.built_id
|
57
|
-
raise Exception::IntrospectImage, data: { built_id: built_id, options: prepared_options, rmi: introspect_error }
|
65
|
+
raise unless project.introspect_error? || project.introspect_before_error?
|
66
|
+
built_id = project.introspect_error? ? commit! : from.built_id
|
67
|
+
raise Exception::IntrospectImage, data: { built_id: built_id, options: prepared_options, rmi: project.introspect_error? }
|
58
68
|
end
|
59
69
|
|
60
70
|
def commit!
|
61
|
-
shellout!("docker commit #{prepared_change} #{container_name}").stdout.strip
|
71
|
+
project.shellout!("docker commit #{prepared_change} #{container_name}").stdout.strip
|
62
72
|
end
|
63
73
|
end # Stage
|
64
74
|
end # Image
|
data/lib/dapp/lock/base.rb
CHANGED
@@ -4,21 +4,20 @@ module Dapp
|
|
4
4
|
# Base
|
5
5
|
class Base
|
6
6
|
attr_reader :name
|
7
|
-
attr_reader :on_wait
|
8
|
-
attr_reader :timeout
|
9
7
|
|
10
|
-
def initialize(name
|
8
|
+
def initialize(name)
|
11
9
|
@name = name
|
12
|
-
@
|
13
|
-
@timeout = timeout
|
10
|
+
@active_locks = 0
|
14
11
|
end
|
15
12
|
|
16
|
-
def lock(
|
17
|
-
|
13
|
+
def lock(timeout: 60, on_wait: nil, readonly: false)
|
14
|
+
_do_lock(timeout, on_wait, readonly) unless @active_locks > 0
|
15
|
+
@active_locks += 1
|
18
16
|
end
|
19
17
|
|
20
18
|
def unlock
|
21
|
-
|
19
|
+
@active_locks -= 1
|
20
|
+
_do_unlock if @active_locks.zero?
|
22
21
|
end
|
23
22
|
|
24
23
|
def synchronize(*args)
|
@@ -32,9 +31,17 @@ module Dapp
|
|
32
31
|
|
33
32
|
protected
|
34
33
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
34
|
+
def _do_lock(_timeout, _on_wait, _readonly)
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
|
38
|
+
def _do_unlock
|
39
|
+
raise
|
40
|
+
end
|
41
|
+
|
42
|
+
def _waiting(timeout, on_wait, &blk)
|
43
|
+
if on_wait
|
44
|
+
on_wait.call { ::Timeout.timeout(timeout, &blk) }
|
38
45
|
else
|
39
46
|
::Timeout.timeout(timeout, &blk)
|
40
47
|
end
|
data/lib/dapp/lock/file.rb
CHANGED
@@ -3,20 +3,30 @@ module Dapp
|
|
3
3
|
module Lock
|
4
4
|
# File
|
5
5
|
class File < Base
|
6
|
+
class << self
|
7
|
+
attr_writer :counter
|
8
|
+
|
9
|
+
def counter
|
10
|
+
@counter ||= 0
|
11
|
+
end
|
12
|
+
end # << self
|
13
|
+
|
6
14
|
attr_reader :lock_path
|
7
15
|
|
8
|
-
def initialize(lock_path, name
|
9
|
-
super(name
|
16
|
+
def initialize(lock_path, name)
|
17
|
+
super(name)
|
18
|
+
|
10
19
|
@lock_path = Pathname.new(lock_path).tap(&:mkpath)
|
11
20
|
end
|
12
21
|
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
protected
|
23
|
+
|
24
|
+
def _do_lock(timeout, on_wait, readonly)
|
25
|
+
@file = ::File.open(lock_path.join(name), ::File::RDWR | ::File::CREAT, 0o644)
|
16
26
|
|
17
27
|
begin
|
18
|
-
mode = (
|
19
|
-
_waiting { @file.flock(mode) } unless @file.flock(mode | ::File::LOCK_NB)
|
28
|
+
mode = (readonly ? ::File::LOCK_SH : ::File::LOCK_EX)
|
29
|
+
_waiting(timeout, on_wait) { @file.flock(mode) } unless @file.flock(mode | ::File::LOCK_NB)
|
20
30
|
rescue ::Timeout::Error
|
21
31
|
raise Dapp::Lock::Error::Timeout, code: :timeout,
|
22
32
|
data: { name: name, timeout: timeout }
|
@@ -25,19 +35,11 @@ module Dapp
|
|
25
35
|
self.class.counter += 1
|
26
36
|
end
|
27
37
|
|
28
|
-
def
|
38
|
+
def _do_unlock
|
29
39
|
@file.close
|
30
40
|
@file = nil
|
31
41
|
self.class.counter -= 1
|
32
42
|
end
|
33
|
-
|
34
|
-
class << self
|
35
|
-
attr_writer :counter
|
36
|
-
|
37
|
-
def counter
|
38
|
-
@counter ||= 0
|
39
|
-
end
|
40
|
-
end # << self
|
41
43
|
end # File
|
42
44
|
end # Lock
|
43
45
|
end # Dapp
|
data/lib/dapp/prctl.rb
CHANGED
data/lib/dapp/project.rb
CHANGED
@@ -3,7 +3,7 @@ module Dapp
|
|
3
3
|
class Project
|
4
4
|
include Lock
|
5
5
|
include Dappfile
|
6
|
-
|
6
|
+
|
7
7
|
include Command::Common
|
8
8
|
include Command::Run
|
9
9
|
include Command::Build
|
@@ -11,17 +11,30 @@ module Dapp
|
|
11
11
|
include Command::Push
|
12
12
|
include Command::Spush
|
13
13
|
include Command::List
|
14
|
-
include Command::
|
15
|
-
include Command::
|
14
|
+
include Command::Stages::CleanupLocal
|
15
|
+
include Command::Stages::CleanupRepo
|
16
|
+
include Command::Stages::FlushLocal
|
17
|
+
include Command::Stages::FlushRepo
|
18
|
+
include Command::Stages::Push
|
19
|
+
include Command::Stages::Pull
|
20
|
+
include Command::Stages::Common
|
16
21
|
include Command::Cleanup
|
22
|
+
include Command::Mrproper
|
23
|
+
include Command::StageImage
|
17
24
|
include Logging::Base
|
18
25
|
include Logging::Process
|
26
|
+
include Logging::I18n
|
27
|
+
include Logging::Paint
|
19
28
|
|
20
29
|
include SshAgent
|
21
|
-
include Helper::I18n
|
22
|
-
include Helper::Shellout
|
23
|
-
include Helper::Paint
|
24
30
|
include Helper::Sha256
|
31
|
+
include Helper::Trivia
|
32
|
+
|
33
|
+
include Deps::Gitartifact
|
34
|
+
include Deps::Base
|
35
|
+
|
36
|
+
include Shellout::Base
|
37
|
+
include Shellout::System
|
25
38
|
|
26
39
|
attr_reader :cli_options
|
27
40
|
attr_reader :apps_patterns
|
@@ -31,13 +44,13 @@ module Dapp
|
|
31
44
|
@apps_patterns = apps_patterns || []
|
32
45
|
@apps_patterns << '*' unless @apps_patterns.any?
|
33
46
|
|
34
|
-
|
35
|
-
|
47
|
+
Logging::Paint.initialize(cli_options[:log_color])
|
48
|
+
Logging::I18n.initialize
|
36
49
|
end
|
37
50
|
|
38
51
|
def name
|
39
52
|
@name ||= begin
|
40
|
-
|
53
|
+
system_shellout!("#{git_path} -C #{path} config --get remote.origin.url").stdout.strip.split('/').last[/.*(?=.git)/]
|
41
54
|
rescue Error::Shellout
|
42
55
|
File.basename(path)
|
43
56
|
end
|
@@ -8,15 +8,12 @@ module Dapp
|
|
8
8
|
def bp(repo)
|
9
9
|
bp_step(:build)
|
10
10
|
bp_step(:push, repo)
|
11
|
-
bp_step(:
|
11
|
+
bp_step(:stages_cleanup_local, repo)
|
12
12
|
bp_step(:cleanup)
|
13
13
|
end
|
14
14
|
|
15
15
|
def bp_step(step, *args)
|
16
|
-
|
17
|
-
with_log_indent do
|
18
|
-
public_send(step, *args)
|
19
|
-
end
|
16
|
+
log_step_with_indent(step) { public_send(step, *args) }
|
20
17
|
end
|
21
18
|
end
|
22
19
|
end
|
@@ -8,13 +8,15 @@ module Dapp
|
|
8
8
|
def cleanup
|
9
9
|
build_configs.map(&:_basename).uniq.each do |basename|
|
10
10
|
lock("#{basename}.images") do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
log_step_with_indent(basename) do
|
12
|
+
project_containers_flush(basename)
|
13
|
+
project_dangling_images_flush(basename)
|
14
|
+
remove_images_by_query([
|
15
|
+
'docker images',
|
16
|
+
%(--format '{{if ne "#{stage_cache(basename)}" .Repository }}{{.ID}}{{ end }}'),
|
17
|
+
%(-f "label=dapp=#{stage_dapp_label(basename)}")
|
18
|
+
].join(' ')) # FIXME: negative filter is not currently supported by the Docker CLI
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -7,18 +7,38 @@ module Dapp
|
|
7
7
|
module Common
|
8
8
|
protected
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def project_images(basename)
|
11
|
+
shellout!(%(docker images --format="{{.Repository}}:{{.Tag}}" #{stage_cache(basename)})).stdout.strip
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
14
|
+
def project_containers_flush(basename)
|
15
|
+
remove_containers_by_query(%(docker ps -a -f "label=dapp" -f "name=#{container_name(basename)}" -q), force: true)
|
16
|
+
end
|
17
|
+
|
18
|
+
def project_dangling_images_flush(basename)
|
19
|
+
remove_images_by_query(%(docker images -f "dangling=true" -f "label=dapp=#{stage_dapp_label(basename)}" -q), force: true)
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_images_by_query(images_query, force: false)
|
23
|
+
with_subquery(images_query) { |ids| remove_images(ids, force: force) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove_images(ids, force: false)
|
27
|
+
remove_base('docker rmi%{force_option} %{ids}', ids, force: force)
|
17
28
|
end
|
18
29
|
|
19
|
-
def
|
30
|
+
def remove_containers_by_query(containers_query, force: false)
|
31
|
+
with_subquery(containers_query) { |ids| remove_containers(ids, force: force) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def remove_containers(ids, force: false)
|
35
|
+
remove_base('docker rm%{force_option} %{ids}', ids, force: force)
|
36
|
+
end
|
37
|
+
|
38
|
+
def remove_base(query_format, ids, force: false)
|
39
|
+
return if ids.empty?
|
20
40
|
force_option = force ? ' -f' : ''
|
21
|
-
|
41
|
+
ids.each_slice(50) { |chunk| run_command(query_format % ({ force_option: force_option, ids: chunk.join(' ') })) }
|
22
42
|
end
|
23
43
|
|
24
44
|
def with_subquery(query)
|
@@ -27,11 +47,8 @@ module Dapp
|
|
27
47
|
end
|
28
48
|
|
29
49
|
def run_command(cmd)
|
30
|
-
if
|
31
|
-
|
32
|
-
else
|
33
|
-
shellout!(cmd)
|
34
|
-
end
|
50
|
+
log(cmd) if log_verbose? || dry_run?
|
51
|
+
shellout!(cmd) unless dry_run?
|
35
52
|
end
|
36
53
|
|
37
54
|
def stage_cache(basename)
|
@@ -45,6 +62,14 @@ module Dapp
|
|
45
62
|
def container_name(basename)
|
46
63
|
basename
|
47
64
|
end
|
65
|
+
|
66
|
+
def proper_cache_version?
|
67
|
+
!!cli_options[:proper_cache_version]
|
68
|
+
end
|
69
|
+
|
70
|
+
def log_proper_cache(&blk)
|
71
|
+
log_step_with_indent(:'proper cache', &blk)
|
72
|
+
end
|
48
73
|
end
|
49
74
|
end
|
50
75
|
end # Project
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Dapp
|
2
|
+
# Project
|
3
|
+
class Project
|
4
|
+
# Command
|
5
|
+
module Command
|
6
|
+
# Mrproper
|
7
|
+
module Mrproper
|
8
|
+
def mrproper
|
9
|
+
log_step_with_indent(:mrproper) do
|
10
|
+
if proper_all?
|
11
|
+
log_step_with_indent(:containers) { dapp_containers_flush }
|
12
|
+
log_step_with_indent(:images) { dapp_images_flush }
|
13
|
+
elsif proper_cache_version?
|
14
|
+
log_proper_cache do
|
15
|
+
proper_cache_images = proper_cache_all_images
|
16
|
+
remove_images(dapp_images.lines.select { |id| !proper_cache_images.lines.include?(id) }.map(&:strip))
|
17
|
+
end
|
18
|
+
else
|
19
|
+
raise Error::Project, code: :mrproper_required_option
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def proper_all?
|
27
|
+
!!cli_options[:proper_all]
|
28
|
+
end
|
29
|
+
|
30
|
+
def dapp_containers_flush
|
31
|
+
remove_containers_by_query('docker ps -a -f "label=dapp" -q', force: true)
|
32
|
+
end
|
33
|
+
|
34
|
+
def dapp_dangling_images_flush
|
35
|
+
remove_images_by_query('docker images -f "dangling=true" -f "label=dapp" -q', force: true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def dapp_images_flush
|
39
|
+
dapp_dangling_images_flush
|
40
|
+
remove_images(dapp_images.lines.map(&:strip), force: true)
|
41
|
+
end
|
42
|
+
|
43
|
+
def dapp_images
|
44
|
+
@dapp_images ||= shellout!('docker images -f "dangling=false" --format="{{.Repository}}:{{.Tag}}" -f "label=dapp"').stdout.strip
|
45
|
+
end
|
46
|
+
|
47
|
+
def proper_cache_all_images
|
48
|
+
shellout!([
|
49
|
+
'docker images',
|
50
|
+
'--format="{{.Repository}}:{{.Tag}}"',
|
51
|
+
%(-f "label=dapp-cache-version=#{Dapp::BUILD_CACHE_VERSION}" -f "dangling=false")
|
52
|
+
].join(' ')).stdout.strip
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end # Project
|
57
|
+
end # Dapp
|