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
@@ -0,0 +1,27 @@
1
+ Feature: Init
2
+
3
+ In order to manage docroot
4
+ As a developer using Cucumber
5
+ I want to use the deploy steps to deploy to local
6
+
7
+ @announce
8
+ @no-clobber
9
+ @init
10
+ Scenario: Local force init
11
+ Given I run `docman init sample-docroot https://github.com/aroq/dm-test-docroot-config.git -f`
12
+ Then the exit status should be 0
13
+ Then the following directories should exist:
14
+ | sample-docroot |
15
+ | sample-docroot/config |
16
+
17
+ @announce
18
+ @no-clobber
19
+ @init
20
+ Scenario: Local interactive init
21
+ Given I run `docman init sample-docroot https://github.com/aroq/dm-test-docroot-config.git` interactively
22
+ And I type "yes"
23
+ Then the exit status should be 0
24
+ Then the following directories should exist:
25
+ | sample-docroot |
26
+ | sample-docroot/config |
27
+
@@ -0,0 +1,88 @@
1
+ Feature: Docroot management - Local
2
+
3
+ In order to manage docroot
4
+ As a developer using Cucumber
5
+ I want to use the deploy steps to deploy to local
6
+
7
+ @announce
8
+ @no-clobber
9
+ @local
10
+ @build
11
+ Scenario: Local build development
12
+ Given I cd to "sample-docroot"
13
+ Then I run `docman build local development`
14
+ Then the exit status should be 0
15
+ Then the following directories should exist:
16
+ | master |
17
+ | master/docroot |
18
+ | master/docroot/sites |
19
+ | master/hooks |
20
+ | master/profiles |
21
+ | master/profiles/sample_profile |
22
+ | master/projects/sample_project1 |
23
+ | master/projects/sample_project2 |
24
+ | master/docroot/profiles/sample_profile |
25
+ Then the following files should exist:
26
+ | master/docroot/CHANGELOG.txt |
27
+ # Then I remove the file "master/docroot/profiles/sample_profile"
28
+ # Then the following directories should not exist:
29
+ # | master/docroot/profiles/sample_profile |
30
+ # Then I run `docman build local development`
31
+ # Then the exit status should be 0
32
+ # Then the following directories should exist:
33
+ # | master |
34
+ # | master/docroot |
35
+ # | master/docroot/sites |
36
+ # | master/hooks |
37
+ # | master/profiles |
38
+ # | master/profiles/sample_profile |
39
+ # | master/projects/sample_project1 |
40
+ # | master/projects/sample_project2 |
41
+ # | master/docroot/profiles/sample_profile |
42
+
43
+ # @announce
44
+ # @no-clobber
45
+ # @deploy
46
+ # Scenario: Local push into project1 develop
47
+ # Given I cd to "sample-docroot/master/projects/sample_project1"
48
+ # And I run `git reset --hard & git clean -f -d`
49
+ # And I run `git checkout develop`
50
+ # And I run `git pull origin develop`
51
+ # Then the exit status should be 0
52
+ # And I store in "name" value "test"
53
+ # And I check stored value of "name" should contain "test"
54
+ ## And I create file with random name in "filename" content in "random_name"
55
+ # Given a file named "develop.txt" with:
56
+ # """
57
+ # test content
58
+ #
59
+ # """
60
+ # And I run `git add -A`
61
+ # And I run `git commit -m "Test commit to develop"`
62
+ # And I run `git push origin develop`
63
+ # Then the exit status should be 0
64
+
65
+ @announce
66
+ @no-clobber
67
+ @local
68
+ @deploy
69
+ Scenario: Local deploy sample project 1 develop
70
+ Given I cd to "sample-docroot"
71
+ Then I run `docman deploy local sample_project1 branch develop`
72
+ Then the exit status should be 0
73
+ Then the following directories should exist:
74
+ | master/projects/sample_project1 |
75
+
76
+ @announce
77
+ @no-clobber
78
+ @local
79
+ @deploy
80
+ @master
81
+ @sample_project2
82
+ Scenario: Local deploy sample project 2 master
83
+ Given I cd to "sample-docroot"
84
+ Then I run `docman deploy local sample_project2 branch master`
85
+ Then the exit status should be 0
86
+ Then the following directories should exist:
87
+ | master/projects/sample_project1 |
88
+ | master/projects/sample_project2 |
@@ -0,0 +1,6 @@
1
+ Feature: Local deploy
2
+
3
+ In order to manage docroot
4
+ As a developer using Cucumber
5
+ I want to use the deploy steps to deploy to local
6
+
@@ -2,5 +2,5 @@ require 'aruba/cucumber'
2
2
 
