docman 0.0.80 → 0.0.81

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: f7879f486dcae92bf43bb21d279c226a58c7ddc9
4
- data.tar.gz: ea6dfe6ebd3df5c78fe973b98e33a806b76535de
3
+ metadata.gz: 9143ca229196d50ceb0be8f5e11d6d8e3650ac1d
4
+ data.tar.gz: 04440af097c5ea1cabb15190c871df939621981a
5
5
  SHA512:
6
- metadata.gz: dfc8c60aec13d38a4230b250dc2f4e986689aba36c46e88a6432e5d4f67ec6d6ba4213f1e509c2168590a83a360446062d922d9607a2120fbcf6df836d592c16
7
- data.tar.gz: 501990da1d1399890eba3b520d0a790d0f41cc1c0c605ddb2c0f606eda54f0136ef40b969173248e05e0443f9db9ea1d7975ca1ff4b48a83ab3ec542086cf814
6
+ metadata.gz: 94991a65d0c2d8eb88c04a1a6e43d66e85cf8f449c789f102bb1b64a136d10bed191a0848c1aa28a7bf453137c586147f8b5d787e4b9ce83de39d9675bbaa874
7
+ data.tar.gz: b884a747f67815c57758efed8bb9e61fbdc885ab5f0aea5afc2fbad91773ee7061a63dc24daf72e546e696cc3fd83031979d89ac4d2511bb29ec083e4e984237
@@ -1,115 +1,157 @@
1
1
  ---
2
+ # common hooks used in deploy targets below
3
+ common_hooks:
4
+ - &execute_yaml_file
5
+ type: yaml_execute
6
+ source_type: file
7
+ order: -10
8
+ stage: build
9
+
10
+ - &execute_yaml_file_for_git_provider
11
+ <<: *execute_yaml_file
12
+ providers:
13
+ - :git_repo_provider
14
+
15
+ - &remove_git_dir
16
+ type: :yaml_execute
17
+ providers:
18
+ - :git_repo_provider
19
+ order: 0
20
+ commands:
21
+ - rm -fR .git
22
+
23
+ - &git_commit
24
+ type: :git_commit
25
+ order: 100
26
+
2
27
  deploy_targets:
28
+ # target for local build
3
29
  local:
30
+ # deployer handler
4
31
  handler: :common_deployer
5
32
  builders:
6
33
  root:
7
34
  handler: :dir_builder
8
35
  root_chain:
9
- handler: :git_direct_builder
36
+ handler: :direct_builder
37
+ provider: :git_repo_provider
38
+ target_path_id: full_build_path
10
39
  hooks:
11
40
  builder:
12
41
  after_execute:
13
- - type: :yaml_execute
14
- source_type: file
15
- order: -10
16
- stage: build
17
- drupal:
18
- handler: :drupal_drush_builder
42
+ - <<: *execute_yaml_file_for_git_provider
43
+ repo:
44
+ handler: :direct_builder
45
+ provider: :git_repo_provider
46
+ target_path_id: full_build_path
19
47
  hooks:
20
48
  builder:
21
49
  after_execute:
22
- - type: :yaml_execute
23
- source_type: file
24
- order: -10
25
- stage: build
50
+ - <<: *execute_yaml_file
51
+ dir:
52
+ handler: :dir_builder
53
+ states:
54
+ development: local
55
+ staging: local
56
+ stable: local
57
+
58
+ # Target for striped (from .git dirs)
59
+ striped:
60
+ # deployer handler
61
+ handler: :common_deployer
62
+ builders:
63
+ root:
64
+ handler: :dir_builder
65
+ root_chain:
66
+ handler: :direct_builder
67
+ provider: :git_repo_provider
68
+ target_path_id: full_build_path
69
+ hooks:
70
+ builder:
71
+ after_execute:
72
+ - <<: *remove_git_dir
73
+ - <<: *execute_yaml_file_for_git_provider
26
74
  repo:
27
- handler: :git_direct_builder
75
+ handler: :direct_builder
76
+ provider: :git_repo_provider
77
+ target_path_id: full_build_path
28
78
  hooks:
29
79
  builder:
30
80
  after_execute:
31
- - type: :yaml_execute
32
- source_type: file
33
- order: -10
34
- stage: build
81
+ - <<: *remove_git_dir
82
+ - <<: *execute_yaml_file
35
83
  dir:
36
84
  handler: :dir_builder
37
- symlink:
38
- handler: :symlink_builder
39
85
  states:
40
86
  development: local
41
87
  staging: local
42
88
  stable: local
89
+
90
+ # Target for pushing build result into target repo
43
91
  git_target:
92
+ # deployer handler
44
93
  handler: :git_deployer
45
94
  builders:
46
95
  root:
47
- handler: :git_direct_builder
96
+ handler: :direct_builder
97
+ provider: :git_repo_provider
98
+ target_path_id: full_build_path
48
99
  hooks:
49
100
  builder:
50
101
  after_execute:
51
- - type: :git_commit
52
- order: 100
53
- execution_dir: $PROJECT$
102
+ - <<: *git_commit
54
103
  root_chain:
55
104
  handler: :git_root_chain_builder
105
+ provider: :git_repo_provider
106
+ target_path_id: temp_path
56
107
  hooks:
57
108
  builder:
58
109
  after_execute:
59
- - type: :yaml_execute
60
- source_type: file
61
- order: -10
62
- execution_dir: $PROJECT$
63
- stage: build
64
- - type: :git_commit
65
- order: 100
66
- execution_dir: $PROJECT$
67
- drupal:
68
- handler: :drupal_drush_builder
69
- hooks:
70
- builder:
71
- after_execute:
72
- - type: :git_commit
73
- order: 100
74
- execution_dir: $PROJECT$
110
+ - <<: *execute_yaml_file_for_git_provider
111
+ - <<: *git_commit
75
112
  repo:
76
113
  handler: :git_strip_builder
