dapp 0.7.23 → 0.7.24

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a274af8b41a35e353f391b7f9c7b0bde96981e5
4
- data.tar.gz: 9b40b2671fe479229e8e4c0e3e923af694514255
3
+ metadata.gz: d5ff393b9a62aa273cec389c96fcbef80d2ad14b
4
+ data.tar.gz: 208c4ff07ab82f1568a20650941666bb45502869
5
5
  SHA512:
6
- metadata.gz: 34c747b33c7cf04d4509141c1d4ed8715854b61656fbc146dafb162eb62dcb6688c4da8206ca8a31a37d126e4099f0867edd2963c89211ade78fc73a409a052b
7
- data.tar.gz: 1722b58dad85758d12405cfed80afbfe9eff1cfc4bfd7378e18f7c21da6efc8ca03156314cf30ce274bcf688f04daae53cf065428fbfa83f4eaf23023c883f7c
6
+ metadata.gz: cf6c726e0477a26497852b4a9ad5842de3ae75cdcd1051670f1258a3a107c1f3dda3a384346bddba518d1db3fec42a2799db6de11f38f28f8df49a6cee0f15c6
7
+ data.tar.gz: 4f26f2d25f6d2a361989603f45860cfca08402f4cfb711c144485a4275c3071252675b50d16419965d2e174c2c42a5e8ffb0d5f7b6d5b7e33cfbe875192b2413
data/bin/dapp CHANGED
@@ -5,7 +5,20 @@
5
5
  require 'rubygems'
6
6
  require 'dapp'
7
7
 
8
+ def check_docker_version
9
+ required_docker_version = '1.10.0'
10
+ if Gem::Version.new(required_docker_version) >= Gem::Version.new(`docker --version`[/(\d+\.)+\d+/])
11
+ $stderr.puts(Dapp::Project.paint_string("Required docker version: >= #{required_docker_version}!", :warning))
12
+ exit 1
13
+ end
14
+ rescue Errno::ENOENT => e
15
+ $stderr.puts(Dapp::Project.paint_string(e.message, :warning))
16
+ exit 1
17
+ end
18
+
8
19
  begin
20
+ check_docker_version
21
+
9
22
  begin
10
23
  Dapp::CLI.new.run
11
24
  rescue ::SystemExit
@@ -10,8 +10,6 @@ en:
10
10
  instructions: "instructions:"
11
11
  container:
12
12
  launched_command: "Launched command: `%{command}`"
13
- system_shellout:
14
- launched_command: "Launched system-shellout command: `%{command}`"
15
13
  process:
16
14
  artifact_copy: "copying artifact `%{name}`"
17
15
  artifact_building: "building artifact `%{name}`"
@@ -23,7 +21,6 @@ en:
23
21
  gitartifact_container_creating: 'creating dappdeps/gitartifact container'
24
22
  base_container_creating: 'creating dappdeps/base container'
25
23
  chefdk_container_creating: 'creating dappdeps/chefdk container'
26
- system_shellout_container_starting: 'starting system-shellout container'
27
24
  image_pull: "pulling image `%{name}`"
28
25
  image_push: "pushing image `%{name}`"
29
26
  status:
@@ -66,5 +66,7 @@ en:
66
66
  rugged:
67
67
  rugged_remote_error: "Remote git repo `%{url}`: `%{message}`!"
68
68
  local_git_repository_does_not_exist: "Local git repo: doesn't exist!"
69
+ commit_not_found_in_local_git_repository: "Local git repo: commit `%{commit}` not found (run command `dapp stages cleanup local --improper-git-commit`)!"
70
+ commit_not_found_in_remote_git_repository: "Remote git repo `%{url}`: commit `%{commit}` not found (run command `dapp stages cleanup local --improper-git-commit`)!"
69
71
  lock:
70
72
  timeout: "Could not obtain lock for `%{name}` within %{timeout} seconds"
@@ -150,7 +150,6 @@ require 'dapp/project/deps/base'
150
150
  require 'dapp/project/deps/gitartifact'