3
3
  Before do
4
4
  @dirs = ['/Users/alex/dev/dm/aruba']
5
- @aruba_timeout_seconds = 600
5
+ @aruba_timeout_seconds = 6000
6
6
  end
data/lib/application.rb CHANGED
@@ -4,40 +4,77 @@ require 'pathname'
4
4
  require 'fileutils'
5
5
  require 'docman/git_util'
6
6
  require 'docman/docroot_config'
7
- require 'docman/docroot_controller'
8
7
  require 'docman/exec'
8
+ require 'docman/config'
9
+ require 'docman/logging'
10
+ require 'docman/context'
9
11
  require 'singleton'
12
+ require 'logger'
13
+
14
+ require 'docman/builders/builder'
15
+ require 'docman/builders/dir_builder'
16
+ require 'docman/builders/git_direct_builder'
17
+ require 'docman/builders/git_strip_builder'
18
+ require 'docman/builders/drupal_drush_builder'
19
+ require 'docman/deployers/deployer'
20
+ require 'docman/deployers/git_deployer'
21
+ require 'docman/deployers/common_deployer'
22
+ require 'docman/commands/command'
23
+ require 'docman/commands/composite_command'
24
+ require 'docman/commands/create_symlink_cmd'
25
+ require 'docman/commands/execute_script_cmd'
26
+ require 'docman/commands/clean_changed_cmd'
27
+ require 'docman/commands/git_commit_cmd'
10
28
 
11
29
  module Docman
12
- class Application
30
+ class Application < Docman::Command
13
31
 
14
- attr_reader :config, :options
15
- attr_accessor :deploy_target
32
+ attr_reader :config, :docroot_config
33
+ attr_accessor :deploy_target, :options, :force
16
34
 
17
35
  include Singleton
36
+ include Docman::Context
18
37
 
19
38
  def initialize
20
39
  # TODO: Define workspace properly
21
40
  @workspace_dir = Dir.pwd
22
- @config = YAML::load_file(File.join(Pathname(__FILE__).dirname.parent, 'config', 'config.yaml'))
41
+ @config = Docman::Config.new(File.join(Pathname(__FILE__).dirname.parent, 'config', 'config.yaml'))
42
+ @force = false
23
43
  end
24
44
 
25
45
  def init(name, repo)
26
46
  `mkdir #{name} && cd #{name} && git clone #{repo} config`
27
47
  end
28
48
 
29
- def build(deploy_target, state, options = false)
49
+ def build(deploy_target_name, state, options = false)
30
50
  @options = options
31
- DocrootController.new(@workspace_dir, deploy_target).build(state)
51
+ @deploy_target = @config['deploy_targets'][deploy_target_name]
52
+ @deploy_target['name'] = deploy_target_name
53
+ @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
54
+ execute('build', state)
32
55
  end
33
56
 
34
- def deploy(deploy_target, name, type, version, options = false)
57
+ def deploy(deploy_target_name, name, type, version, options = false)
35
58
  @options = options