114
+ provider: :git_repo_provider
115
+ target_path_id: temp_path
116
+ hooks:
77
117
  hooks:
78
118
  builder:
79
119
  before_execute:
80
120
  - type: :git_pull
81
- execution_dir: $PROJECT$
82
121
  after_execute:
83
- - type: :yaml_execute
84
- source_type: file
85
- order: -10
86
- execution_dir: $PROJECT$
87
- stage: build
88
- - type: :git_commit
89
- order: 100
90
- execution_dir: $PROJECT$
122
+ - <<: *execute_yaml_file_for_git_provider
123
+ - <<: *git_commit
91
124
  dir:
92
125
  handler: :dir_builder
93
126
  hooks:
94
127
  builder:
95
128
  after_execute:
96
- - type: :git_commit
97
- order: 100
98
- execution_dir: $PROJECT$
99
- symlink:
100
- handler: :symlink_builder
101
- hooks:
102
- builder:
103
- after_execute:
104
- - type: :git_commit
105
- order: 100
106
- execution_dir: $PROJECT$
129
+ - <<: *git_commit
107
130
  states:
108
131
  development: dev
109
132
  staging: test
110
133
  stable: prod
134
+
111
135
  environments:
112
136
  local:
113
137
  deploy_target: local
114
138
  state: development
115
139
  clean_changed: true
140
+ striped:
141
+ deploy_target: striped
142
+ state: development
143
+ clean_changed: true
144
+ dev:
145
+ deploy_target: git_target
146
+ state: development
147
+ test:
148
+ deploy_target: git_target
149
+ state: staging
150
+ prod:
151
+ deploy_target: git_target
152
+ state: stable
153
+
154
+ components:
155
+ master:
156
+
157
+ pipeline_script: .pipeline
@@ -27,4 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency 'net-sftp'
28
28
  spec.add_dependency 'hooks'
29
29
  spec.add_dependency 'diffy'
30
+ spec.add_dependency 'io-console'
31
+ spec.add_dependency 'json'
30
32
  end
@@ -13,12 +13,12 @@ require 'logger'
13
13
  require 'json'
14
14
 
15
15
  require 'docman/builders/builder'
16
+ require 'docman/builders/provider_builder'
17
+ require 'docman/builders/git_provider_builder'
16
18
  require 'docman/builders/dir_builder'
17
- require 'docman/builders/symlink_builder'
18
- require 'docman/builders/git_direct_builder'
19
+ require 'docman/builders/direct_builder'
19
20
  require 'docman/builders/git_root_chain_builder'
20
21
  require 'docman/builders/git_strip_builder'
21
- require 'docman/builders/drupal_drush_builder'
22
22
  require 'docman/deployers/deployer'
23
23
  require 'docman/deployers/git_deployer'
24
24
  require 'docman/deployers/common_deployer'
@@ -30,7 +30,8 @@ require 'docman/commands/clean_changed_cmd'
30
30
  require 'docman/commands/git_commit_cmd'
31
31
  require 'docman/commands/yaml_execute_cmd'
32
32
  require 'docman/commands/git_pull_cmd'
33
- require 'docman/commands/git_copy_repo_content_cmd'
33
+ require 'docman/commands/git_repo_provider_cmd'
34
+ require 'docman/commands/nexus_provider_cmd'
34
35
  require 'docman/taggers/tagger'
35
36
  require 'docman/taggers/incremental_tagger'
36
37
  require 'docman/taggers/option_tagger'
@@ -80,9 +81,8 @@ module Docman
80
81
  def build(deploy_target_name, state, options = false)
81
82
  with_rescue do
82
83
  @options = options
83
- @deploy_target = @config['deploy_targets'][deploy_target_name]
84
- @deploy_target['name'] = deploy_target_name
85
- @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
84
+ @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target_name, options)
85
+ @deploy_target = @docroot_config.deploy_target
86
86
  execute('build', state, nil, options['tag'])
87
87
  end
88
88
  end
@@ -91,10 +91,8 @@ module Docman
91
91
  result = nil
92
92
  with_rescue do
93
93
  @options = options
94
- @deploy_target = @config['deploy_targets'][deploy_target_name]
95
- raise "Wrong deploy target: #{deploy_target_name}" if @deploy_target.nil?
96
- @deploy_target['name'] = deploy_target_name
97
- @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
94
+ @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target_name, options)
95
+ @deploy_target = @docroot_config.deploy_target
98
96
  @docroot_config.states_dependin_on(name, version).keys.each do |state|
99
97
  execute('deploy', state, name)
100
98
  write_environment(@deploy_target['states'][state], name)
@@ -146,7 +144,7 @@ module Docman
146
144
 
147
145
  def info(command, file, options = false)
148
146
  result = {}
149
- @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
147
+ @docroot_config = DocrootConfig.new(@workspace_dir, nil, options)
150
148
  if (command == 'full')
151
149
  result['states'] = Docman::Application.instance.config['deploy_targets']['git_target']['states']
152
150
  result['environments'] = Docman::Application.instance.config['environments']
@@ -3,6 +3,7 @@ require 'docman/commands/command'
3
3
  module Docman
4
4
  module Builders
5
5
  class Builder < Docman::Command
6
+
6
7
  @@builders = {}
7
8
  @@build_results = {}
8
9
 
@@ -28,8 +29,7 @@ module Docman
28
29
  clean_changed = environment['clean_changed'].nil? ? true : environment['clean_changed']
29
30
  add_action('before_execute', {'type' => :clean_changed}, @context) if clean_changed
30
31
 
31
- info_file = File.join(@context['full_build_path'], 'info.yaml')
32
- info = YAML::load_file(info_file) if File.file? info_file
32
+ info = @context.info_file_yaml
33
33
  if info
34
34
  info['context'] = @context
35
35
  name = @context['name']
@@ -37,6 +37,13 @@ module Docman
37
37
  environment['previous'][name] = info
38
38
  end
39
39
 
