dapp 0.23.10 → 0.24.0
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 +0 -4
- data/config/en/net_status.yml +4 -2
- data/lib/dapp.rb +0 -4
- data/lib/dapp/cli.rb +0 -4
- data/lib/dapp/cli/command/base.rb +1 -7
- data/lib/dapp/dapp.rb +22 -39
- data/lib/dapp/dapp/option_tags.rb +2 -12
- data/lib/dapp/dimg/build/stage/artifact_default.rb +1 -1
- data/lib/dapp/dimg/builder/chef/cookbook.rb +1 -1
- data/lib/dapp/dimg/cli/command/base.rb +4 -0
- data/lib/dapp/dimg/config/directive/artifact_dimg.rb +7 -0
- data/lib/dapp/dimg/config/directive/dimg/instance_methods.rb +0 -1
- data/lib/dapp/dimg/config/directive/dimg/validation.rb +16 -39
- data/lib/dapp/dimg/config/directive/git_artifact_remote.rb +9 -8
- data/lib/dapp/dimg/dapp/command/cleanup_repo.rb +10 -8
- data/lib/dapp/dimg/dimg/git_artifact.rb +20 -8
- data/lib/dapp/dimg/git_artifact.rb +101 -20
- data/lib/dapp/dimg/git_repo/base.rb +115 -1
- data/lib/dapp/dimg/git_repo/own.rb +14 -0
- data/lib/dapp/dimg/git_repo/remote.rb +13 -16
- data/lib/dapp/helper/trivia.rb +2 -18
- data/lib/dapp/kube/dapp/command/deploy.rb +0 -1
- data/lib/dapp/kube/dapp/command/render.rb +2 -2
- data/lib/dapp/kube/helm/values.rb +2 -2
- data/lib/dapp/version.rb +2 -2
- metadata +2 -32
- data/lib/dapp/dapp/sentry.rb +0 -112
- data/lib/dapp/helper/url.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a3eb814504194a1734b9bab5b11a53763eef1b7
|
4
|
+
data.tar.gz: 66666ebe9a2afbb29b34345e8183dbdd855ff787
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ab24da89ae14385765f1d8424fad856113fbd54ab978f1bc71d7a67b281d9def44e333e3955042bb29f85b469043bb54eea90f0154ced45e4177a74c7001e44
|
7
|
+
data.tar.gz: e3cd721f5989eca155057cb56a16ff396ad7b11ce5b28896fb16e812cf2cbda8cf9108ff98b9920dfedd3f62691c9d64fa91836adab72290634311f6392c4c14
|
data/bin/dapp
CHANGED
data/config/en/net_status.yml
CHANGED
@@ -80,7 +80,7 @@ en:
|
|
80
80
|
stage_artifact_double_associate: "Can't use `%{stage}` stage for artifact; already used in `%{conflict_stage}` stage!"
|
81
81
|
stage_artifact_not_supported_associated_stage: "Bad artifact stage `%{stage}`!"
|
82
82
|
git_artifact_remote_branch_with_commit: "Remote git repo: use `commit` or `branch` directive!"
|
83
|
-
artifact_conflict: "Conflict between artifacts
|
83
|
+
artifact_conflict: "Conflict between artifacts paths!"
|
84
84
|
scratch_unsupported_directive: "Scratch dimg has unsupported directive `%{directive}`!"
|
85
85
|
scratch_artifact_required: "Scratch dimg without artifacts!"
|
86
86
|
scratch_artifact_associated: "Scratch artifact can't be associated: not expected `before`/`after` attribute!"
|
@@ -120,7 +120,9 @@ en:
|
|
120
120
|
commit_not_found_in_remote_git_repository: "Remote git repo `%{url}`: commit `%{commit}` not found!\nIf commit has been rebased: run command `dapp dimg stages cleanup local --improper-git-commit`!"
|
121
121
|
branch_not_exist_in_remote_git_repository: "Remote git repo `%{url}`: branch `%{branch}` not exist!"
|
122
122
|
rugged_protocol_not_supported: "Rugged has been compiled without support for `%{protocol}`.\nGit repositories will not be reachable via `%{protocol}` (`%{url}`).\nRugged.features should include `%{protocol}`."
|
123
|
-
|
123
|
+
incorrect_gitmodules_file: "Local git repo with invalid `.gitmodules` file: `%{error}`."
|
124
|
+
git_repository_without_remote_url: "Git repo `%{name}`: remote url cannot be detected!\nYou should check `remote origin url` in `%{path}` repository."
|
125
|
+
git_repository_not_found: "Git repository `%{path}` not found!\nYou should check `remote origin url` in `%{parent_git_path}` repository."
|
124
126
|
lock:
|
125
127
|
timeout: "Could not obtain lock for `%{name}` within %{timeout} seconds!"
|
126
128
|
app:
|
data/lib/dapp.rb
CHANGED
@@ -26,8 +26,6 @@ require 'zlib'
|
|
26
26
|
require 'slugify'
|
27
27
|
require 'base64'
|
28
28
|
require 'io/console'
|
29
|
-
require 'sentry-raven'
|
30
|
-
require 'toml-rb'
|
31
29
|
|
32
30
|
require 'dapp/version'
|
33
31
|
require 'dapp/core_ext/hash'
|
@@ -38,7 +36,6 @@ require 'dapp/helper/sha256'
|
|
38
36
|
require 'dapp/helper/net_status'
|
39
37
|
require 'dapp/helper/tar'
|
40
38
|
require 'dapp/helper/yaml'
|
41
|
-
require 'dapp/helper/url'
|
42
39
|
require 'dapp/prctl'
|
43
40
|
require 'dapp/error/mod/user'
|
44
41
|
require 'dapp/error/base'
|
@@ -59,7 +56,6 @@ require 'dapp/config/directive/base'
|
|
59
56
|
require 'dapp/config/config'
|
60
57
|
require 'dapp/dapp/lock'
|
61
58
|
require 'dapp/dapp/ssh_agent'
|
62
|
-
require 'dapp/dapp/sentry'
|
63
59
|
require 'dapp/dapp/git_artifact'
|
64
60
|
require 'dapp/dapp/dappfile'
|
65
61
|
require 'dapp/dapp/chef'
|
data/lib/dapp/cli.rb
CHANGED
@@ -58,8 +58,6 @@ module Dapp
|
|
58
58
|
|
59
59
|
def run_dapp_command(run_method, options: {}, log_running_time: true, try_host_docker_login: false)
|
60
60
|
dapp = ::Dapp::Dapp.new(options: options)
|
61
|
-
::Dapp::CLI.dapp_object = dapp
|
62
|
-
dapp.sentry_message("Manual usage: `#{options[:dapp_command]}` command") unless ENV['CI']
|
63
61
|
|
64
62
|
log_dapp_running_time(dapp, ignore: !log_running_time) do
|
65
63
|
begin
|
@@ -76,10 +74,6 @@ module Dapp
|
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
79
|
-
def run_method
|
80
|
-
class_to_lowercase
|
81
|
-
end
|
82
|
-
|
83
77
|
def log_dapp_running_time(dapp, ignore: false)
|
84
78
|
return yield if ignore
|
85
79
|
|
@@ -101,7 +95,7 @@ module Dapp
|
|
101
95
|
self.class.print_error_with_help_and_die! self, "cannot use alias options --run-dir, --build-dir, --deploy-dir at the same time"
|
102
96
|
end
|
103
97
|
|
104
|
-
config.merge(build_dir: dirs.compact.first,
|
98
|
+
config.merge(build_dir: dirs.compact.first, **kwargs)
|
105
99
|
end
|
106
100
|
end
|
107
101
|
end
|
data/lib/dapp/dapp.rb
CHANGED
@@ -17,13 +17,10 @@ module Dapp
|
|
17
17
|
include Logging::Paint
|
18
18
|
|
19
19
|
include SshAgent
|
20
|
-
include Sentry
|
21
|
-
|
22
20
|
include Helper::Sha256
|
23
|
-
extend
|
21
|
+
extend Helper::Trivia
|
24
22
|
include Helper::Trivia
|
25
23
|
include Helper::Tar
|
26
|
-
include Helper::Url
|
27
24
|
|
28
25
|
include Deps::Toolchain
|
29
26
|
include Deps::Gitartifact
|
@@ -44,29 +41,19 @@ module Dapp
|
|
44
41
|
self.class.options
|
45
42
|
end
|
46
43
|
|
47
|
-
def settings
|
48
|
-
@settings ||= begin
|
49
|
-
settings_path = File.join(self.class.home_dir, "settings.toml")
|
50
|
-
|
51
|
-
if File.exists? settings_path
|
52
|
-
TomlRB.load_file(settings_path)
|
53
|
-
else
|
54
|
-
{}
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
44
|
def name
|
60
45
|
@name ||= begin
|
61
46
|
n = begin
|
62
47
|
if (name = options[:name])
|
63
48
|
name
|
64
|
-
elsif
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
49
|
+
elsif git_own_repo_exist?
|
50
|
+
if git_url
|
51
|
+
repo_name = git_url.split('/').last
|
52
|
+
repo_name = repo_name[/.*(?=\.git)/] if repo_name.end_with? '.git'
|
53
|
+
repo_name
|
54
|
+
else
|
55
|
+
File.basename(File.dirname(git_own_repo.path)).to_s
|
56
|
+
end
|
70
57
|
else
|
71
58
|
path.basename.to_s
|
72
59
|
end
|
@@ -76,20 +63,19 @@ module Dapp
|
|
76
63
|
end
|
77
64
|
|
78
65
|
def git_url
|
79
|
-
return unless
|
80
|
-
|
66
|
+
return unless git_own_repo_exist?
|
67
|
+
git_own_repo.remote_origin_url
|
68
|
+
rescue Dimg::Error::Rugged => e
|
69
|
+
return if e.net_status[:code] == :git_repository_without_remote_url
|
70
|
+
raise
|
81
71
|
end
|
82
72
|
|
83
|
-
def
|
84
|
-
|
85
|
-
IniFile.load(File.join(git_path, 'config')) if git_path
|
86
|
-
end
|
73
|
+
def git_own_repo_exist?
|
74
|
+
git_own_repo.exist?
|
87
75
|
end
|
88
76
|
|
89
|
-
def
|
90
|
-
|
91
|
-
@git_path = search_file_upward('.git')
|
92
|
-
end
|
77
|
+
def git_own_repo
|
78
|
+
@git_own_repo ||= Dimg::GitRepo::Own.new(self)
|
93
79
|
end
|
94
80
|
|
95
81
|
def path(*path)
|
@@ -101,8 +87,8 @@ module Dapp
|
|
101
87
|
self.class.tmp_base_dir
|
102
88
|
end
|
103
89
|
|
104
|
-
def
|
105
|
-
@
|
90
|
+
def build_path(*path)
|
91
|
+
@build_path ||= begin
|
106
92
|
if option_build_dir
|
107
93
|
Pathname.new(option_build_dir)
|
108
94
|
else
|
@@ -110,15 +96,12 @@ module Dapp
|
|
110
96
|
Pathname.new(dir)
|
111
97
|
end.expand_path.tap(&:mkpath)
|
112
98
|
end
|
113
|
-
|
114
|
-
|
115
|
-
def build_path(*path)
|
116
|
-
make_path(build_dir, *path)
|
99
|
+
make_path(@build_path, *path)
|
117
100
|
end
|
118
101
|
|
119
102
|
def local_git_artifact_exclude_paths(&blk)
|
120
103
|
super do |exclude_paths|
|
121
|
-
build_path_relpath = Pathname.new(build_path).subpath_of(File.dirname(
|
104
|
+
build_path_relpath = Pathname.new(build_path).subpath_of(File.dirname(git_own_repo.path))
|
122
105
|
exclude_paths << build_path_relpath.to_s if build_path_relpath
|
123
106
|
|
124
107
|
yield exclude_paths if block_given?
|
@@ -1,22 +1,12 @@
|
|
1
1
|
module Dapp
|
2
2
|
class Dapp
|
3
3
|
module OptionTags
|
4
|
-
def git_local_repo
|
5
|
-
@git_repo ||= ::Dapp::Dimg::GitRepo::Own.new(self)
|
6
|
-
end
|
7
|
-
|
8
4
|
def tagging_schemes
|
9
5
|
%w(git_tag git_branch git_commit custom ci)
|
10
6
|
end
|
11
7
|
|
12
8
|
def tags_by_scheme
|
13
9
|
@tags_by_scheme_name ||= begin
|
14
|
-
if simple_tags[:custom].any?
|
15
|
-
if settings.fetch("sentry", {}).fetch("detect-push-tag-usage", false)
|
16
|
-
sentry_message("--tag or --tag-slug usage detected", extra: {"slug_tags" => simple_tags})
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
10
|
[simple_tags, branch_tags, commit_tags, build_tags, ci_tags].reduce({}) do |some_tags_by_scheme, tags_by_scheme|
|
21
11
|
tags_by_scheme.in_depth_merge(some_tags_by_scheme)
|
22
12
|
end.tap do |tags_by_scheme|
|
@@ -38,13 +28,13 @@ module Dapp
|
|
38
28
|
|
39
29
|
def branch_tags
|
40
30
|
return {} unless options[:tag_branch]
|
41
|
-
raise Error::Dapp, code: :git_branch_without_name if (branch =
|
31
|
+
raise Error::Dapp, code: :git_branch_without_name if (branch = git_own_repo.branch) == 'HEAD'
|
42
32
|
{ git_branch: [branch] }
|
43
33
|
end
|
44
34
|
|
45
35
|
def commit_tags
|
46
36
|
return {} unless options[:tag_commit]
|
47
|
-
{ git_commit: [
|
37
|
+
{ git_commit: [git_own_repo.latest_commit] }
|
48
38
|
end
|
49
39
|
|
50
40
|
def build_tags
|
@@ -32,7 +32,7 @@ module Dapp
|
|
32
32
|
def safe_cp(from, to, owner, group, include_paths = [], exclude_paths = [])
|
33
33
|
''.tap do |cmd|
|
34
34
|
cmd << dimg.dapp.rsync_bin
|
35
|
-
cmd << ' --archive --links
|
35
|
+
cmd << ' --archive --links'
|
36
36
|
cmd << " --chown=#{owner}:#{group}" if owner or group
|
37
37
|
|
38
38
|
if include_paths.any?
|
@@ -87,7 +87,7 @@ module Dapp
|
|
87
87
|
"#{builder.dimg.dapp.mkdir_bin} -p ~/.ssh",
|
88
88
|
'echo "Host *" >> ~/.ssh/config',
|
89
89
|
'echo " StrictHostKeyChecking no" >> ~/.ssh/config',
|
90
|
-
*local_paths.map {|path| "#{builder.dimg.dapp.rsync_bin} --
|
90
|
+
*local_paths.map {|path| "#{builder.dimg.dapp.rsync_bin} --archive --relative #{path} /tmp/local_cookbooks"},
|
91
91
|
"cd /tmp/local_cookbooks/#{path}",
|
92
92
|
"cp #{tmp_berksfile_path} Berksfile",
|
93
93
|
"cp #{tmp_metadata_path} metadata.rb",
|
@@ -4,8 +4,6 @@ module Dapp
|
|
4
4
|
module Directive
|
5
5
|
class Dimg < Base
|
6
6
|
module Validation
|
7
|
-
include Helper::Trivia
|
8
|
-
|
9
7
|
def validate!
|
10
8
|
directives_validate!
|
11
9
|
validate_scratch!
|
@@ -73,39 +71,12 @@ module Dapp
|
|
73
71
|
verifiable_artifact = artifacts.shift
|
74
72
|
artifacts.select { |a| a[:to] == verifiable_artifact[:to] }.each do |artifact|
|
75
73
|
next if verifiable_artifact[:index] == artifact[:index]
|
76
|
-
|
77
|
-
|
78
|
-
validate_artifact!(artifact, verifiable_artifact)
|
79
|
-
rescue ::Dapp::Error::Config => e
|
80
|
-
conflict_between_artifacts!(artifact, verifiable_artifact) if e.net_status[:code] == :artifact_conflict
|
81
|
-
raise
|
82
|
-
end
|
74
|
+
validate_artifact!(verifiable_artifact, artifact)
|
75
|
+
validate_artifact!(artifact, verifiable_artifact)
|
83
76
|
end
|
84
77
|
end
|
85
78
|
end
|
86
79
|
|
87
|
-
def conflict_between_artifacts!(*formatted_artifacts)
|
88
|
-
artifacts = formatted_artifacts.flatten.map { |formatted_artifact| formatted_artifact[:related_artifact] }
|
89
|
-
dappfile_context = artifacts.map do |artifact|
|
90
|
-
artifact_directive = []
|
91
|
-
artifact_directive << begin
|
92
|
-
if artifact.is_a? Artifact::Export
|
93
|
-
"artifact.export('#{artifact._cwd}') do"
|
94
|
-
else
|
95
|
-
"git#{"('#{artifact._url}')" if artifact.respond_to?(:_url)}.add('#{artifact._cwd}') do"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
[:include_paths, :exclude_paths].each do |directive|
|
99
|
-
next if (paths = artifact.send("_#{directive}")).empty?
|
100
|
-
artifact_directive << " #{directive} '#{paths.join("', '")}'"
|
101
|
-
end
|
102
|
-
artifact_directive << " to '#{artifact._to}'"
|
103
|
-
artifact_directive << 'end'
|
104
|
-
artifact_directive.join("\n")
|
105
|
-
end.join("\n\n")
|
106
|
-
raise ::Dapp::Error::Config, code: :artifact_conflict, data: { dappfile_context: dappfile_context }
|
107
|
-
end
|
108
|
-
|
109
80
|
def validate_artifact_format(artifacts)
|
110
81
|
artifacts.map do |a|
|
111
82
|
path_format = proc { |path| File.expand_path(File.join('/', path, '/'))[1..-1] }
|
@@ -133,20 +104,26 @@ module Dapp
|
|
133
104
|
index: artifacts.index(a),
|
134
105
|
to: to,
|
135
106
|
include_paths: include_paths,
|
136
|
-
exclude_paths: exclude_paths
|
137
|
-
related_artifact: a
|
107
|
+
exclude_paths: exclude_paths
|
138
108
|
}
|
139
109
|
end
|
140
110
|
end
|
141
111
|
|
142
112
|
def validate_artifact!(verifiable_artifact, artifact)
|
143
|
-
|
144
|
-
|
145
|
-
!
|
146
|
-
end
|
147
|
-
|
113
|
+
verifiable_artifact[:include_paths].each do |verifiable_path|
|
114
|
+
potential_conflicts = artifact[:include_paths].select { |path| path.start_with?(verifiable_path) }
|
115
|
+
validate_artifact_path!(verifiable_artifact, potential_conflicts)
|
116
|
+
end.empty? && verifiable_artifact[:exclude_paths].empty? && raise(::Dapp::Error::Config, code: :artifact_conflict)
|
117
|
+
validate_artifact_path!(verifiable_artifact, artifact[:include_paths]) if verifiable_artifact[:include_paths].empty?
|
118
|
+
end
|
148
119
|
|
149
|
-
|
120
|
+
def validate_artifact_path!(verifiable_artifact, potential_conflicts)
|
121
|
+
potential_conflicts.all? do |path|
|
122
|
+
loop do
|
123
|
+
break if verifiable_artifact[:exclude_paths].include?(path) || ((path = File.dirname(path)) == '.')
|
124
|
+
end
|
125
|
+
verifiable_artifact[:exclude_paths].include?(path)
|
126
|
+
end.tap { |res| res || raise(::Dapp::Error::Config, code: :artifact_conflict) }
|
150
127
|
end
|
151
128
|
|
152
129
|
def _associated_artifacts
|
@@ -3,23 +3,24 @@ module Dapp
|
|
3
3
|
module Config
|
4
4
|
module Directive
|
5
5
|
class GitArtifactRemote < GitArtifactLocal
|
6
|
-
include ::Dapp::Helper::Url
|
7
|
-
|
8
6
|
attr_reader :_url, :_name, :_branch, :_commit
|
9
7
|
|
10
8
|
def initialize(url, **kwargs, &blk)
|
11
9
|
@_url = url
|
12
|
-
|
10
|
+
|
11
|
+
url_without_scheme = url.split("://", 2).last
|
12
|
+
url_without_creds = url_without_scheme.split(":", 2).last
|
13
|
+
@_name = url_without_creds.gsub(%r{.*?([^\/ ]+\/[^\/ ]+)\.git}, '\\1')
|
13
14
|
|
14
15
|
super(**kwargs, &blk)
|
15
16
|
end
|
16
17
|
|
17
18
|
def branch(value)
|
18
|
-
sub_directive_eval { @_branch = value
|
19
|
+
sub_directive_eval { @_branch = value }
|
19
20
|
end
|
20
21
|
|
21
22
|
def commit(value)
|
22
|
-
sub_directive_eval { @_commit = value
|
23
|
+
sub_directive_eval { @_commit = value }
|
23
24
|
end
|
24
25
|
|
25
26
|
def _export
|
@@ -37,15 +38,15 @@ module Dapp
|
|
37
38
|
attr_accessor :_url, :_name, :_branch, :_commit
|
38
39
|
|
39
40
|
def _artifact_options
|
40
|
-
super.merge(name: _name, branch: _branch, commit: _commit)
|
41
|
+
super.merge(name: _name, branch: _branch.to_s, commit: _commit.to_s)
|
41
42
|
end
|
42
43
|
|
43
44
|
def branch(value)
|
44
|
-
sub_directive_eval { @_branch = value
|
45
|
+
sub_directive_eval { @_branch = value }
|
45
46
|
end
|
46
47
|
|
47
48
|
def commit(value)
|
48
|
-
sub_directive_eval { @_commit = value
|
49
|
+
sub_directive_eval { @_commit = value }
|
49
50
|
end
|
50
51
|
|
51
52
|
def validate!
|
@@ -11,8 +11,10 @@ module Dapp
|
|
11
11
|
log_step_with_indent(repo) do
|
12
12
|
registry = dimg_registry(repo)
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
if git_own_repo_exist?
|
15
|
+
cleanup_repo_by_nonexistent_git_primitive(registry, actual_detailed_dimgs_images_by_scheme(registry))
|
16
|
+
cleanup_repo_by_policies(registry, actual_detailed_dimgs_images_by_scheme(registry))
|
17
|
+
end
|
16
18
|
|
17
19
|
begin
|
18
20
|
repo_dimgs = repo_dimgs_images(registry)
|
@@ -46,7 +48,7 @@ module Dapp
|
|
46
48
|
case scheme
|
47
49
|
when 'git_tag' then consistent_git_tags.include?(detailed_dimg_image[:tag])
|
48
50
|
when 'git_branch' then consistent_git_remote_branches.include?(detailed_dimg_image[:tag])
|
49
|
-
when 'git_commit' then
|
51
|
+
when 'git_commit' then git_own_repo.commit_exists?(detailed_dimg_image[:tag])
|
50
52
|
else
|
51
53
|
raise
|
52
54
|
end
|
@@ -60,7 +62,7 @@ module Dapp
|
|
60
62
|
end
|
61
63
|
|
62
64
|
def consistent_git_remote_branches
|
63
|
-
@consistent_git_remote_branches ||=
|
65
|
+
@consistent_git_remote_branches ||= git_own_repo.remote_branches.map(&method(:consistent_uniq_slugify))
|
64
66
|
end
|
65
67
|
|
66
68
|
def cleanup_repo_by_nonexistent_git_base(repo_dimgs_images_by_scheme, dapp_tag_scheme)
|
@@ -80,15 +82,15 @@ module Dapp
|
|
80
82
|
if scheme == 'git_tag'
|
81
83
|
!consistent_git_tags.include?(dimg[:tag])
|
82
84
|
elsif scheme == 'git_commit'
|
83
|
-
!
|
85
|
+
!git_own_repo.commit_exists?(dimg[:tag])
|
84
86
|
end
|
85
87
|
end
|
86
88
|
|
87
89
|
dimg[:created_at] = begin
|
88
90
|
if scheme == 'git_tag'
|
89
|
-
|
91
|
+
git_own_repo.tag_at(git_tag_by_consistent_git_tag(dimg[:tag]))
|
90
92
|
elsif scheme == 'git_commit'
|
91
|
-
|
93
|
+
git_own_repo.commit_at(dimg[:tag])
|
92
94
|
end
|
93
95
|
end
|
94
96
|
dimg
|
@@ -120,7 +122,7 @@ module Dapp
|
|
120
122
|
end
|
121
123
|
|
122
124
|
def git_tag_by_consistent_tag_name
|
123
|
-
@git_consistent_tags ||=
|
125
|
+
@git_consistent_tags ||= git_own_repo.tags.map { |t| [consistent_uniq_slugify(t), t] }.to_h
|
124
126
|
end
|
125
127
|
|
126
128
|
def deployed_docker_images
|
@@ -7,24 +7,36 @@ module Dapp
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def local_git_artifacts
|
10
|
-
@local_git_artifact_list ||=
|
10
|
+
@local_git_artifact_list ||= [].tap do |artifacts|
|
11
11
|
repo = GitRepo::Own.new(self)
|
12
12
|
Array(config._git_artifact._local).map do |ga_config|
|
13
|
-
|
13
|
+
artifacts.concat(generate_git_artifacts(repo, **ga_config._artifact_options))
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
def remote_git_artifacts
|
19
|
-
@remote_git_artifact_list ||=
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
repos[repo_key] ||= GitRepo::Remote.new(self, ga_config._name, url: ga_config._url).tap { |repo| repo.fetch!(ga_config._branch) }
|
24
|
-
::Dapp::Dimg::GitArtifact.new(repos[repo_key], **ga_config._artifact_options)
|
19
|
+
@remote_git_artifact_list ||= [].tap do |artifacts|
|
20
|
+
Array(config._git_artifact._remote).each do |ga_config|
|
21
|
+
repo = GitRepo::Remote.get_or_init(self, ga_config._name, url: ga_config._url, branch: ga_config._branch)
|
22
|
+
artifacts.concat(generate_git_artifacts(repo, **ga_config._artifact_options))
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
26
|
+
|
27
|
+
def generate_git_artifacts(repo, **git_artifact_options)
|
28
|
+
[].tap do |artifacts|
|
29
|
+
artifacts << (artifact = ::Dapp::Dimg::GitArtifact.new(repo, **git_artifact_options))
|
30
|
+
artifacts.concat(generate_git_submodules_artifacts(artifact))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_git_submodules_artifacts(artifact)
|
35
|
+
[].tap do |artifacts|
|
36
|
+
artifacts.concat(submodules_artifacts = artifact.submodules_artifacts)
|
37
|
+
artifacts.concat(submodules_artifacts.map(&method(:generate_git_submodules_artifacts)).flatten)
|
38
|
+
end
|
39
|
+
end
|
28
40
|
end # GitArtifact
|
29
41
|
end # Mod
|
30
42
|
end # Dimg
|
@@ -3,6 +3,7 @@ module Dapp
|
|
3
3
|
# Git repo artifact
|
4
4
|
class GitArtifact
|
5
5
|
include Helper::Tar
|
6
|
+
include Helper::Trivia
|
6
7
|
|
7
8
|
attr_reader :repo
|
8
9
|
attr_reader :name
|
@@ -32,6 +33,93 @@ module Dapp
|
|
32
33
|
end
|
33
34
|
# rubocop:enable Metrics/ParameterLists
|
34
35
|
|
36
|
+
def submodules_artifacts
|
37
|
+
commit = dev_mode? ? nil : latest_commit
|
38
|
+
repo.submodules_params(commit,
|
39
|
+
paths: include_paths_or_cwd,
|
40
|
+
exclude_paths: exclude_paths(true)).map(&method(:submodule_artifact))
|
41
|
+
end
|
42
|
+
|
43
|
+
def submodule_artifact(submodule_params)
|
44
|
+
submodule_rel_path = submodule_params[:path]
|
45
|
+
submodule_repo = begin
|
46
|
+
GitRepo::Remote.get_or_init(repo.dimg, submodule_rel_path,
|
47
|
+
url: submodule_url(submodule_params[:url]),
|
48
|
+
branch: submodule_params[:branch])
|
49
|
+
rescue Rugged::InvalidError => e
|
50
|
+
raise Error::Rugged, code: :incorrect_gitmodules_file, data: { error: e.message }
|
51
|
+
end
|
52
|
+
|
53
|
+
self.class.new(submodule_repo, submodule_artifact_options(submodule_params))
|
54
|
+
end
|
55
|
+
|
56
|
+
def submodule_url(url)
|
57
|
+
if url.start_with?('../')
|
58
|
+
case repo.remote_origin_url_protocol
|
59
|
+
when :http, :https, :git
|
60
|
+
uri = URI.parse(repo.remote_origin_url)
|
61
|
+
uri.path = File.expand_path(File.join(uri.path, url))
|
62
|
+
uri.to_s
|
63
|
+
when :ssh
|
64
|
+
host_with_user, group_and_project = repo.remote_origin_url.split(':', 2)
|
65
|
+
group_and_project = File.expand_path(File.join('/', group_and_project, url))[1..-1]
|
66
|
+
[host_with_user, group_and_project].join(':')
|
67
|
+
else
|
68
|
+
raise
|
69
|
+
end
|
70
|
+
else
|
71
|
+
url
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def submodule_artifact_options(submodule_params)
|
76
|
+
submodule_rel_path = submodule_params[:path]
|
77
|
+
|
78
|
+
{}.tap do |options|
|
79
|
+
options[:name] = repo.dapp.consistent_uniq_slugify("submodule-#{submodule_rel_path}")
|
80
|
+
options[:cwd] = submodule_inherit_path(cwd, submodule_rel_path).last
|
81
|
+
options[:to] = File.join(to, submodule_rel_path)
|
82
|
+
options[:include_paths] = submodule_inherit_paths(include_paths, submodule_rel_path)
|
83
|
+
options[:exclude_paths] = submodule_inherit_paths(exclude_paths, submodule_rel_path)
|
84
|
+
options[:stages_dependencies] = begin
|
85
|
+
stages_dependencies
|
86
|
+
.map { |stage, paths| [stage, submodule_inherit_paths(paths, submodule_rel_path)] }
|
87
|
+
.to_h
|
88
|
+
end
|
89
|
+
options[:branch] = submodule_params[:branch]
|
90
|
+
options[:owner] = owner
|
91
|
+
options[:group] = group
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def submodule_inherit_paths(paths, submodule_rel_path)
|
96
|
+
paths
|
97
|
+
.select { |path| check_path?(submodule_rel_path, path) || check_subpath?(submodule_rel_path, path) }
|
98
|
+
.map { |path| submodule_inherit_path(path, submodule_rel_path) }
|
99
|
+
.flatten
|
100
|
+
.compact
|
101
|
+
end
|
102
|
+
|
103
|
+
def submodule_inherit_path(path, submodule_rel_path)
|
104
|
+
path_parts = path.split('/')
|
105
|
+
test_path = nil
|
106
|
+
inherited_paths = []
|
107
|
+
until path_parts.empty?
|
108
|
+
last_part_path = path_parts.shift
|
109
|
+
test_path = [test_path, last_part_path].compact.join('/')
|
110
|
+
|
111
|
+
non_match = !File.fnmatch(test_path, submodule_rel_path, File::FNM_PATHNAME)
|
112
|
+
part_for_all = (last_part_path == '**')
|
113
|
+
|
114
|
+
if non_match || part_for_all
|
115
|
+
inherited_paths << [last_part_path, path_parts].flatten.join('/')
|
116
|
+
break unless part_for_all
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
inherited_paths
|
121
|
+
end
|
122
|
+
|
35
123
|
def cwd_type(stage)
|
36
124
|
if dev_mode?
|
37
125
|
p = repo.workdir_path.join(cwd)
|
@@ -164,7 +252,6 @@ module Dapp
|
|
164
252
|
hexdigest begin
|
165
253
|
diff_patches(nil, nil, **options).map do |patch|
|
166
254
|
file = patch.delta.new_file
|
167
|
-
raise_if_submodule!(file[:path], file[:mode])
|
168
255
|
[file[:path], File.read(File.join(repo.workdir_path, file[:path])), file[:mode]]
|
169
256
|
end
|
170
257
|
end
|
@@ -225,7 +312,7 @@ module Dapp
|
|
225
312
|
def archive_file_with_tar_writer(stage, commit)
|
226
313
|
tar_write(repo.dimg.tmp_path('archives', archive_file_name(commit))) do |tar|
|
227
314
|
each_archive_entry(stage, commit) do |path, content, mode|
|
228
|
-
if mode ==
|
315
|
+
if mode == 0o120000 # symlink
|
229
316
|
tar.add_symlink path, content, mode
|
230
317
|
else
|
231
318
|
tar.add_file path, mode do |tf|
|
@@ -244,7 +331,7 @@ module Dapp
|
|
244
331
|
each_archive_entry(stage, commit) do |path, content, mode|
|
245
332
|
file_path = repo.dimg.tmp_path(relative_archive_file_path, path)
|
246
333
|
|
247
|
-
if mode ==
|
334
|
+
if mode == 0o120000 # symlink
|
248
335
|
FileUtils.symlink(content, file_path)
|
249
336
|
else
|
250
337
|
IO.write(file_path, content)
|
@@ -279,20 +366,11 @@ module Dapp
|
|
279
366
|
|
280
367
|
def patch_file(stage, from_commit, to_commit)
|
281
368
|
File.open(repo.dimg.tmp_path('patches', patch_file_name(from_commit, to_commit)), File::RDWR | File::CREAT) do |f|
|
282
|
-
diff_patches(from_commit, to_commit).each
|
283
|
-
file = patch.delta.new_file
|
284
|
-
raise_if_submodule!(file[:path], file[:mode])
|
285
|
-
f.write change_patch_new_file_path(stage, patch)
|
286
|
-
end
|
369
|
+
diff_patches(from_commit, to_commit).each { |patch| f.write change_patch_new_file_path(stage, patch) }
|
287
370
|
end
|
288
371
|
repo.dimg.container_tmp_path('patches', patch_file_name(from_commit, to_commit))
|
289
372
|
end
|
290
373
|
|
291
|
-
def raise_if_submodule!(relative_file_path, mode) # FIXME
|
292
|
-
return unless mode == 57344
|
293
|
-
raise Error::Rugged, code: :submodule_not_supported, data: { path: repo.path.dirname.join(relative_file_path) }
|
294
|
-
end
|
295
|
-
|
296
374
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
297
375
|
def change_patch_new_file_path(stage, patch)
|
298
376
|
patch.to_s.lines.tap do |lines|
|
@@ -356,7 +434,9 @@ module Dapp
|
|
356
434
|
|
357
435
|
def repo_entries(commit, paths: include_paths_or_cwd)
|
358
436
|
(@repo_entries ||= {})[[commit, paths]] ||= begin
|
359
|
-
repo
|
437
|
+
repo
|
438
|
+
.entries(commit, paths: paths, exclude_paths: exclude_paths(true))
|
439
|
+
.select { |_, entry| !submodule_mode?(entry[:filemode]) }
|
360
440
|
end
|
361
441
|
end
|
362
442
|
|
@@ -365,9 +445,7 @@ module Dapp
|
|
365
445
|
diff_patches(commit, nil).each do |patch|
|
366
446
|
file = patch.delta.new_file
|
367
447
|
host_file_path = File.join(repo.workdir_path, file[:path])
|
368
|
-
|
369
448
|
next unless File.exist?(host_file_path)
|
370
|
-
raise_if_submodule!(file[:path], file[:mode])
|
371
449
|
|
372
450
|
content = File.read(host_file_path)
|
373
451
|
yield slice_cwd(stage, file[:path]), content, file[:mode]
|
@@ -377,9 +455,6 @@ module Dapp
|
|
377
455
|
next unless entry[:type] == :blob
|
378
456
|
|
379
457
|
entry_file_path = File.join(root, entry[:name])
|
380
|
-
|
381
|
-
raise_if_submodule!(entry_file_path, entry[:filemode])
|
382
|
-
|
383
458
|
content = repo.lookup_object(entry[:oid]).content
|
384
459
|
yield slice_cwd(stage, entry_file_path), content, entry[:filemode]
|
385
460
|
end
|
@@ -395,10 +470,16 @@ module Dapp
|
|
395
470
|
opts[:recurse_untracked_dirs] = true
|
396
471
|
end
|
397
472
|
end
|
398
|
-
repo
|
473
|
+
repo
|
474
|
+
.patches(from_commit, to_commit, paths: paths, exclude_paths: exclude_paths(true), **options)
|
475
|
+
.select { |patch| !submodule_mode?(patch.delta.new_file[:mode]) } # FIXME: https://github.com/libgit2/rugged/issues/727
|
399
476
|
end
|
400
477
|
end
|
401
478
|
|
479
|
+
def submodule_mode?(mode) # FIXME
|
480
|
+
mode == 0o160000
|
481
|
+
end
|
482
|
+
|
402
483
|
def include_paths_or_cwd
|
403
484
|
case
|
404
485
|
when !include_paths(true).empty? then include_paths(true)
|
@@ -36,6 +36,56 @@ module Dapp
|
|
36
36
|
[]
|
37
37
|
end
|
38
38
|
|
39
|
+
def remote_origin_url
|
40
|
+
@remote_origin_url ||= begin
|
41
|
+
ro_url = url
|
42
|
+
while url_protocol(ro_url) == :noname
|
43
|
+
begin
|
44
|
+
parent_git = Rugged::Repository.discover(ro_url)
|
45
|
+
rescue Rugged::OSError
|
46
|
+
parent_git_path = parent_git ? parent_git.path : path
|
47
|
+
raise Error::Rugged, code: :git_repository_not_found, data: { path: ro_url, parent_git_path: parent_git_path }
|
48
|
+
end
|
49
|
+
|
50
|
+
ro_url = begin
|
51
|
+
git_url(parent_git)
|
52
|
+
rescue Error::Rugged => e
|
53
|
+
break if e.net_status[:code] == :git_repository_without_remote_url # local repository
|
54
|
+
raise
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
ro_url
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def remote_origin_url_protocol
|
63
|
+
url_protocol(remote_origin_url)
|
64
|
+
end
|
65
|
+
|
66
|
+
def submodules_params(commit, paths: [], exclude_paths: [])
|
67
|
+
raise "Workdir not supported for #{self.class}" if commit.nil?
|
68
|
+
|
69
|
+
entry = begin
|
70
|
+
lookup_commit(commit).tree.path('.gitmodules')
|
71
|
+
rescue Rugged::TreeError
|
72
|
+
return []
|
73
|
+
end
|
74
|
+
|
75
|
+
submodules_params_base(lookup_object(entry[:oid]).content, paths: paths, exclude_paths: exclude_paths)
|
76
|
+
end
|
77
|
+
|
78
|
+
def submodules_params_base(gitsubmodule_content, paths: [], exclude_paths: [])
|
79
|
+
IniFile.new.parse(gitsubmodule_content)
|
80
|
+
.to_h
|
81
|
+
.select { |_, params| !ignore_directory?(params['path'], paths: paths, exclude_paths: exclude_paths) }
|
82
|
+
.map do |_, params|
|
83
|
+
params = params.symbolize_keys
|
84
|
+
params[:branch] = params[:branch].to_s if params.key?(:branch)
|
85
|
+
params
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
39
89
|
# FIXME: Убрать логику исключения путей exclude_paths из данного класса,
|
40
90
|
# FIXME: т.к. большинство методов не поддерживают инвариант
|
41
91
|
# FIXME "всегда выдавать данные с исключенными путями".
|
@@ -48,7 +98,13 @@ module Dapp
|
|
48
98
|
|
49
99
|
def patches(from, to, paths: [], exclude_paths: [], **kwargs)
|
50
100
|
diff(from, to, **kwargs).patches.select do |patch|
|
51
|
-
|
101
|
+
delta_new_file = patch.delta.new_file
|
102
|
+
args = [delta_new_file[:path], paths: paths, exclude_paths: exclude_paths]
|
103
|
+
if delta_new_file[:mode] == 0o040000 # nested git repository in dev mode
|
104
|
+
!ignore_directory?(*args)
|
105
|
+
else
|
106
|
+
!ignore_path?(*args)
|
107
|
+
end
|
52
108
|
end
|
53
109
|
end
|
54
110
|
|
@@ -127,6 +183,13 @@ module Dapp
|
|
127
183
|
git.lookup(commit)
|
128
184
|
end
|
129
185
|
|
186
|
+
def exist?
|
187
|
+
git
|
188
|
+
true
|
189
|
+
rescue Rugged::OSError
|
190
|
+
false
|
191
|
+
end
|
192
|
+
|
130
193
|
protected
|
131
194
|
|
132
195
|
attr_reader :manager
|
@@ -134,6 +197,57 @@ module Dapp
|
|
134
197
|
def git(**kwargs)
|
135
198
|
@git ||= Rugged::Repository.new(path.to_s, **kwargs)
|
136
199
|
end
|
200
|
+
|
201
|
+
def url
|
202
|
+
@url ||= git_config_remote_origin_url(git)
|
203
|
+
end
|
204
|
+
|
205
|
+
def git_url(git_repo)
|
206
|
+
git_config_remote_origin_url(git_repo)
|
207
|
+
end
|
208
|
+
|
209
|
+
def git_config_remote_origin_url(git_repo)
|
210
|
+
git_repo.config.to_hash['remote.origin.url'].tap do |url|
|
211
|
+
raise Error::Rugged, code: :git_repository_without_remote_url, data: { name: self.class, path: git_repo.path } if url.nil?
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def url_protocol(url)
|
216
|
+
if (scheme = URI.parse(url).scheme).nil?
|
217
|
+
:noname
|
218
|
+
else
|
219
|
+
scheme.to_sym
|
220
|
+
end
|
221
|
+
rescue URI::InvalidURIError
|
222
|
+
:ssh
|
223
|
+
rescue Error::Rugged => e
|
224
|
+
return :none if e.net_status[:code] == :git_repository_without_remote_url
|
225
|
+
raise
|
226
|
+
end
|
227
|
+
|
228
|
+
private
|
229
|
+
|
230
|
+
def ignore_directory?(path, paths: [], exclude_paths: [])
|
231
|
+
ignore_path_base(path, exclude_paths: exclude_paths) do
|
232
|
+
paths.empty? || paths.any? { |p| check_path?(path, p) || check_subpath?(path, p) }
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def ignore_path?(path, paths: [], exclude_paths: [])
|
237
|
+
ignore_path_base(path, exclude_paths: exclude_paths) do
|
238
|
+
paths.empty? ||
|
239
|
+
paths.any? do |p|
|
240
|
+
File.fnmatch?(p, path, File::FNM_PATHNAME) ||
|
241
|
+
File.fnmatch?(File.join(p, '**', '*'), path, File::FNM_PATHNAME)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def ignore_path_base(path, exclude_paths: [])
|
247
|
+
is_exclude_path = exclude_paths.any? { |p| check_path?(path, p) }
|
248
|
+
is_include_path = yield
|
249
|
+
is_exclude_path || !is_include_path
|
250
|
+
end
|
137
251
|
end
|
138
252
|
end
|
139
253
|
end
|
@@ -23,6 +23,13 @@ module Dapp
|
|
23
23
|
# NOTICE: Параметры {from: nil, to: nil} можно указать только для Own repo.
|
24
24
|
# NOTICE: Для Remote repo такой вызов не имеет смысла и это ошибка пользователя класса Remote.
|
25
25
|
|
26
|
+
def submodules_params(commit, paths: [], exclude_paths: [])
|
27
|
+
return super unless commit.nil?
|
28
|
+
return [] unless File.file?((gitmodules_file_path = File.join(workdir_path, '.gitmodules')))
|
29
|
+
|
30
|
+
submodules_params_base(File.read(gitmodules_file_path), paths: paths, exclude_paths: exclude_paths)
|
31
|
+
end
|
32
|
+
|
26
33
|
def diff(from, to, **kwargs)
|
27
34
|
if from.nil? and to.nil?
|
28
35
|
mid_commit = latest_commit
|
@@ -45,6 +52,13 @@ module Dapp
|
|
45
52
|
rescue Rugged::OdbError, TypeError => _e
|
46
53
|
raise Error::Rugged, code: :commit_not_found_in_local_git_repository, data: { commit: commit }
|
47
54
|
end
|
55
|
+
|
56
|
+
def exist?
|
57
|
+
super
|
58
|
+
rescue Error::Rugged => e
|
59
|
+
return false if e.net_status[:code] == :local_git_repository_does_not_exist
|
60
|
+
raise
|
61
|
+
end
|
48
62
|
end
|
49
63
|
end
|
50
64
|
end
|
@@ -4,6 +4,11 @@ module Dapp
|
|
4
4
|
class Remote < Base
|
5
5
|
CACHE_VERSION = 1
|
6
6
|
|
7
|
+
def self.get_or_init(dimg, name, url:, branch:)
|
8
|
+
key = [url, branch]
|
9
|
+
(@repos ||= {})[key] ||= new(dimg, name, url: url).tap { |repo| repo.fetch!(branch) }
|
10
|
+
end
|
11
|
+
|
7
12
|
attr_reader :url
|
8
13
|
|
9
14
|
def initialize(dimg, name, url:)
|
@@ -14,8 +19,8 @@ module Dapp
|
|
14
19
|
_with_lock do
|
15
20
|
dapp.log_secondary_process(dapp.t(code: 'process.git_artifact_clone', data: { url: url }), short: true) do
|
16
21
|
begin
|
17
|
-
if [:https, :ssh].include?(
|
18
|
-
raise Error::Rugged, code: :rugged_protocol_not_supported, data: { url: url,
|
22
|
+
if [:https, :ssh].include?(remote_origin_url_protocol) && !Rugged.features.include?(remote_origin_url_protocol)
|
23
|
+
raise Error::Rugged, code: :rugged_protocol_not_supported, data: { url: url, url_protocol: remote_origin_url_protocol }
|
19
24
|
end
|
20
25
|
|
21
26
|
Rugged::Repository.clone_at(url, path.to_s, bare: true, credentials: _rugged_credentials)
|
@@ -32,7 +37,7 @@ module Dapp
|
|
32
37
|
|
33
38
|
def _rugged_credentials
|
34
39
|
@_rugged_credentials ||= begin
|
35
|
-
if
|
40
|
+
if remote_origin_url_protocol == :ssh
|
36
41
|
host_with_user = url.split(':', 2).first
|
37
42
|
username = host_with_user.split('@', 2).reverse.last
|
38
43
|
Rugged::Credentials::SshKeyFromAgent.new(username: username)
|
@@ -59,7 +64,11 @@ module Dapp
|
|
59
64
|
end
|
60
65
|
|
61
66
|
dapp.log_secondary_process(dapp.t(code: 'process.git_artifact_fetch', data: { url: url }), short: true) do
|
62
|
-
|
67
|
+
begin
|
68
|
+
git.fetch('origin', [branch], credentials: _rugged_credentials)
|
69
|
+
rescue Rugged::SshError => e
|
70
|
+
raise Error::Rugged, code: :rugged_remote_error, data: { url: url, message: e.message.strip }
|
71
|
+
end
|
63
72
|
raise Error::Rugged, code: :branch_not_exist_in_remote_git_repository, data: { branch: branch, url: url } unless branch_exist?(branch)
|
64
73
|
end
|
65
74
|
end unless dimg.ignore_git_fetch || dapp.dry_run?
|
@@ -90,18 +99,6 @@ module Dapp
|
|
90
99
|
def branch_format(name)
|
91
100
|
"origin/#{name.reverse.chomp('origin/'.reverse).reverse}"
|
92
101
|
end
|
93
|
-
|
94
|
-
def protocol
|
95
|
-
@protocol ||= begin
|
96
|
-
if (scheme = URI.parse(url).scheme).nil?
|
97
|
-
:noname
|
98
|
-
else
|
99
|
-
scheme.to_sym
|
100
|
-
end
|
101
|
-
rescue URI::InvalidURIError
|
102
|
-
:ssh
|
103
|
-
end
|
104
|
-
end
|
105
102
|
end
|
106
103
|
end
|
107
104
|
end
|
data/lib/dapp/helper/trivia.rb
CHANGED
@@ -28,28 +28,12 @@ module Dapp
|
|
28
28
|
Pathname.new(File.join(base.to_s, *path.compact.map(&:to_s)))
|
29
29
|
end
|
30
30
|
|
31
|
-
def ignore_path?(path, paths: [], exclude_paths: [])
|
32
|
-
ignore_path_base(path, exclude_paths: exclude_paths) do
|
33
|
-
paths.empty? ||
|
34
|
-
paths.any? do |p|
|
35
|
-
File.fnmatch?(p, path, File::FNM_PATHNAME|File::FNM_DOTMATCH) ||
|
36
|
-
File.fnmatch?(File.join(p, '**', '*'), path, File::FNM_PATHNAME|File::FNM_DOTMATCH)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def ignore_path_base(path, exclude_paths: [])
|
42
|
-
is_exclude_path = exclude_paths.any? { |p| check_path?(path, p) }
|
43
|
-
is_include_path = yield
|
44
|
-
is_exclude_path || !is_include_path
|
45
|
-
end
|
46
|
-
|
47
31
|
def check_path?(path, format)
|
48
|
-
path_checker(path) { |checking_path| File.fnmatch(format, checking_path, File::FNM_PATHNAME
|
32
|
+
path_checker(path) { |checking_path| File.fnmatch(format, checking_path, File::FNM_PATHNAME) }
|
49
33
|
end
|
50
34
|
|
51
35
|
def check_subpath?(path, format)
|
52
|
-
path_checker(format) { |checking_path| File.fnmatch(checking_path, path, File::FNM_PATHNAME
|
36
|
+
path_checker(format) { |checking_path| File.fnmatch(checking_path, path, File::FNM_PATHNAME) }
|
53
37
|
end
|
54
38
|
|
55
39
|
def path_checker(path)
|
@@ -116,7 +116,6 @@ module Dapp
|
|
116
116
|
# Поэтому перехватываем и просто отображаем произошедшую
|
117
117
|
# ошибку для информации пользователю без завершения работы dapp.
|
118
118
|
$stderr.puts(::Dapp::Dapp.paint_string(::Dapp::Helper::NetStatus.message(e), :warning))
|
119
|
-
sentry_exception(e, extra: {"job-spec" => job.spec})
|
120
119
|
end
|
121
120
|
|
122
121
|
end # Thread
|
@@ -13,8 +13,8 @@ module Dapp
|
|
13
13
|
template_relative_path_pattern = Pathname(File.expand_path(template_path_pattern)).subpath_of(path('.helm'))
|
14
14
|
template_relative_path_pattern ||= template_path_pattern
|
15
15
|
|
16
|
-
File.fnmatch?(template_relative_path_pattern, template_path_without_chart_name, File::FNM_PATHNAME
|
17
|
-
File.fnmatch?(template_relative_path_pattern, template_path, File::FNM_PATHNAME
|
16
|
+
File.fnmatch?(template_relative_path_pattern, template_path_without_chart_name, File::FNM_PATHNAME) ||
|
17
|
+
File.fnmatch?(template_relative_path_pattern, template_path, File::FNM_PATHNAME)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
else
|
@@ -36,10 +36,10 @@ module Dapp
|
|
36
36
|
elsif ENV["CI_COMMIT_REF_NAME"]
|
37
37
|
ci_info["branch"] = ci_info["ref"] = ENV["CI_COMMIT_REF_NAME"]
|
38
38
|
ci_info["is_branch"] = true
|
39
|
-
elsif dapp.
|
39
|
+
elsif dapp.git_own_repo_exist? and dapp.git_local_repo.branch != "HEAD"
|
40
40
|
ci_info["branch"] = ci_info["ref"] = dapp.git_local_repo.branch
|
41
41
|
ci_info["is_branch"] = true
|
42
|
-
elsif dapp.
|
42
|
+
elsif dapp.git_own_repo_exist?
|
43
43
|
git = dapp.git_local_repo.send(:git)
|
44
44
|
|
45
45
|
tagref = git.references.find do |r|
|
data/lib/dapp/version.rb
CHANGED
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.
|
4
|
+
version: 0.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Stolyarov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|
@@ -186,34 +186,6 @@ dependencies:
|
|
186
186
|
- - ">="
|
187
187
|
- !ruby/object:Gem::Version
|
188
188
|
version: 1.0.6
|
189
|
-
- !ruby/object:Gem::Dependency
|
190
|
-
name: sentry-raven
|
191
|
-
requirement: !ruby/object:Gem::Requirement
|
192
|
-
requirements:
|
193
|
-
- - "~>"
|
194
|
-
- !ruby/object:Gem::Version
|
195
|
-
version: 2.7.2
|
196
|
-
type: :runtime
|
197
|
-
prerelease: false
|
198
|
-
version_requirements: !ruby/object:Gem::Requirement
|
199
|
-
requirements:
|
200
|
-
- - "~>"
|
201
|
-
- !ruby/object:Gem::Version
|
202
|
-
version: 2.7.2
|
203
|
-
- !ruby/object:Gem::Dependency
|
204
|
-
name: toml-rb
|
205
|
-
requirement: !ruby/object:Gem::Requirement
|
206
|
-
requirements:
|
207
|
-
- - "~>"
|
208
|
-
- !ruby/object:Gem::Version
|
209
|
-
version: 1.1.1
|
210
|
-
type: :runtime
|
211
|
-
prerelease: false
|
212
|
-
version_requirements: !ruby/object:Gem::Requirement
|
213
|
-
requirements:
|
214
|
-
- - "~>"
|
215
|
-
- !ruby/object:Gem::Version
|
216
|
-
version: 1.1.1
|
217
189
|
- !ruby/object:Gem::Dependency
|
218
190
|
name: bundler
|
219
191
|
requirement: !ruby/object:Gem::Requirement
|
@@ -476,7 +448,6 @@ files:
|
|
476
448
|
- lib/dapp/dapp/logging/paint.rb
|
477
449
|
- lib/dapp/dapp/logging/process.rb
|
478
450
|
- lib/dapp/dapp/option_tags.rb
|
479
|
-
- lib/dapp/dapp/sentry.rb
|
480
451
|
- lib/dapp/dapp/shellout/base.rb
|
481
452
|
- lib/dapp/dapp/shellout/streaming.rb
|
482
453
|
- lib/dapp/dapp/slug.rb
|
@@ -676,7 +647,6 @@ files:
|
|
676
647
|
- lib/dapp/helper/sha256.rb
|
677
648
|
- lib/dapp/helper/tar.rb
|
678
649
|
- lib/dapp/helper/trivia.rb
|
679
|
-
- lib/dapp/helper/url.rb
|
680
650
|
- lib/dapp/helper/yaml.rb
|
681
651
|
- lib/dapp/kube.rb
|
682
652
|
- lib/dapp/kube/cli/cli.rb
|
data/lib/dapp/dapp/sentry.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
module Dapp
|
2
|
-
class Dapp
|
3
|
-
module Sentry
|
4
|
-
def sentry_message(msg, **kwargs)
|
5
|
-
return if not ensure_sentry_configured
|
6
|
-
kwargs[:level] ||= "info"
|
7
|
-
Raven.capture_message(msg, _make_sentry_params(**kwargs))
|
8
|
-
end
|
9
|
-
|
10
|
-
def sentry_exception(exception, **kwargs)
|
11
|
-
return if not ensure_sentry_configured
|
12
|
-
(kwargs[:tags] ||= {})['error-code'] = begin
|
13
|
-
net_status = exception.net_status
|
14
|
-
[net_status[:context], net_status[:code]].compact.join('_')
|
15
|
-
end
|
16
|
-
Raven.capture_exception(exception, _make_sentry_params(**kwargs))
|
17
|
-
end
|
18
|
-
|
19
|
-
def ensure_sentry_configured
|
20
|
-
return false unless sentry_settings = settings["sentry"]
|
21
|
-
|
22
|
-
unless @sentry_settings_configured
|
23
|
-
Raven.configure do |config|
|
24
|
-
logger = ::Logger.new(STDOUT)
|
25
|
-
logger.level = ::Logger::WARN
|
26
|
-
|
27
|
-
config.logger = logger
|
28
|
-
config.dsn = sentry_settings["dsn"]
|
29
|
-
end
|
30
|
-
|
31
|
-
@sentry_settings_configured = true
|
32
|
-
end
|
33
|
-
|
34
|
-
return true
|
35
|
-
end
|
36
|
-
|
37
|
-
def _make_sentry_params(level: nil, tags: {}, extra: {}, user: {})
|
38
|
-
{
|
39
|
-
level: level,
|
40
|
-
tags: _sentry_tags_context.merge(tags),
|
41
|
-
extra: _sentry_extra_context.merge(extra),
|
42
|
-
user: _sentry_user_context.merge(user),
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
def _sentry_extra_context
|
47
|
-
@_sentry_extra_context ||= {
|
48
|
-
"pwd" => Dir.pwd,
|
49
|
-
"dapp-dir" => self.work_dir,
|
50
|
-
"options" => self.options,
|
51
|
-
"env-options" => {
|
52
|
-
"DAPP_FORCE_SAVE_CACHE" => ENV["DAPP_FORCE_SAVE_CACHE"],
|
53
|
-
"DAPP_BIN_DAPPFILE_YML" => ENV["DAPP_BIN_DAPPFILE_YML"],
|
54
|
-
"ANSIBLE_ARGS" => ENV["ANSIBLE_ARGS"],
|
55
|
-
"DAPP_CHEF_DEBUG" => ENV["DAPP_CHEF_DEBUG"],
|
56
|
-
},
|
57
|
-
}.tap {|extra|
|
58
|
-
extra["ci-env"] = {"CI" => ENV["CI"]}
|
59
|
-
ENV.select {|k, v| k.start_with?("CI_")}.each do |k, v|
|
60
|
-
extra["ci-env"][k] = v
|
61
|
-
end
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
def _sentry_tags_context
|
66
|
-
name = options[:name] ||
|
67
|
-
@_sentry_tags_context ||= {
|
68
|
-
"dapp-short-version" => ::Dapp::VERSION.split(".")[0..1].join("."),
|
69
|
-
"dapp-version" => ::Dapp::VERSION,
|
70
|
-
"dapp-build-cache-version" => ::Dapp::BUILD_CACHE_VERSION,
|
71
|
-
"dapp-command" => self.options[:dapp_command],
|
72
|
-
}.tap {|tags|
|
73
|
-
git_config_path = File.join(Dir.pwd, ".git/config")
|
74
|
-
|
75
|
-
tags["dapp-name"] = options[:name]
|
76
|
-
|
77
|
-
if File.exists? git_config_path
|
78
|
-
cfg = IniFile.load(File.join(Dir.pwd, ".git/config"))
|
79
|
-
remote_origin_cfg = cfg['remote "origin"']
|
80
|
-
remote_origin_url = remote_origin_cfg["url"]
|
81
|
-
if remote_origin_url
|
82
|
-
tags["dapp-name"] ||= begin
|
83
|
-
repo_name = remote_origin_url.split('/').last
|
84
|
-
repo_name = repo_name[/.*(?=\.git)/] if repo_name.end_with? '.git'
|
85
|
-
repo_name
|
86
|
-
end
|
87
|
-
|
88
|
-
tags["git-host"] = self.get_host_from_git_url(remote_origin_url)
|
89
|
-
|
90
|
-
git_name = self.git_url_to_name(remote_origin_url)
|
91
|
-
|
92
|
-
tags["git-group"] = git_name.partition("/")[0]
|
93
|
-
tags["git-name"] = git_name
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
tags["dapp-name"] ||= File.basename(Dir.pwd)
|
98
|
-
|
99
|
-
begin
|
100
|
-
ver = self.class.host_docker_minor_version
|
101
|
-
tags["docker-minor-version"] = ver.to_s
|
102
|
-
rescue ::Exception
|
103
|
-
end
|
104
|
-
}
|
105
|
-
end
|
106
|
-
|
107
|
-
def _sentry_user_context
|
108
|
-
@_sentry_user_context ||= {}
|
109
|
-
end
|
110
|
-
end # Sentry
|
111
|
-
end # Dapp
|
112
|
-
end # Dapp
|
data/lib/dapp/helper/url.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Dapp
|
2
|
-
module Helper
|
3
|
-
module Url
|
4
|
-
def git_url_to_name(url)
|
5
|
-
url_without_scheme = url.split("://", 2).last
|
6
|
-
# This may be broken, because "@" should delimit creds, not a ":"
|
7
|
-
url_without_creds = url_without_scheme.split(":", 2).last
|
8
|
-
url_without_creds.gsub(%r{.*?([^\/ ]+\/[^\/ ]+)\.git}, '\\1')
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_host_from_git_url(url)
|
12
|
-
url_without_scheme = url.split("://", 2).last
|
13
|
-
url_without_creds = url_without_scheme.split("@", 2).last
|
14
|
-
|
15
|
-
# Split out part after ":" in this kind of url: github.com:flant/dapp.git
|
16
|
-
url_part = url_without_creds.split(":", 2).first
|
17
|
-
|
18
|
-
# Split out part after first "/": github.com/flant/dapp.git
|
19
|
-
url_part.split("/", 2).first
|
20
|
-
end
|
21
|
-
end # Url
|
22
|
-
end # Helper
|
23
|
-
end # Dapp
|