151
151
  require 'dapp/project/shellout/streaming'
152
152
  require 'dapp/project/shellout/base'
153
- require 'dapp/project/system_shellout'
154
153
  require 'dapp/project'
155
154
  require 'dapp/docker_registry'
156
155
  require 'dapp/docker_registry/mod/request'
@@ -161,7 +160,6 @@ require 'dapp/dimg/git_artifact'
161
160
  require 'dapp/dimg/path'
162
161
  require 'dapp/dimg/tags'
163
162
  require 'dapp/dimg/stages'
164
- require 'dapp/dimg/system_shellout'
165
163
  require 'dapp/dimg'
166
164
  require 'dapp/artifact'
167
165
  require 'dapp/image/argument'
@@ -5,7 +5,6 @@ module Dapp
5
5
  include Path
6
6
  include Tags
7
7
  include Stages
8
- include SystemShellout
9
8
 
10
9
  include Helper::Sha256
11
10
 
@@ -26,16 +26,21 @@ module Dapp
26
26
  def apply_archive_command(stage)
27
27
  credentials = [:owner, :group].map { |attr| "--#{attr}=#{send(attr)}" unless send(attr).nil? }.compact
28
28
 
29
- ["#{repo.dimg.project.install_bin} #{credentials.join(' ')} -d #{to}",
30
- ["#{repo.dimg.project.git_bin} --git-dir=#{repo.container_path} archive #{stage.layer_commit(self)}:#{cwd} #{include_paths.join(' ')}",
31
- "#{sudo}#{repo.dimg.project.tar_bin} -x -C #{to} #{archive_command_excludes.join(' ')}"].join(' | ')]
29
+ [].tap do |commands|
30
+ commands << "#{repo.dimg.project.install_bin} #{credentials.join(' ')} -d #{to}"
31
+
32
+ if include_paths_or_cwd.empty? || include_paths_or_cwd.any? { |path| file_exist_in_repo?(stage.layer_commit(self), path) }
33
+ commands << ["#{repo.dimg.project.git_bin} --git-dir=#{repo.container_path} archive #{stage.layer_commit(self)}:#{cwd} #{include_paths.join(' ')}",
34
+ "#{sudo}#{repo.dimg.project.tar_bin} -x -C #{to} #{archive_command_excludes.join(' ')}"].join(' | ')
35
+ end
36
+ end
32
37
  end
33
38
 
34
39
  def apply_patch_command(stage)
35
40
  current_commit = stage.layer_commit(self)
36
41
  prev_commit = stage.prev_g_a_stage.layer_commit(self)
37
42
 
38
- if prev_commit != current_commit || any_changes?(prev_commit, current_commit)
43
+ if any_changes?(prev_commit, current_commit)
39
44
  [["#{repo.dimg.project.git_bin} --git-dir=#{repo.container_path} #{diff_command(prev_commit, current_commit)}",
40
45
  "#{sudo}#{repo.dimg.project.git_bin} apply --whitespace=nowarn --directory=#{to} #{patch_command_excludes.join(' ')} --unsafe-paths"].join(' | ')]
41
46
  else
@@ -55,11 +60,24 @@ module Dapp
55
60
  end
56
61
 
57
62
  def any_changes?(from, to = latest_commit)
58
- !repo.old_git_bare(diff_command(from, to, quiet: true), returns: [0, 1]).status.success?
63
+ diff_patches(from, to).any?
59
64
  end
60
65
 
61
66
  def patch_size(from, to)
62
- repo.old_git_bare("#{diff_command(from, to)} | wc -c").stdout.strip.to_i
67
+ diff_patches(from, to).reduce(0) do |bytes, patch|
68
+ patch.hunks.each do |hunk|
69
+ hunk.lines.each do |l|
70
+ bytes +=
71
+ case l.line_origin
72
+ when :eof_newline_added, :eof_newline_removed then 1
73
+ when :addition, :deletion, :binary then l.content.size
74
+ else # :context, :file_header, :hunk_header, :eof_no_newline
75
+ 0
76
+ end
77
+ end
78
+ end
79
+ bytes
80
+ end
63
81
  end