40
+ unless @context.key? 'provider'
41
+ @context['provider'] = self['provider']
42
+ end
43
+ if @context['provider'] && self['target_path_id']
44
+ self['target_path'] = @context[self['target_path_id']]
45
+ @provider = Docman::Command.create({'type' => @context['provider'], 'target_path' => self['target_path']}, @context, self)
46
+ end
40
47
  end
41
48
 
42
49
  def validate_command
@@ -51,6 +58,7 @@ module Docman
51
58
  before_execute do
52
59
  if @context.need_rebuild?
53
60
  @context.build_mode = :rebuild
61
+ log("Need to rebuild")
54
62
  else
55
63
  if @context.changed? or changed?
56
64
  @context.build_mode = :update
@@ -0,0 +1,9 @@
1
+ module Docman
2
+ module Builders
3
+ class DirectBuilder < ProviderBuilder
4
+
5
+ register_builder :direct_builder
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ module Docman
2
+ module Builders
3
+ class GitProviderBuilder < ProviderBuilder
4
+
5
+ register_builder :git_provider_builder
6
+
7
+ def prepare_build_dir
8
+ FileUtils.mkdir_p(@context['full_build_path'])
9
+ end
10
+
11
+ def build_with_provider
12
+ FileUtils.rm_r(Dir["#{@context['full_build_path']}/*"]) if File.directory? @context['full_build_path']
13
+ FileUtils.rm_r self['target_path'] if @context.need_rebuild? and File.directory? self['target_path']
14
+ result = @provider.perform
15
+ `rsync -a --exclude '.git' #{self['target_path']}/. #{@context['full_build_path']}`
16
+ result
17
+ end
18
+
19
+ def changed_from_last_version?
20
+ @provider.changed_from_last_version?
21
+ end
22
+
23
+ def execute
24
+ prepare_build_dir
25
+ @execute_result = build_with_provider
26
+ changed_from_last_version? ? @execute_result : false
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -1,21 +1,11 @@
1
1
  module Docman
2
2
  module Builders
3
- class GitRootChainBuilder < Builder
3
+ class GitRootChainBuilder < GitProviderBuilder
4
4
 
5
5
  register_builder :git_root_chain_builder
6
6
 
7
- def execute
8
- GitUtil.get(@context['root_repo'], @context['full_build_path'], @context.version_type(type: 'root'), @context.version(type: 'root'))
9
- @version = Docman::Command.create({'type' => :git_copy_repo_content, 'remove_target' => true}, @context, self).perform
10
- @last_revision != @version ? @version : false
11
- end
12
-
13
- def changed?
14
- stored_version = @context.stored_version['result']
15
- @last_revision = GitUtil.last_revision @context['temp_path']
16
- # No commit hash for 'root' as it will be changed later
17
- @version = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version)
18
- stored_version != @version
7
+ def prepare_build_dir
8
+ GitUtil.get(@context['root_repo'], @context['full_build_path'], @context.version_type(type: 'root'), @context.version(type: 'root'), true, 1)
19
9
  end
20
10
 
21
11
  end
@@ -1,23 +1,11 @@
1
1
  module Docman
2
2
  module Builders
3
- class GitStripBuilder < Builder
3
+ class GitStripBuilder < GitProviderBuilder
4
4
 
5
5
  register_builder :git_strip_builder
6
6
 
7
- def execute
8
- FileUtils.rm_r(@context['full_build_path']) if File.directory? @context['full_build_path']
9
- FileUtils.rm_r @context['temp_path'] if @context.need_rebuild? and File.directory? @context['temp_path']
10
- @version = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version, nil, nil)
11
- FileUtils.mkdir_p(@context['full_build_path'])
12
- FileUtils.cp_r(Dir["#{@context['temp_path']}/."], @context['full_build_path'])
13
- FileUtils.rm_r(File.join(@context['full_build_path'], '.git')) if File.directory?(File.join(@context['full_build_path'], '.git'))
14
- GitUtil.repo_changed?(@context['full_build_path']) ? @version : false
15
- end
16
-
17
- def changed?
18
- stored_version = @context.stored_version['result']
19
- @version = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version, nil, nil)
20
- stored_version != @version
7
+ def changed_from_last_version?
8
+ GitUtil.repo_changed?(@context['full_build_path'])
21
9
  end
22
10
 
23
11
  end
@@ -0,0 +1,17 @@
1
+ module Docman
2
+ module Builders
3
+ class ProviderBuilder < Builder
4
+
5
+ register_builder :provider_builder
6
+
7
+ def execute
8
+ @provider.perform
9
+ end
10
+
11
+ def changed?
12
+ @provider.changed?
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -40,6 +40,7 @@ module Docman
40
40
 
41
41
  desc 'build', 'Build docroot'
42
42
  method_option :force, :aliases => '-f', :desc => 'Force full rebuild'
43
+ method_option :config, :desc => 'Configuration override JSON'
43
44
  option :tag
44
45
  def build(deploy_target, state)
45
46
  get_to_root_dir
@@ -52,6 +53,7 @@ module Docman
52
53
 
53
54
  desc 'deploy', 'Deploy to target'
54
55
  method_option :force, :aliases => '-f', :desc => 'Force full deploy'
56
+ method_option :config, :desc => 'Configuration override JSON'
55
57
  def deploy(deploy_target, name, type, version)
56
58
  get_to_root_dir
57
59
  if version.start_with?('state_')
@@ -14,11 +14,11 @@ module Docman
14
14
  if @context.need_rebuild?
15
15
  return false if @context['type'] == 'dir'
16
16
  return false if @context['type'] == 'root' and @context['build_type'] == :dir_builder and not GitUtil.repo?(@context['full_build_path'])
