docman 0.0.5 → 0.0.6

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -4
  3. data/bin/functions.sh +265 -0
  4. data/config/config.yaml +36 -39
  5. data/config/cucumber.yml +2 -0
  6. data/docman.gemspec +3 -0
  7. data/features/acquia/acquia.feature +65 -0
  8. data/features/init/init.feature +27 -0
  9. data/features/local/local.feature +88 -0
  10. data/features/local/local_deploy.feature +6 -0
  11. data/features/support/env.rb +1 -1
  12. data/lib/application.rb +48 -11
  13. data/lib/docman/builders/builder.rb +34 -34
  14. data/lib/docman/builders/dir_builder.rb +21 -0
  15. data/lib/docman/builders/drupal_drush_builder.rb +22 -0
  16. data/lib/docman/builders/git_direct_builder.rb +20 -0
  17. data/lib/docman/builders/git_strip_builder.rb +27 -0
  18. data/lib/docman/cli.rb +3 -0
  19. data/lib/docman/commands/clean_changed_cmd.rb +23 -0
  20. data/lib/docman/commands/command.rb +137 -0
  21. data/lib/docman/commands/composite_command.rb +28 -0
  22. data/lib/docman/commands/create_symlink_cmd.rb +24 -0
  23. data/lib/docman/commands/execute_script_cmd.rb +40 -0
  24. data/lib/docman/commands/git_commit_cmd.rb +25 -0
  25. data/lib/docman/commands/ssh_target_checker.rb +28 -0
  26. data/lib/docman/commands/target_checker.rb +22 -0
  27. data/lib/docman/config.rb +31 -0
  28. data/lib/docman/context.rb +11 -0
  29. data/lib/docman/deployers/common_deployer.rb +2 -1
  30. data/lib/docman/deployers/deployer.rb +121 -17
  31. data/lib/docman/deployers/git_deployer.rb +6 -3
  32. data/lib/docman/docroot_config.rb +15 -17
  33. data/lib/docman/docroot_controller.rb +23 -35
  34. data/lib/docman/exceptions/command_validation_error.rb +5 -0
  35. data/lib/docman/exceptions/no_changes_error.rb +5 -0
  36. data/lib/docman/exec.rb +1 -1
  37. data/lib/docman/git_util.rb +43 -15
  38. data/lib/docman/info.rb +63 -9
  39. data/lib/docman/logging.rb +41 -0
  40. data/lib/docman/version.rb +1 -1
  41. metadata +72 -8
  42. data/features/local.feature +0 -60
  43. data/features/local_deploy.feature +0 -37
  44. data/lib/docman/builders/common_builder.rb +0 -16
  45. data/lib/docman/builders/git_builder.rb +0 -26
@@ -4,10 +4,13 @@ module Docman
4
4
 
5
5
  register_deployer :git_deployer
6
6
 
7
- def push(info, state_name)
8
- version = info['states'][state_name]['version']
9
- GitUtil.push(info['full_build_path'], version)
7
+ def push
8
+ root = @docroot_config.root
9
+ root.state = self['state']
10
+ GitUtil.commit(root['full_build_path'], root['full_build_path'], 'Updated version.yaml')
11
+ GitUtil.push(root['full_build_path'], root.version)
10
12
  end
13
+
11
14
  end
12
15
  end
13
16
  end
@@ -5,14 +5,17 @@ module Docman
5
5
 
6
6
  class DocrootConfig
7
7
 
8
- attr_reader :structure, :deploy_target
9
-
8
+ attr_reader :structure, :deploy_target, :docroot_dir, :root
10
9
  def initialize(docroot_dir, deploy_target)
11
10
  @docroot_dir = docroot_dir
12
11
  @deploy_target = deploy_target
13
12
  @docroot_config_dir = File.join(docroot_dir, 'config')
14
13
  update
14
+ if File.file? File.join(@docroot_config_dir, 'config.yaml')
15
+ Docman::Application.instance.config.merge_config_from_file(File.join(@docroot_config_dir, 'config.yaml'))
16
+ end
15
17
  @names = {}
18
+ @raw_infos = []
16
19
  @structure = structure_build File.join(@docroot_config_dir, 'master')
17
20
  end
18
21
 
@@ -25,6 +28,10 @@ module Docman
25
28
 
26
29
  children = []
27
30
  info = YAML::load_file(File.join(path, 'info.yaml'))
31
+ @raw_infos << YAML::load_file(File.join(path, 'info.yaml'))
32
+ unless info['status'].nil?
33
+ return if info['status'] == 'disabled'
34
+ end
28
35
  name = File.basename path
29
36
  prefix = prefix.size > 0 ? File.join(prefix, name) : name