64
82
 
65
83
  def latest_commit
@@ -102,5 +120,24 @@ module Dapp
102
120
  def diff_command(from, to, quiet: false)
103
121
  "diff --binary #{'--quiet' if quiet} #{from}..#{to} #{"--relative=#{cwd}" if cwd} -- #{include_paths(true).join(' ')}"
104
122
  end
123
+
124
+ def include_paths_or_cwd
125
+ case
126
+ when !include_paths(true).empty? then include_paths(true)
127
+ when !cwd.empty? then [cwd]
128
+ else
129
+ []
130
+ end
131
+ end
132
+
133
+ def diff_patches(from, to)
134
+ repo.diff(from, to, paths: include_paths_or_cwd).patches.select do |p|
135
+ exclude_paths(true).any? { |path| !p.delta.new_file[:path].start_with?(path) }
136
+ end
137
+ end
138
+
139
+ def file_exist_in_repo?(from, path)
140
+ repo.file_exist_in_tree?(repo.lookup_commit(from).tree, path.split('/'))
141
+ end
105
142
  end
106
143
  end
@@ -22,12 +22,12 @@ module Dapp
22
22
  @git_bare ||= Rugged::Repository.new(path, bare: true)
23
23
  end
24
24
 
25
- def old_git_bare(command, **kwargs)
26
- old_git "--git-dir=#{path} #{command}", **kwargs
25
+ def diff(from, to, **kwargs)
26
+ lookup_commit(from).diff(lookup_commit(to), **kwargs)
27
27
  end
28
28
 
29
29
  def commit_at(commit)
30
- git_bare.lookup(commit).time.to_i
30
+ lookup_commit(commit).time.to_i
31
31
  end
32
32
 
33
33
  def latest_commit(branch)