17
- return false if @context['type'] == 'root' and @context['build_type'] == :git_direct_builder and GitUtil.repo?(@context['full_build_path'])
18
- return false if @context['type'] == 'root_chain' and @context['build_type'] == :git_direct_builder and GitUtil.repo?(@context['full_build_path'])
17
+ return false if @context['type'] == 'root' and @context['build_type'] == :direct_builder and GitUtil.repo?(@context['full_build_path'])
18
+ return false if @context['type'] == 'root_chain' and @context['build_type'] == :direct_builder and GitUtil.repo?(@context['full_build_path'])
19
19
  return false if @context['type'] == 'root_chain' and @context['build_type'] == :git_root_chain_builder and GitUtil.repo?(@context['full_build_path'])
20
20
  if @context['type'] == 'repo'
21
- if @context['build_type'] == :git_direct_builder
21
+ if @context['build_type'] == :direct_builder
22
22
  return false if GitUtil.repo?(@context['full_build_path'])
23
23
  end
24
24
  end
@@ -17,6 +17,7 @@ module Docman
17
17
  define_hooks :before_execute, :after_execute
18
18
 
19
19
  def self.create(params, context = nil, caller = nil)
20
+ params['type'] = params['type'].to_sym if params['type'].instance_of? String
20
21
  c = @@subclasses[params['type']]
21
22
  if c
22
23
  c.new(params, context, caller)
@@ -0,0 +1,42 @@
1
+ module Docman
2
+ class GitRepoProvider < Docman::Command
3
+
4
+ attr_reader :version
5
+
6
+ register_command :git_repo_provider
7
+
8
+ def validate_command
9
+ raise "Please provide 'context'" if @context.nil?
10
+ raise "Context should be of type 'Info'" unless @context.is_a? Docman::Info
11
+ end
12
+
13
+ def execute
14
+ @execute_result = get_content
15
+ # No commit hash for 'root' as it will be changed later
16
+ @version = @context['type'] == 'root' ? @context['build_path'] : @execute_result
17
+ end
18
+
19
+ def changed?
20
+ stored_version = @context.stored_version['result']
21
+ @last_version = GitUtil.last_revision(self['target_path'])
22
+ # TODO: diff with remote instead of get
23
+ v = version(true)
24
+ stored_version != v
25
+ end
26
+
27
+ def get_content
28
+ GitUtil.get(@context['repo'], self['target_path'], @context.version_type, @context.version, true, 1)
29
+ end
30
+
31
+ def changed_from_last_version?
32
+ @last_version != @version
33
+ end
34
+
35
+ def version(remote = false)
36
+ # branch = remote ? "origin/#{@context.version}" : nil
37
+ # @context['type'] == 'root' ? @context['build_path'] : GitUtil.last_revision(self['target_path'], branch)
38
+ @context['type'] == 'root' ? @context['build_path'] : get_content
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,60 @@
1
+ module Docman
2
+ class NexusProvider < Docman::Command
3
+
4
+ register_command :nexus_provider
5
+
6
+ def validate_command
7
+ raise "Please provide 'context'" if @context.nil?
8
+ raise "Context should be of type 'Info'" unless @context.is_a? Docman::Info
9
+ raise "Please provide 'artifact_aid'" if @context['artifact_aid'].nil?
10
+ raise "Please provide 'artifact_gid'" if @context['artifact_gid'].nil?
11
+ raise "Please provide 'artifact_version'" if @context['artifact_version'].nil?
12
+ end
13
+
14
+ def execute
15
+ # TODO: refactor it.
16
+ nexus_address = '138.68.81.158:8081'
17
+ a = @context['artifact_aid']
18
+ g = @context['artifact_gid']
19
+ v = @context['artifact_version']
20
+ r = 'releases'
21
+ e = 'tar.gz'
22
+ artifact_file = "#{a}-#{v}.#{e}"
23
+
24
+ @context['version_type'] = 'nexus_artifact'
25
+ @context['version'] = v
26
+
27
+ FileUtils.mkdir_p(self['target_path'])
28
+ Dir.chdir self['target_path']
29
+
30
+ # TODO: refactor cmd execution.
31
+ cmd = "wget -O #{artifact_file} \"http://#{nexus_address}/nexus/service/local/artifact/maven/content?a=#{a}&g=#{g}&v=#{v}&r=#{r}&e=#{e}\""
32
+
33
+ `#{cmd}`
34
+
35
+ if $?.exitstatus > 0
36
+ raise "Artifact retrieving has been failed: #{cmd}"
37
+ end
38
+
39
+ cmd ="tar --strip-components=1 -xzf #{artifact_file}"
40
+ `#{cmd}`
41
+
42
+ if $?.exitstatus > 0
43
+ raise "Artifact unpack has been failed: #{cmd}"
44
+ end
45
+
46
+ cmd ="rm -f #{artifact_file}"
47
+ `#{cmd}`
48
+ @execute_result = artifact_file
49
+ end
50
+
51
+ def changed?
52
+ true
53
+ end
54
+
55
+ def changed_from_last_version?
56
+ true
57
+ end
58
+
59
+ end
60
+ end
@@ -15,27 +15,30 @@ module Docman
15
15
 
16
16
  def execute
17
17
  with_logging('yaml_execute') do
18
+ Dir.chdir @context['full_build_path']
18
19
  if self['environments'].nil? || self['environments'] == 'all' || self['environments'].include?(@context.environment_name)
19
- commands = nil
20
- if self['source_type'] == 'file'
21
- yaml_file_name = self['yaml_file_name'].nil? ? '.build.yml' : self['yaml_file_name']
22
- build_file = File.join(@context['full_build_path'], yaml_file_name)
23
- if File.file? build_file
24
- build_file_yaml = YAML::load_file(build_file)
25
- commands = build_file_yaml[self['stage']]
26
- source = yaml_file_name
20
+ if self['providers'].nil? || self['providers'] == 'all' || self['providers'].include?(@context['provider'])
21
+ commands = nil
22
+ if self['source_type'] == 'file'
23
+ yaml_file_name = self['yaml_file_name'].nil? ? '.build.yml' : self['yaml_file_name']
24
+ build_file = File.join(@context['full_build_path'], yaml_file_name)
25
+ if File.file? build_file
26
+ build_file_yaml = YAML::load_file(build_file)
27
+ commands = build_file_yaml[self['stage']]
28
+ source = yaml_file_name
29
+ end
27
30
  end