30
37
  info['full_path'] = path
@@ -37,11 +44,11 @@ module Docman
37
44
  info['children'] = children
38
45
 
39
46
  i = Docman::Info.new(info)
47
+ @root = i if parent.nil?
48
+ i['root'] = @root
40
49
 
41
50
  @names[name.to_s] = i
42
51
 
43
- data = [i]
44
- # data[:children] = children
45
52
  Dir.foreach(path) do |entry|
46
53
  next if (entry == '..' || entry == '.')
47
54
  full_path = File.join(path, entry)
@@ -55,7 +62,6 @@ module Docman
55
62
  i
56
63
  end
57
64
 
58
-
59
65
  def chain(info)
60
66
  chain = {}
61
67
  chain[info['name']] = info
@@ -66,18 +72,6 @@ module Docman
66
72
  Hash[chain.to_a.reverse!]
67
73
  end
68
74
 
69
- def root(info)
70
- chain(info).each do |name, item|
71
- if item['type'] == 'root'
72
- return item
73
- end
74
- end
75
- end
76
-
77
- def root_dir
78
- @structure[:data]
79
- end
80
-
81
75
  def info_by(name)
82
76
  @names[name]
83
77
  end
@@ -90,5 +84,9 @@ module Docman
90
84
  states
91
85
  end
92
86
 
87
+ def config_hash
88
+ Digest::MD5.hexdigest(Marshal::dump(@raw_infos))
89
+ end
90
+
93
91
  end
94
92
  end
@@ -1,62 +1,50 @@
1
1
  require 'docman/builders/builder'
2
- require 'docman/builders/common_builder'
3
- require 'docman/builders/git_builder'
2
+ require 'docman/builders/dir_builder'
3
+ require 'docman/builders/git_direct_builder'
4
+ require 'docman/builders/git_strip_builder'
5
+ require 'docman/builders/drupal_drush_builder'
4
6
  require 'docman/deployers/deployer'
5
7
  require 'docman/deployers/git_deployer'
6
8
  require 'docman/deployers/common_deployer'
9
+ require 'docman/command'
10
+ require 'docman/composite_command'
11
+ require 'docman/builders/commands/create_symlink_cmd'
12
+ require 'docman/builders/commands/execute_script_cmd'
13
+ require 'docman/builders/commands/clean_changed_cmd'
14
+ require 'docman/builders/commands/git_commit_cmd'
7
15
 
8
16
  # TODO: make universal logging class.
9
17
 
10
18
  module Docman
11
19
  class DocrootController
12
20
 
13
- attr_reader :docroot_dir
21
+ attr_reader :docroot_dir, :docroot_config
14
22
 
15
23
  def initialize(docroot_dir, deploy_target_name, options = {})
16
24
  @deploy_target = Docman::Application.instance.config['deploy_targets'][deploy_target_name]
25
+ @deploy_target_name = deploy_target_name
17
26
  Docman::Application.instance.deploy_target = @deploy_target
18
27
  docroot_config = DocrootConfig.new(docroot_dir, @deploy_target)
19
- @deployer = Docman::Deployers::Deployer.create(@deploy_target['handler'], @deploy_target)
20
28
  @docroot_dir = docroot_dir
21
29
  @docroot_config = docroot_config
22
30
  end
23
31
 
24
- def deploy(name, type, version)
25
- puts "Deploy #{name}, type: #{type}"
26
- @docroot_config.states_dependin_on(name, version).each do |state_name, state|
27
- deploy_dir_chain(state_name, @docroot_config.info_by(name))
28
- @deployer.push(@docroot_config.root_dir, state_name)
29
- end
32
+ def build(state_name)
33
+ execute(state_name)
30
34
  end
31
35
 
32
- def build(state)
33
- build_recursive(state)
34
- @deployer.push(@docroot_config.root_dir, state)
35
- end
36
-
37
- def build_recursive(state, info = nil)
38
- info = info ? info : @docroot_config.structure
39
- build_dir(state, info)
40
-
41
- info['children'].each do |child|
42
- build_recursive(state, child)
43
- end
44
- end
45
-
46
- def deploy_dir_chain(state, info)
47
- @docroot_config.chain(info).each do |name, item|
48
- if item.need_rebuild?
49
- build_recursive(state, item)
50
- return
51
- elsif
52
- build_dir(state, item)
53
- end
36
+ def deploy(name, type, version)
37
+ @docroot_config.states_dependin_on(name, version).keys.each do |state_name|
38
+ execute(state_name, name)
54
39
  end
55
40
  end
56
41
 