36
- DocrootController.new(@workspace_dir, deploy_target).deploy(name, type, version)
59
+ @deploy_target = @config['deploy_targets'][deploy_target_name]
60
+ @deploy_target['name'] = deploy_target_name
61
+ @docroot_config = DocrootConfig.new(@workspace_dir, deploy_target)
62
+ @docroot_config.states_dependin_on(name, version).keys.each do |state|
63
+ execute('deploy', state, name)
64
+ end
65
+ end
66
+
67
+ def execute(action, state, name = nil)
68
+ params = @deploy_target
69
+ params['state'] = state
70
+ params['action'] = action
71
+ params['name'] = name
72
+ params['environment'] = @deploy_target['environments'][state]
73
+ Docman::Deployers::Deployer.create(params, nil, self).perform
37
74
  end
38
75
 
39
- def state(name, type, version)
40
- DocrootController.new(@workspace_dir, deploy_target).state(name, type, version)
76
+ def force?
77
+ @force or @options[:force]
41
78
  end
42
79
 
43
80
  def self.root
@@ -1,62 +1,62 @@
1
- require 'yaml'
1
+ require 'docman/commands/command'
2
2
 
3
3
  module Docman
4
4
  module Builders
5
- class Builder
6
- @@subclasses = {}
5
+ class Builder < Docman::Command
6
+ @@builders = {}
7
+ @@build_results = {}
7
8
 
8
- def self.create(type, root, build_type, info)
9
- c = @@subclasses[type]
9
+
10
+ def self.create(params = nil, context = nil, caller = nil)
11
+ c = @@builders[params['handler']]
10
12
  if c
11
- c.new(root, build_type, info)
13
+ c.new(params, context, caller, 'builder')
12
14
  else
13
15
  raise "Bad builder type: #{type}"
14
16
  end
15
17
  end
16
18
 
17
19
  def self.register_builder(name)
18
- @@subclasses[name] = self
20
+ @@builders[name] = self
21
+ end
22
+
23
+ def config
24
+ super
25
+ add_action('before_execute', {'type' => :clean_changed})
19
26
  end
20
27
 
21
- def initialize(root, build_type, info)
22
- @root = root
23
- @build_type = build_type
24
- @info = info
25
- @before_build_actions = @build_type['before_build_actions'].nil? ? [] : @build_type['before_build_actions']
26
- @after_build_actions = @build_type['after_build_actions'].nil? ? [] : @build_type['after_build_actions']
27
- @before_build_actions << 'clean_if_changed'
28
+ def validate_command
29
+ raise "Please provide 'context'" if @context.nil?
30
+ raise "Context should be of type 'Info'" unless @context.is_a? Docman::Info
28
31
  end
29
32
 
30
- def before_build_action_clean_if_changed
31
- if File.directory? @info['full_build_path']
32
- FileUtils.rm_r @info['full_build_path'] if @info.need_rebuild?
33
+ before_execute do
34
+ #TODO: rebuld if config changed.
35
+ if @context.need_rebuild?
36
+ log("Need rebuild")
37
+ else
38
+ log("Rebuild not needed")
39
+ raise NoChangesError, 'This version already deployed' unless changed?
33
40
  end
41
+
34
42
  end
35
43
 
36
- def do
37
- perform(@before_build_actions, 'before_build_action')
38
- # Dispatch to corresponding method.
39
- @info.write_info(self.send("#{@build_type['type']}"))
40
- perform(@after_build_actions, 'after_build_action')
44
+ after_execute do
45
+ @execute_result = @context.write_info(@execute_result)
41
46
  end
42
47
 
43
- def perform(actions, method_prefix)
44
- unless actions.nil?
45
- actions.each do |action|
46
- method = "#{method_prefix}_#{action}"
47
- self.send(method)
48
- end
49
- end
48
+ def changed?
49
+ false
50
50
  end
51
51
 
52
- def repo?(path)
53
- File.directory? File.join(path, '.git')
52
+ def describe
53
+ "Build: #{properties_info}"
54
54
  end
55
55
 
56
- def after_build_action_git_commit
57
- message = "name: #{@info['name']} updated, state: #{@info['state']}"
58
- GitUtil.commit(@root['full_build_path'], @info['full_build_path'], message)
56
+ def prefix
57
+ "#{@context['name']} - #{self.class.name}"
59
58
  end