28
- end
29
- if self['source_type'] == 'inline'
30
- commands = self['commands']
31
- source = 'inline'
32
- end
33
- unless commands.nil?
34
- commands.each do |cmd|
35
- logger.info "Execute from #{source}: #{cmd}"
36
- logger.info `#{cmd}`
37
- if $?.exitstatus > 0
38
- raise "Command #{cmd} was failed"
31
+ if self['source_type'] == 'inline'
32
+ commands = self['commands']
33
+ source = 'inline'
34
+ end
35
+ unless commands.nil?
36
+ commands.each do |cmd|
37
+ logger.info "Execute from #{source}: #{cmd}"
38
+ logger.info `#{cmd}`
39
+ if $?.exitstatus > 0
40
+ raise "Command #{cmd} was failed"
41
+ end
39
42
  end
40
43
  end
41
44
  end
@@ -1,15 +1,19 @@
1
1
  require 'singleton'
2
2
  require 'hash_deep_merge'
3
3
  require 'digest/md5'
4
+ require 'json'
4
5
 
5
6
  module Docman
6
7
  class Config < Hash
7
8
 
8
9
  attr_reader :unmutable_config
9
10
 
11
+ @loaded_scenario_sources
12
+
10
13
  def initialize(file)
11
14
  super
12
15
  @config = YAML::load_file(file)
16
+ @loaded_scenario_sources = {}
13
17
  assign_to_self
14
18
  end
15
19
 
@@ -20,13 +24,77 @@ module Docman
20
24
  @unmutable_config = Marshal::load(Marshal.dump(@config))
21
25
  end
22
26
 
23
- def merge_config_from_file(file)
24
- config = YAML::load_file(file)
25
- @config.deep_merge(config)
26
- @config['version'] = config['version'].nil? ? 1 : config['version']
27
+ def merge_config_from_file(docroot_config_dir, config_file, options = nil)
28
+ file = File.join(docroot_config_dir, config_file)
29
+ if File.file?(file)
30
+ config = YAML::load_file(file)
31
+ if config['scenarios']
32
+ scenarios_path = File.join(docroot_config_dir, '/../', 'scenarios')
33
+ `rm -fR #{scenarios_path}` if File.directory? scenarios_path
34
+ `mkdir -p scenarios_path`
35
+ unless config['scenarioSources']
36
+ config['scenarioSources'] = {}
37
+ end
38
+ config['scenarioSources']['root_config'] = {}
39
+ config['scenarioSources']['root_config']['dir'] = docroot_config_dir
40
+ @loaded_scenario_sources['root_config'] = config['scenarioSources']['root_config']
41
+ config = merge_scenarios_configs(config, {}, scenarios_path, 'root_config')
42
+ end
43
+ end
44
+ unless config.nil?
45
+ unless config['override_docman_default'].nil?
46
+ self.clear
47
+ @config = config
48
+ else
49
+ @config.deep_merge!(config)
50
+ end
51
+ @config['version'] = config['version'].nil? ? 1 : config['version']
52
+ end
53
+
27
54
  assign_to_self
28
55
  end
29
56
 
57
+ def merge_scenarios_configs(config, temp_config = {}, scenarios_path, current_scenario_source_name)
58
+ temp_config.deep_merge!(config)
59
+ scenarios_config = {}
60
+ unless config['scenarios'].nil?
61
+ config['scenarios'].each do |s|
62
+ scenario = {}
63
+ if s.is_a? String
64
+ values = s.split(':')
65
+ if values.size() > 1
66
+ scenario_source_name = values[0]
67
+ scenario_name = values[1]
68
+ else
69
+ scenario_source_name = current_scenario_source_name
70
+ scenario_name = values[0]
71
+ end
72
+ scenario['name'] = scenario_name
73
+ if temp_config['scenarioSources'].key? scenario_source_name
74
+ temp_config['scenarioSources'][scenario_source_name]['dir']
75
+ scenario_source_path = temp_config['scenarioSources'][scenario_source_name]['dir'] ? temp_config['scenarioSources'][scenario_source_name]['dir'] : File.join(scenarios_path, scenario_source_name)
76
+ if @loaded_scenario_sources.key? scenario_source_name
77
+ scenario['source'] = @loaded_scenario_sources[scenario_source_name]
78
+ else
79
+ `rm -fR #{scenario_source_path}` if File.directory? scenario_source_path
80
+ scenario['source'] = temp_config['scenarioSources'][scenario_source_name]
81
+ scenario['source']['ref'] = scenario['source']['ref'] ? scenario['source']['ref'] : 'master'
82
+ GitUtil.clone_repo(scenario['source']['repo'], scenario_source_path, 'branch', scenario['source']['ref'], true, 1)
83
+ @loaded_scenario_sources[scenario_source_name] = scenario['source']
84
+ end
85
+ scenario_config_file = File.join(scenario_source_path, 'scenarios', scenario['name'], 'config.yaml')
86
+ if File.file? scenario_config_file
87
+ scenario_config = merge_scenarios_configs(YAML::load_file(scenario_config_file), temp_config, scenarios_path, scenario_source_name)
88
+ scenarios_config.deep_merge!(scenario_config)
89
+ puts "Loaded scenario #{scenario['name']} from source #{scenario_source_name}"
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ scenarios_config.deep_merge!(config)
96
+ end
97
+
30
98
  def config_hash
31
99
  Digest::MD5.hexdigest(Marshal::dump(@unmutable_config))
32
100
  end
@@ -171,12 +171,12 @@ module Docman
171
171
  @build_results[info['name']] = build_result ? build_result : 'Not builded'