57
- def build_dir(state, info)
58
- info.state = state
59
- @deployer.build(@docroot_config.root(info), info)
42
+ def execute(state, name = nil)
43
+ #Docman::Application.instance.config.environment(state_name, @deploy_target_name)
44
+ params = @deploy_target
45
+ params['state'] = state
46
+ params['name'] = name
47
+ Docman::Deployers::Deployer.create(params, self).perform
60
48
  end
61
49
 
62
50
  end
@@ -0,0 +1,5 @@
1
+ module Docman
2
+ class CommandValidationError < StandardError
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Docman
2
+ class NoChangesError < StandardError
3
+
4
+ end
5
+ end
data/lib/docman/exec.rb CHANGED
@@ -2,7 +2,7 @@ module Docman
2
2
 
3
3
  class Exec
4
4
 
5
- def Exec.do(cmd)
5
+ def Exec.do(cmd, output = false)
6
6
  `#{cmd}`
7
7
  $?.exitstatus == 0
8
8
  end
@@ -1,45 +1,73 @@
1
+ require 'logger'
2
+
1
3
  module Docman
2
4
 
3
- class GitUtil
5
+ module GitUtil
6
+
7
+ @logger = Logger.new(STDOUT)
8
+
9
+ def self.exec(command)
10
+ @logger.info command
11
+ @logger.info `#{command}`.delete!("\n")
12
+ end
4
13
 
5
14
  def self.get(repo, path, type, version)
6
- if File.directory? path
15
+ if File.directory? path and File.directory?(File.join(path, '.git'))
7
16
  Dir.chdir path
8
- `git checkout #{version} && git pull origin #{version}` if type == 'branch'
17
+ if type == 'branch'
18
+ exec "git checkout #{version}"
19
+ exec "git pull origin #{version}"
20
+ end
9
21
  if type == 'tag'
10
- `git fetch --tags`
11
- `git checkout "tags/#{version}"`
22
+ exec "git fetch --tags"
23
+ exec "git checkout tags/#{version}"
12
24
  end
13
25
  else
14
- `git clone #{repo} #{path}`
26
+ FileUtils.rm_rf path if File.directory? path
27
+ exec "git clone #{repo} #{path}"
15
28
  Dir.chdir path
16
- `git checkout #{version}`
29
+ exec "git checkout #{version}"
17
30
  end
18
31
  result = `git rev-parse --short HEAD`
32
+ @logger.info "Commit hash: #{result}"
19
33
  result.delete!("\n")
20
34
  end
21
35
 
22
36
  def self.update(path)
23
- `cd #{path} && git pull`
37
+ pull path
24
38
  end
25
39
 
26
40
  def self.commit(root_path, path, message)