@@ -42,15 +42,23 @@ module Dapp
42
42
  git_bare.head.name.sub(/^refs\/heads\//, '')
43
43
  end
44
44
 
45
+ def file_exist_in_tree?(tree, paths)
46
+ path = paths.shift
47
+ paths.empty? ?
48
+ tree.each { |obj| return true if obj[:name] == path } :
49
+ tree.each_tree { |tree| return file_exist_in_tree?(tree, paths) if tree[:name] == path }
50
+ false
51
+ end
52
+
53
+ def lookup_commit(commit)
54
+ git_bare.lookup(commit)
55
+ end
56
+
45
57
  protected
46
58
 
47
59
  def git
48
60
  @git ||= Rugged::Repository.new(path)
49
61
  end
50
-
51
- def old_git(command, **kwargs)
52
- dimg.system_shellout! "#{dimg.project.git_bin} #{command}", **kwargs
53
- end
54
62
  end
55
63
  end
56
64
  end
@@ -19,6 +19,12 @@ module Dapp
19
19
  def latest_commit(branch = nil)
20
20
  super(branch || 'HEAD')
21
21
  end
22
+
23
+ def lookup_commit(commit)
24
+ super
25
+ rescue Rugged::OdbError => _e
26
+ raise Error::Rugged, code: :commit_not_found_in_local_git_repository, data: { commit: commit }
27
+ end
22
28
  end
23
29
  end
24
30
  end
@@ -30,9 +30,21 @@ module Dapp
30
30
  FileUtils.rm_rf path
31
31
  end
32
32
 
33
+ def lookup_commit(commit)
34
+ super
35
+ rescue Rugged::OdbError => _e
36
+ raise Error::Rugged, code: :commit_not_found_in_remote_git_repository, data: { commit: commit, url: url }
37
+ end
38
+
33
39
  protected
34
40
 
35
41
  attr_reader :url
42
+
43
+ def lookup_commit(commit)
44
+ super
45
+ rescue Rugged::OdbError => _e
46
+ raise Error::Rugged, code: :commit_not_found_in_remote_git_repository, data: { commit: commit, url: url }
47
+ end
36
48
  end
37
49
  end
38
50
  end
@@ -13,13 +13,15 @@ module Dapp
13
13
  end
14
14
 
15
15
  def build!(**_kwargs)
16
- build_from_command = if from_archives.empty?
17
- "#{project.tar_bin} c --files-from /dev/null"
18
- else
19
- "#{project.cat_bin} #{from_archives.join(' ')}"
20
- end
21
- #FIXME: do not use docker import from system-shellout
22
- @built_id = project.system_shellout!("#{build_from_command} | docker import #{prepared_change} - ").stdout.strip
16
+ raise
17
+
18
+ #FIXME: system-shellout rejected
19
+ # build_from_command = if from_archives.empty?
20
+ # "#{project.tar_bin} c --files-from /dev/null"
21
+ # else
22
+ # "#{project.cat_bin} #{from_archives.join(' ')}"
23
+ # end
24
+ # @built_id = project.system_shellout!("#{build_from_command} | docker import #{prepared_change} - ").stdout.strip
23
25
  end
24
26
 
25
27
  protected
@@ -35,7 +35,6 @@ module Dapp
35
35
  include Deps::Base
36
36
 
37
37
  include Shellout::Base
38
- include SystemShellout
39
38
 
40
39
  attr_reader :cli_options
41
40
  attr_reader :dimgs_patterns
@@ -7,26 +7,24 @@ module Dapp
7
7
  module Mrproper
8
8
  def mrproper
9
9
  log_step_with_indent(:mrproper) do
10
- if proper_all?
11
- flush_by_label('dapp')
12
- elsif proper_dev_mode_cache?
13
- flush_by_label('dapp-dev-mode')
14
- elsif proper_cache_version?
15
- log_proper_cache do
16
- proper_cache_images = proper_cache_all_images
17
- remove_images(dapp_images_by_label('dapp').select { |id| !proper_cache_images.include?(id) }.map(&:strip))
18
- end
19
- else
20
- raise Error::Project, code: :mrproper_required_option
21
- end
10
+ raise Error::Project, code: :mrproper_required_option unless proper_all? || proper_dev_mode_cache? || proper_cache_version?
11
+
12
+ project_dangling_images_flush
13
+
14
+ flush_by_label('dapp') if proper_all?
15
+ flush_by_label('dapp-dev-mode', adding_message: '(dev)') if proper_all? || proper_dev_mode_cache?
16
+ log_proper_cache do
17
+ proper_cache_images = proper_cache_all_images
18
+ remove_images(dapp_images_by_label('dapp').select { |id| !proper_cache_images.include?(id) }.map(&:strip))
19
+ end if proper_cache_version?
22
20
  end
23
21
  end
24
22
 
25
23
  protected
26
24
 
27
- def flush_by_label(label)
28
- log_step_with_indent(:containers) { dapp_containers_flush_by_label(label) }
29
- log_step_with_indent(:images) { dapp_images_flush_by_label(label) }
25
+ def flush_by_label(label, adding_message: nil)
26
+ log_step_with_indent([:containers, adding_message].compact.join(' ')) { dapp_containers_flush_by_label(label) }
27
+ log_step_with_indent([:images, adding_message].compact.join(' ')) { dapp_images_flush_by_label(label) }
30
28
  end
31
29
 
32
30
  def proper_all?
@@ -6,7 +6,6 @@ module Dapp
6
6
  class << self
7
7
  def included(_base)
8
8
  ::Dapp::Project::Shellout::Base.default_env_keys << 'SSH_AUTH_SOCK'
9
- ::Dapp::Project::SystemShellout.default_env_keys << 'SSH_AUTH_SOCK'
10
9
  end
11
10
  end # << self
12
11
 
@@ -1,5 +1,5 @@
1
1
  # Version
2
2
  module Dapp
3
- VERSION = '0.7.23'.freeze
3
+ VERSION = '0.7.24'.freeze
4
4
  BUILD_CACHE_VERSION = 6
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.23
4
+ version: 0.7.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-22 00:00:00.000000000 Z
11
+ date: 2016-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -459,7 +459,6 @@ files:
459
459
  - lib/dapp/dimg/git_artifact.rb
460
460
  - lib/dapp/dimg/path.rb
461
461
  - lib/dapp/dimg/stages.rb
462
- - lib/dapp/dimg/system_shellout.rb
463
462
  - lib/dapp/dimg/tags.rb
464
463
  - lib/dapp/docker_registry.rb
465
464
  - lib/dapp/docker_registry/base.rb
@@ -526,7 +525,6 @@ files:
526
525
  - lib/dapp/project/shellout/base.rb
527
526
  - lib/dapp/project/shellout/streaming.rb
528
527
  - lib/dapp/project/ssh_agent.rb
529
- - lib/dapp/project/system_shellout.rb
530
528
  - lib/dapp/version.rb
531
529
  homepage: https://github.com/flant/dapp
532
530
  licenses:
@@ -1,17 +0,0 @@
1
- module Dapp
2
- # Dimg
3
- class Dimg
4
- # SystemShellout
5
- module SystemShellout
6
- def system_shellout(command, **kwargs)
7
- project.system_shellout_extra(volume: tmp_path) do
8
- project.system_shellout(command, **kwargs)
9
- end
10
- end
11
-
12
- def system_shellout!(command, **kwargs)
13
- system_shellout(command, raise_error: true, **kwargs)
14
- end
15
- end # SystemShellout
16
- end # Dimg
17
- end # Dapp
@@ -1,71 +0,0 @@
1
- module Dapp
2
- # Project
3
- class Project
4
- module SystemShellout
5
- SYSTEM_SHELLOUT_IMAGE = 'ubuntu:16.04'.freeze
6
-
7
- def system_shellout(command, raise_error: false, **kwargs)
8
- system_shellout_extra(volume: (git_path ? File.dirname(git_path) : path)) do
9
- begin
10
- if raise_error
11
- shellout! _to_system_shellout_command(command), **kwargs
12
- else
13
- shellout _to_system_shellout_command(command), **kwargs
14
- end
15
- rescue Error::Shellout
16
- log_warning(
17
- desc: { code: :launched_command,
18
- data: { command: _to_system_shellout_command(command) },
19
- context: :system_shellout }
20
- )
21
- raise
22
- end
23
- end
24
- end
25
-
26
- def system_shellout!(command, **kwargs)
27
- system_shellout(command, raise_error: true, **kwargs)
28
- end
29
-
30
- def system_shellout_extra(volume: [], workdir: nil, &blk)
31
- old = system_shellout_opts.dup
32
-
33
- system_shellout_opts[:volume] += Array(volume)
34
- system_shellout_opts[:workdir] = workdir if workdir
35
-
36
- yield if block_given?
37
- ensure
38
- @system_shellout_opts = old
39
- end
40
-
41
- protected
42
-
43
- def system_shellout_opts
44
- @system_shellout_opts ||= {volume: []}
45
- end
46
-
47
- def _to_system_shellout_command(command)
48
- volumes_from = [base_container, gitartifact_container]
49
-
50
- ['docker run',
51
- '--rm',
52
- "--workdir #{system_shellout_opts[:workdir] || Dir.pwd}",
53
- *volumes_from.map { |container| "--volumes-from #{container}" },
54
- *Array(system_shellout_opts[:volume]).map { |volume| "--volume #{volume}:#{volume}" },
55
- *SystemShellout.default_env_keys.map { |env_key|
56
- env_key = env_key.to_s.upcase
57
- "--env #{env_key}=#{ENV[env_key]}"
58
- },
59
- SYSTEM_SHELLOUT_IMAGE,
60
- "#{bash_bin} -ec '#{shellout_pack(command)}'"
61
- ].join(' ')
62
- end
63
-
64
- class << self
65
- def default_env_keys
66
- @default_env_keys ||= []
67
- end
68
- end # << self
69
- end # SystemShellout
70
- end # Project
71
- end # Dapp