172
172
  @versions[info['name']] = builder.version
173
173
  @builded << info['name']
174
- if (build_result)
175
- info['children'].sort_by!{|a| a['order']}
176
- info['children'].each do |child|
177
- build_recursive(child)
178
- end
174
+ # if (build_result)
175
+ info['children'].sort_by!{|a| a['order']}
176
+ info['children'].each do |child|
177
+ build_recursive(child)
179
178
  end
179
+ # end
180
180
  end
181
181
 
182
182
  # TODO: need to refactor.
@@ -7,23 +7,90 @@ module Docman
7
7
 
8
8
  attr_reader :structure, :deploy_target, :docroot_dir, :root, :raw_infos
9
9
 
10
- def initialize(docroot_dir, deploy_target = nil)
10
+ def initialize(docroot_dir, deploy_target_name = nil, options = nil)
11
+ @override = {}
12
+ if options && options['config']
13
+ @override = JSON.parse(options['config'])
14
+ end
11
15
  @docroot_dir = docroot_dir
12
- @deploy_target = deploy_target
16
+ #@deploy_target = deploy_target
13
17
  @docroot_config_dir = File.join(docroot_dir, 'config')
18
+
19
+ Dir.chdir @docroot_config_dir
14
20
  update(' origin master')
15
21
  if File.file? File.join(@docroot_config_dir, 'config.yaml')
16
- Docman::Application.instance.config.merge_config_from_file(File.join(@docroot_config_dir, 'config.yaml'))
22
+ Docman::Application.instance.config.merge_config_from_file(@docroot_config_dir, 'config.yaml', options)
17
23
  end
24
+
25
+ if deploy_target_name
26
+ @deploy_target = Application.instance.config['deploy_targets'][deploy_target_name]
27
+ raise "Wrong deploy target: #{deploy_target_name}" if @deploy_target.nil?
28
+ @deploy_target['name'] = deploy_target_name
29
+ end
30
+
18
31
  @names = {}
19
32
  @raw_infos = {}
20
- @structure = structure_build File.join(@docroot_config_dir, 'master')
33
+ master_file = File.join(@docroot_config_dir, 'master')
34
+ if File.directory? master_file
35
+ @structure = structure_build(File.join(@docroot_config_dir, 'master'))
36
+ else
37
+ @structure = structure_build_from_config_file(File.join(@docroot_config_dir, 'master'))
38
+ end
21
39
  end
22
40
 
23
41
  def update(options = '')
42
+ GitUtil.exec("reset --hard", false)
24
43
  GitUtil.update @docroot_config_dir, options
25
44
  end
26
45
 
46
+ def structure_build_from_config_file(path, prefix = '', parent = nil, parent_key = 'master')
47
+ config = Docman::Application.instance.config
48
+ return if config['components'][parent_key].nil?
49
+ children = []
50
+
51
+ info = config['components'][parent_key]
52
+ @raw_infos[parent_key] = info
53
+
54
+ unless info['status'].nil?
55
+ return if info['status'] == 'disabled'
56
+ end
57
+
58
+ name = parent_key
59
+ prefix = prefix.size > 0 ? File.join(prefix, name) : name
60
+ info['full_path'] = path
61
+ info['docroot_config'] = self
62
+ info['build_path'] = prefix
63
+ info['full_build_path'] = File.join(@docroot_dir, prefix)
64
+ info['temp_path'] = File.join(@docroot_dir, 'tmp', info['build_path'])
65
+ info['states_path'] = File.join(@docroot_dir, 'states', info['build_path'])
66
+ info['name'] = name
67
+ info['parent'] = parent
68
+ info['order'] = info.has_key?('order') ? info['order'] : 10
69
+ info['children'] = children
70
+
71
+ if @override['projects'] && @override['projects'].key?(info['name'])
72
+ info.merge! @override['projects'][info['name']]
73
+ end
74
+
75
+ i = Docman::Info.new(info)
76
+ @root = i if parent.nil?
77
+ i['root'] = @root
78
+
79
+ @names[name.to_s] = i
80
+
81
+ # Dir.foreach(path) do |entry|
82
+ # next if (entry == '..' || entry == '.')
83
+ # full_path = File.join(path, entry)
84
+ # if File.directory?(full_path)
85
+ # dir_hash = structure_build(full_path, prefix, i)
86
+ # unless dir_hash == nil
87
+ # children << dir_hash
88
+ # end
89
+ # end
90
+ # end
91
+ i
92
+ end
93
+
27
94
  def structure_build(path, prefix = '', parent = nil)
28
95
  return unless File.file? File.join(path, 'info.yaml')
29
96
 
@@ -46,6 +113,10 @@ module Docman
46
113
  info['order'] = info.has_key?('order') ? info['order'] : 10
47
114
  info['children'] = children
48
115
 
116
+ if @override['projects'] && @override['projects'].key?(info['name'])
117
+ info.merge! @override['projects'][info['name']]
118
+ end
119
+
49
120
  i = Docman::Info.new(info)
50
121
  @root = i if parent.nil?
51
122
  i['root'] = @root
@@ -8,7 +8,7 @@ module Docman
8
8
  @git = ENV.has_key?('GIT_CMD') ? ENV['GIT_CMD'] : 'git'
9
9
 
10
10
  def self.exec(command, show_result = true)
11
- @logger.info "#{@git} #{command}"
11
+ @logger.info "#{@git} #{command} in #{Dir.pwd}"
12
12
  result = `#{@git} #{command}`
13
13
  #result = `#{@git} #{command}`.delete!("\n")
14
14
  @logger.info result if show_result and result
@@ -33,13 +33,13 @@ module Docman
33
33
  if File.directory? path and File.directory?(File.join(path, '.git'))
34
34
  Dir.chdir path
35
35
  self.reset_repo(path) #if self.repo_changed?(path)
36
+ exec 'fetch --tags'
36
37
  if type == 'branch'