27
- if self.repo_changed? path
28
- puts message
29
- Dir.chdir root_path
30
- path.slice! "#{root_path}/"
31
- `git pull`
32
- `git add --all #{path}`
33
- `git commit -m "#{message}"`
41
+ if repo_changed? path
42
+ # puts message
43
+ pull root_path
44
+ exec %Q(git add --all #{path.slice "#{root_path}/"})
45
+ exec %Q(git commit -m "#{message}")
34
46
  end
35
47
  end
36
48
 
49
+ def self.pull(path)
50
+ Dir.chdir path
51
+ exec 'git pull'
52
+ end
53
+
54
+ def self.repo?(path)
55
+ File.directory? File.join(path, '.git')
56
+ end
57
+
37
58
  def self.repo_changed?(path)
38
59
  not Exec.do "#{Application::bin}/dm_repo_clean.sh #{path}"
39
60
  end
40
61
 
62
+ def self.last_commit_hash(path, branch)
63
+ Dir.chdir path
64
+ result = `git rev-parse --short origin/#{branch}`
65
+ result.delete!("\n")
66
+ end
67
+
41
68
  def self.push(root_path, version)
42
69
  Dir.chdir root_path
70
+ `git pull origin #{version}`
43
71
  `git push origin #{version}`
44
72
  end
45
73
  end
data/lib/docman/info.rb CHANGED
@@ -1,12 +1,19 @@
1
+ require 'docman/context'
2
+
1
3
  module Docman
2
4
  class Info < Hash
3
5
 
6
+ include Docman::Context
7
+
8
+ attr_accessor :need_rebuild
9
+
4
10
  def initialize(hash = {})
5
11
  super
6
12
  hash.each_pair do |k, v|
7
13
  self[k] = v
8
14
  end
9
- self['build_type'] = self['docroot_config'].deploy_target['builders'][self['type']]['type']
15
+ self['build_type'] = self['docroot_config'].deploy_target['builders'][self['type']]['handler']
16
+ @need_rebuild = Hash.new
10
17
  end
11
18
 
12
19
  def version
@@ -17,32 +24,79 @@ module Docman
17
24
  self['states'][self['state']].nil? ? nil : self['states'][self['state']]['type']
18
25
  end
19
26
 
27
+ def describe(type = 'short')
28
+ properties_info(%w(name type build_type))
29
+ end
30
+
20
31
  def write_info(result)
21
32
  to_save = {}
22
33
  to_save['state'] = self['state']
23
34
  to_save['version_type'] = self.version_type unless self.version_type.nil?
24
35
  to_save['version'] = self.version unless self.version.nil?
25
- # to_save['ref'] = result
36
+ to_save['result'] = result
26
37
  to_save['type'] = self['type']
27
38
  to_save['build_type'] = self['build_type']
28
39
 
29
40
  File.open(File.join(self['full_build_path'], 'info.yaml'), 'w') {|f| f.write to_save.to_yaml}
41
+ to_save
30
42
  end
31
43
 
32
44
  def need_rebuild?
33
- return TRUE if Docman::Application.instance.options[:force]
34
- return TRUE unless File.directory? self['full_build_path']
35
- info_filename = File.join(self['full_build_path'], 'info.yaml')
36
- return TRUE unless File.file?(info_filename)
37
- version = YAML::load_file(info_filename)
38
- return TRUE if version['type'] != self['type']
39
- return TRUE if version['build_type'] != self['build_type']
45
+ return @need_rebuild[self['state']] if not @need_rebuild.nil? and @need_rebuild.has_key? self['state'] and not @need_rebuild[self['state']].nil?
46
+ @need_rebuild[self['state']] = _need_rebuild?
47
+ if @need_rebuild[self['state']]
48
+ set_rebuild_recursive(self, true)
49
+ end
50
+ @need_rebuild[self['state']]
51
+ end
52
+
53
+ def set_rebuild_recursive(obj, value)
54
+ obj.need_rebuild[self['state']] = value
55
+ if obj.has_key?('children')
56
+ obj['children'].each do |info|
57
+ set_rebuild_recursive(info, value)
58
+ end
59
+ end
60
+ end
61
+
62
+ def _need_rebuild?
63
+ return true if Docman::Application.instance.force?
64
+ return true unless File.directory? self['full_build_path']
65
+ v = stored_version
66
+ return true unless v
67
+ return true if v['type'] != self['type']
68
+ return true if v['build_type'] != self['build_type']
69
+ return true if (not v['version'].nil? and v['version'] != self.version)
70
+ return true if (not v['version_type'].nil? and v['version_type'] != self.version_type)
71
+ unless v['state'].nil?
72
+ return true if v['state'] != self['state']
73
+ end
40
74
  false
41
75
  end
42
76
 
77
+ def stored_version
78
+ info_filename = File.join(self['full_build_path'], 'info.yaml')
79
+ return false unless File.file?(info_filename)
80
+ YAML::load_file(info_filename)
81
+ end
82
+
43
83
  def state=(state)
44
84
  self['state'] = state
45
85
  end
46
86
 
87
+ def disabled?
88
+ unless self['status'].nil?
89
+ return self['status'] == 'disabled'
90
+ end
91
+ false
92
+ end
93
+
94
+ def commands(type, hook)
95
+ if self.has_key? 'actions' and self['actions'].has_key? type and self['actions'][type].has_key? hook
96
+ return self['actions'][type][hook]
97
+ end
98
+ []
99
+ end
100
+
47
101
  end
48
102
  end
@@ -0,0 +1,41 @@
1
+ module Docman
2
+ module Logging
3
+
4
+ def logger
5
+ Logging.logger
6
+ end
7
+
8
+ def self.logger
9
+ @logger ||= Logger.new(STDOUT)
10
+ end
11
+
12
+ def properties_info(properties = [])
13
+ arr = ["name=#{self.class.name}"]
14
+ properties.each do |property|
15
+ if self.is_a? Hash
16
+ arr << "#{property}=#{self[property]}" if self.include?(property)
17
+ else
18
+ arr << "#{property}=#{self.send(property)}" if self.respond_to?(property)
19
+ end
20
+ end
21
+ arr.join(', ')
22
+ end
23
+
24
+ def with_logging(message = nil, type = 'debug')
25
+ # logger.send(type, "#{prefix} - #{message} - start") if @log
26
+ log("#{message} - start", type)
27
+ result = yield
28
+ log("#{message} - finish", type)
29
+ # logger.send(type, "#{prefix} - #{message} - finish") if @log
30
+ result
31
+ end
32
+
33
+ def log(message, type = 'debug')
34
+ logger.send(type, "#{prefix} - #{message}")
35
+ end
36
+
37
+ def prefix
38
+ end
39
+
40
+ end
41
+ end