59
+
60
60
  end
61
61
  end
62
62
  end
@@ -0,0 +1,21 @@
1
+ module Docman
2
+ module Builders
3
+ class DirBuilder < Builder
4
+
5
+ register_builder :dir_builder
6
+
7
+ def execute
8
+ if File.directory? @context['full_build_path']
9
+ if GitUtil.repo? @context['full_build_path']
10
+ log("Removed dir: #{@context['full_build_path']} because directory is git repo")
11
+ FileUtils.rm_r(@context['full_build_path'])
12
+ end
13
+ end
14
+ log("Created dir: #{@context['full_build_path']}")
15
+ FileUtils::mkdir_p @context['full_build_path']
16
+ @context['build_path']
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
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 unless @context.need_rebuild?
11
+ puts 'Download drupal through drush'
12
+ FileUtils.mkdir_p(@context['temp_path'])
13
+ Dir.chdir @context['temp_path']
14
+ `drush dl drupal-#{@context.version} --yes`
15
+ FileUtils.mkdir_p(@context['full_build_path'])
16
+ FileUtils.cp_r(Dir["#{@context['temp_path']}/drupal-#{@context.version}/."], @context['full_build_path'])
17
+ @context['version']
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
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
+ @context['type'] == 'root' ? @context['build_path'] : execute_result
10
+ end
11
+
12
+ def changed?
13
+ stored_version = @context.stored_version['result']
14
+ repo_version = GitUtil.get(@context['repo'], @context['full_build_path'], @context.version_type, @context.version)
15
+ stored_version != repo_version
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ module Docman
2
+ module Builders
3
+ class GitStripBuilder < Builder
4
+
5
+ register_builder :git_strip_builder
6
+
7
+
8
+ def execute
9
+ FileUtils.rm_r(@context['full_build_path']) if File.directory? @context['full_build_path']
10
+ FileUtils.rm_r @context['temp_path'] if @context.need_rebuild? and File.directory? @context['temp_path']
11
+ result = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version)
12
+ FileUtils.mkdir_p(@context['full_build_path'])
13
+ FileUtils.cp_r(Dir["#{@context['temp_path']}/."], @context['full_build_path'])
14
+ FileUtils.rm_r(File.join(@context['full_build_path'], '.git')) if File.directory?(File.join(@context['full_build_path'], '.git'))
15
+ # GitUtil.repo_changed?(@context['full_build_path']) ? result : false
16
+ result
17
+ end
18
+
19
+ def changed?
20
+ stored_version = @context.stored_version['result']
21
+ repo_version = GitUtil.get(@context['repo'], @context['temp_path'], @context.version_type, @context.version)
22
+ stored_version != repo_version
23
+ end
24
+
25
+ end
26
+ end
27
+ end
data/lib/docman/cli.rb CHANGED
@@ -32,6 +32,9 @@ module Docman
32
32
  method_option :force, :aliases => '-f', :desc => 'Force full rebuild'
33
33
  def build(deploy_target, state)
34
34
  config_dir?
35
+ if options[:force]
36
+ FileUtils.rm_r('master') if File.directory? 'master'
37
+ end
35
38
  Application.instance.build(deploy_target, state, options)
36
39
  say('Complete!', :green)
37
40
  end
@@ -0,0 +1,23 @@
1
+ module Docman
2
+ class CleanChangedCmd < Docman::Command
3
+
4
+ register_command :clean_changed
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 File.directory? @context['full_build_path']
13
+ if @context.need_rebuild?
14
+ return false if @context['type'] == 'root' and @context['build_type'] == :dir_builder and not GitUtil.repo?(@context['full_build_path'])
15
+ return false if @context['type'] == 'root' and @context['build_type'] == :git_direct_builder and GitUtil.repo?(@context['full_build_path'])
16
+ log("Remove #{@context['full_build_path']}")
17
+ FileUtils.rm_rf @context['full_build_path']
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end