37
- exec "fetch"
38
+ #exec "fetch"
38
39
  exec "checkout #{version}"
39
40
  exec "pull origin #{version}"
40
41
  end
41
42
  if type == 'tag'
42
- exec 'fetch --tags'
43
43
  exec "checkout tags/#{version}"
44
44
  end
45
45
  else
@@ -63,11 +63,11 @@ module Docman
63
63
  exec("clone #{single_branch} #{depth} #{repo} #{path}")
64
64
  end
65
65
 
66
- def self.last_revision(path = nil)
66
+ def self.last_revision(path = nil, branch = 'HEAD')
67
67
  result = nil
68
68
  if self.repo? path
69
69
  Dir.chdir path unless path.nil?
70
- result = `git rev-parse --short HEAD`
70
+ result = `git rev-parse --short #{branch}`
71
71
  result.delete!("\n")
72
72
  end
73
73
  result
@@ -19,7 +19,7 @@ module Docman
19
19
  unless self['docroot_config'].deploy_target.nil?
20
20
  if self.has_key? 'states'
21
21
  self['states'].each_pair do |name, state|
22
- if state.has_key?('source')
22
+ if state.has_key?('source') and (not state.has_key?('type') or state.has_key['type'] == 'external_source')
23
23
  if state['source']['type'] == :retrieve_from_repo
24
24
  @state_name = name
25
25
  repo = state['source']['repo'] == :project_repo ? self['repo'] : state['source']['repo']
@@ -46,7 +46,8 @@ module Docman
46
46
  end
47
47
 
48
48
  def version_type(options = {})
49
- state(options).nil? ? nil : state(options)['type']
49
+ return self['version_type'] if self.key? 'version_type'
50
+ return state(options).nil? ? nil : state(options)['type']
50
51
  end
51
52
 
52
53
  def describe(type = 'short')
@@ -59,11 +60,18 @@ module Docman
59
60
  to_save['version_type'] = self.version_type unless self.version_type.nil?
60
61
  to_save['version'] = self.version unless self.version.nil?
61
62
  to_save['result'] = result
63
+ to_save['provider'] = self['provider'] unless self['provider'].nil?
62
64
  to_save['type'] = self['type']
63
65
  to_save['build_type'] = self['build_type']
64
- if environment_name() != 'local'
65
- File.open(File.join(self['full_build_path'], 'info.yaml'), 'w') {|f| f.write to_save.to_yaml}
66
+ FileUtils::mkdir_p info_dir unless File.directory? info_dir
67
+
68
+ # Create local git ignored .docman dir for info file
69
+ if environment_name() == 'local'
70
+ gitignore_file = File.join(info_dir, '.gitignore')
71
+ File.open(gitignore_file, 'w') {|f| f.write '*'} unless File.file? gitignore_file
66
72
  end
73
+ File.open(info_file, 'w') {|f| f.write to_save.to_yaml}
74
+ #end
67
75
  to_save
68
76
  end
69
77
 
@@ -112,11 +120,25 @@ module Docman
112
120
  false
113
121
  end
114
122
 
115
- #TODO: check if info.yaml needed for local state
116
123
  def stored_version
117
- info_filename = File.join(self['full_build_path'], 'info.yaml')
118
- return false unless File.file?(info_filename)
119
- YAML::load_file(info_filename)
124
+ info_file_yaml
125
+ end
126
+
127
+ def info_dir(path = nil)
128
+ File.join(
129
+ path.nil? ? self['full_build_path'] : path,
130
+ environment_name() == 'local' ? '.docman' : ''
131
+ )
132
+ end
133
+
134
+ # TODO: make default with lazy initialize
135
+ def info_file(path = nil)
136
+ File.join(info_dir(path), 'info.yaml')
137
+ end
138
+
139
+ def info_file_yaml
140
+ file = info_file
141
+ File.file?(file) ? YAML::load_file(file) : nil
120
142
  end
121
143
 
122
144
  def state(options = {})
@@ -1,3 +1,3 @@
1
1
  module Docman
2
- VERSION = "0.0.80"
2
+ VERSION = "0.0.81"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.80
4
+ version: 0.0.81
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Tolstikov
@@ -136,6 +136,34 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: io-console
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: json
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  description:
140
168
  email:
141
169
  - atolstikov@adyax.com
@@ -172,11 +200,11 @@ files:
172
200
  - lib/application.rb
173
201
  - lib/docman/builders/builder.rb
174
202
  - lib/docman/builders/dir_builder.rb
175
- - lib/docman/builders/drupal_drush_builder.rb
176
- - lib/docman/builders/git_direct_builder.rb
203
+ - lib/docman/builders/direct_builder.rb
204
+ - lib/docman/builders/git_provider_builder.rb
177
205
  - lib/docman/builders/git_root_chain_builder.rb
178
206
  - lib/docman/builders/git_strip_builder.rb
179
- - lib/docman/builders/symlink_builder.rb
207
+ - lib/docman/builders/provider_builder.rb
180
208
  - lib/docman/cli.rb
181
209
  - lib/docman/commands/clean_changed_cmd.rb
182
210
  - lib/docman/commands/command.rb
@@ -184,8 +212,9 @@ files:
184
212
  - lib/docman/commands/create_symlink_cmd.rb
185
213
  - lib/docman/commands/execute_script_cmd.rb
186
214
  - lib/docman/commands/git_commit_cmd.rb
187
- - lib/docman/commands/git_copy_repo_content_cmd.rb
188
215
  - lib/docman/commands/git_pull_cmd.rb
216
+ - lib/docman/commands/git_repo_provider_cmd.rb
217
+ - lib/docman/commands/nexus_provider_cmd.rb
189
218
  - lib/docman/commands/ssh_target_checker.rb
190
219
  - lib/docman/commands/target_checker.rb
191
220
  - lib/docman/commands/yaml_execute_cmd.rb
@@ -195,7 +224,6 @@ files:
195
224
  - lib/docman/deployers/deployer.rb
196
225
  - lib/docman/deployers/git_deployer.rb
197
226
  - lib/docman/docroot_config.rb
198
- - lib/docman/docroot_controller.rb
199
227
  - lib/docman/exceptions/command_validation_error.rb
200
228
  - lib/docman/exceptions/no_changes_error.rb
201
229
  - lib/docman/exec.rb
@@ -1,27 +0,0 @@
1
- require 'yaml'
2
-
3
- module Docman
4
- module Builders
5
- class DrupalDrushBuilder < Builder
6
-
7
- register_builder :drupal_drush_builder
8
-
9
- def execute
10
- return if @build_mode == :none
11
- #return unless @context.need_rebuild?
12
- puts 'Download drupal through drush'
13
- FileUtils.mkdir_p(@context['temp_path'])
14
- Dir.chdir @context['temp_path']
15
- `drush dl drupal-#{@context.version} --yes`
16
- FileUtils.mkdir_p(@context['full_build_path'])
17
- FileUtils.cp_r(Dir["#{@context['temp_path']}/drupal-#{@context.version}/."], @context['full_build_path'])
18
- @context.version
19
- end
20
-
21
- def version
22
- @context.version
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,30 +0,0 @@
1
- module Docman
2
- module Builders
3
- class GitDirectBuilder < Builder
4
-
5
- register_builder :git_direct_builder
6
-
7
- def execute
8
- execute_result = GitUtil.get(@context['repo'], @context['full_build_path'], @context.version_type, @context.version)
9
- # No commit hash for 'root' as it will be changed later
10
- @version = @context['type'] == 'root' ? @context['build_path'] : execute_result
11
- @last_revision != @version ? @version : false
12
- end
13
-
14
- def changed?
15
- stored_version = @context.stored_version['result']
16
- if @context['type'] == 'root_chain'
17
- repo_path = @context['temp_path']
18
- else
19
- repo_path = @context['full_build_path']
20
- end
21
-
22
- @last_revision = GitUtil.last_revision(repo_path)
23
- # No commit hash for 'root' as it will be changed later
24
- @version = @context['type'] == 'root' ? @context['build_path'] : GitUtil.get(@context['repo'], repo_path, @context.version_type, @context.version)
25
- stored_version != @version
26
- end
27
-
28
- end
29
- end
30
- end
@@ -1,24 +0,0 @@
1
- module Docman
2
- module Builders
3
- class SymlinkBuilder < Builder
4
-
5
- register_builder :symlink_builder
6
-
7
- def execute
8
- if File.directory? @context['full_build_path']
9
- log("Removed dir: #{@context['full_build_path']} because directory is a directory")
10
- FileUtils.rm_r(@context['full_build_path'])
11
- end
12
- Dir.chdir Pathname(@context['full_build_path']).dirname
13
- `ln -f -s #{@context['target_path']} #{@context['name']}`
14
- log("Created symlink: #{@context['full_build_path']}")
15
- @context['build_path']
16
- end
17
-
18
- def version
19
- @context['build_path']
20
- end
21
-
22
- end
23
- end
24
- end
@@ -1,23 +0,0 @@
1
- module Docman
2
- class GitCopyRepoContent < Docman::Command
3
-
4
- register_command :git_copy_repo_content
5
-
6
- def validate_command
7
- raise "Please provide 'context'" if @context.nil?
8
- raise "Context should be of type 'Info'" unless @context.is_a? Docman::Info
9
- end
10
-
11
- def execute
12
- if (self['remove_target'])
13
- FileUtils.rm_r(Dir["#{@context['full_build_path']}/*"]) if File.directory? @context['full_build_path']
14
- end
15
- FileUtils.rm_r @context['temp_path'] if @context.need_rebuild? and File.directory? @context['temp_path']
16
- @version = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version, nil, nil)
17
- # FileUtils.rm_r(File.join(@context['temp_path'], '.git')) if File.directory?(File.join(@context['temp_path'], '.git'))
18
- FileUtils.mkdir_p(@context['full_build_path'])
19
- `rsync -a --exclude '.git' #{@context['temp_path']}/. #{@context['full_build_path']}`
20
- @version
21
- end
22
- end
23
- end
@@ -1,47 +0,0 @@
1
- require 'docman/builders/builder'
2
- require 'docman/builders/dir_builder'
3
- require 'docman/builders/git_direct_builder'
4
- require 'docman/builders/git_root_chain_builder'
5
- require 'docman/builders/git_strip_builder'
6
- require 'docman/builders/drupal_drush_builder'
7
- require 'docman/deployers/deployer'
8
- require 'docman/deployers/git_deployer'
9
- require 'docman/deployers/common_deployer'
10
-
11
- # TODO: make universal logging class.
12
-
13
- module Docman
14
- class DocrootController
15
-
16
- attr_reader :docroot_dir, :docroot_config
17
-
18
- def initialize(docroot_dir, deploy_target_name, options = {})
19
- @deploy_target = Docman::Application.instance.config['deploy_targets'][deploy_target_name]
20
- @deploy_target_name = deploy_target_name
21
- Docman::Application.instance.deploy_target = @deploy_target
22
- docroot_config = DocrootConfig.new(docroot_dir, @deploy_target)
23
- @docroot_dir = docroot_dir
24
- @docroot_config = docroot_config
25
- end
26
-
27
- def build(state_name)
28
- execute(state_name)
29
- end
30
-
31
- def deploy(name, type, version)
32
- @docroot_config.states_dependin_on(name, version).keys.each do |state_name|
33
- execute(state_name, name)
34
- end
35
- end
36
-
37
- def execute(state, name = nil)
38
- #Docman::Application.instance.config.environment(state_name, @deploy_target_name)
39
- params = @deploy_target
40
- params['state'] = state
41
- params['name'] = name
42
- Docman::Deployers::Deployer.create(params, self).perform
43
- end
44
-
45
- end
46
-
47
- end