docman 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d1034856fdc60a997b250d585f83e26d24417bc
4
- data.tar.gz: e938706541e51075cd3bb3d3a962f4de8d74a2c2
3
+ metadata.gz: 03c6d600c4554cc1eb0570c4c1248f6662db3af0
4
+ data.tar.gz: 8511855ac1a09d583c0ce3cef70c7d4a5c96a228
5
5
  SHA512:
6
- metadata.gz: ffc1b6c9a829ac5bacad49e09248152c2763128d07519414dc431696a6c5b7164952685b11e815be20549f6243ad181d8976ddf22947ce4caef6bfd153db51ad
7
- data.tar.gz: 3a20e9bd9853ef90c12b48742d25a1458b994f5c45c96654590d140e0d66bce08d505d482d87386e69a3b6d54b43c9d70d50fcd326022b33fda88a0a9c18e6ab
6
+ metadata.gz: 4fec63186230d02c13e1df24e52c812a175fb63b590319bafa6d2c9175e088ea543cd4976f823e90ed9c4ea15c8137b4b013000bb663a353712ac11493194b19
7
+ data.tar.gz: 485796775944d65fa287c66e76140f42c3fb500dc3de54d445a54bc122b19701f73cb0a01ea11a1e8663ee1e0dcde511b4fc0073af1b0c391b9935fee15b6867
@@ -0,0 +1,64 @@
1
+ #!/bin/bash
2
+
3
+ # works with a file called VERSION in the current directory,
4
+ # the contents of which should be a semantic version number
5
+ # such as "1.2.3"
6
+
7
+ # this script will display the current version, automatically
8
+ # suggest a "minor" version update, and ask for input to use
9
+ # the suggestion, or a newly entered value.
10
+
11
+ # once the new version number is determined, the script will
12
+ # pull a list of changes from git history, prepend this to
13
+ # a file called CHANGES (under the title of the new version
14
+ # number) and create a GIT tag.
15
+
16
+ if [ -f VERSION ]; then
17
+ BASE_STRING=`cat VERSION`
18
+ BASE_LIST=(`echo $BASE_STRING | tr '.' ' '`)
19
+ V_MAJOR=${BASE_LIST[0]}
20
+ V_MINOR=${BASE_LIST[1]}
21
+ V_PATCH=${BASE_LIST[2]}
22
+ echo "Current version : $BASE_STRING"
23
+ V_MINOR=$((V_MINOR + 1))
24
+ V_PATCH=0
25
+ SUGGESTED_VERSION="$V_MAJOR.$V_MINOR.$V_PATCH"
26
+ read -p "Enter a version number [$SUGGESTED_VERSION]: " INPUT_STRING
27
+ if [ "$INPUT_STRING" = "" ]; then
28
+ INPUT_STRING=$SUGGESTED_VERSION
29
+ fi
30
+ echo "Will set new version to be $INPUT_STRING"
31
+ echo $INPUT_STRING > VERSION
32
+ echo "Version $INPUT_STRING:" > tmpfile
33
+ git log --pretty=format:" - %s" "$BASE_STRING"...HEAD >> tmpfile
34
+ echo "" >> tmpfile
35
+ echo "" >> tmpfile
36
+ cat CHANGES >> tmpfile
37
+ mv tmpfile CHANGES
38
+ git add CHANGES VERSION
39
+ git commit -m "Version bump to $INPUT_STRING"
40
+ git tag -a -m "Tagging version $INPUT_STRING" "$INPUT_STRING"
41
+ git push origin --tags
42
+ git push
43
+ else
44
+ echo "Could not find a VERSION file"
45
+ read -p "Do you want to create a version file and start from scratch? [y]" RESPONSE
46
+ if [ "$RESPONSE" = "" ]; then RESPONSE="y"; fi
47
+ if [ "$RESPONSE" = "Y" ]; then RESPONSE="y"; fi
48
+ if [ "$RESPONSE" = "Yes" ]; then RESPONSE="y"; fi
49
+ if [ "$RESPONSE" = "yes" ]; then RESPONSE="y"; fi
50
+ if [ "$RESPONSE" = "YES" ]; then RESPONSE="y"; fi
51
+ if [ "$RESPONSE" = "y" ]; then
52
+ echo "0.1.0" > VERSION
53
+ echo "Version 0.1.0" > CHANGES
54
+ git log --pretty=format:" - %s" >> CHANGES
55
+ echo "" >> CHANGES
56
+ echo "" >> CHANGES
57
+ git add VERSION CHANGES
58
+ git commit -m "Added VERSION and CHANGES files, Version bump to 0.1.0"
59
+ git tag -a -m "Tagging version 0.1.0" "0.1.0"
60
+ git push origin --tags
61
+ git push
62
+ fi
63
+
64
+ fi
@@ -0,0 +1,29 @@
1
+ #!/bin/sh
2
+
3
+ #
4
+ # Check if git directory has no changes.
5
+ #
6
+ cd $1
7
+
8
+ git rev-parse --verify HEAD >/dev/null || echo 1
9
+ git update-index -q --ignore-submodules --refresh
10
+
11
+ err=0
12
+
13
+ if ! git diff-files --quiet --ignore-submodules
14
+ then
15
+ err=1
16
+ fi
17
+
18
+ if ! git diff-index --cached --quiet --ignore-submodules HEAD --
19
+ then
20
+ err=1
21
+ fi
22
+
23
+ test -z "$(git status --porcelain)" || err=1
24
+
25
+ if [ ${err} = "1" ]
26
+ then
27
+ echo ${err}
28
+ exit 1
29
+ fi
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'docman/cli'
7
+
8
+ Docman::CLI.start(ARGV)
@@ -1,32 +1,55 @@
1
+ ---
1
2
  deploy_targets:
2
3
  local:
3
- build_types:
4
- root: dir
5
- drupal: drupal
6
- repo: repo
7
- dir: dir
4
+ handler: LocalDeployer
5
+ builders:
6
+ root:
7
+ handler: :common
8
+ type: dir
9
+ drupal:
10
+ handler: :drupal
11
+ type: drupal
12
+ repo:
13
+ handler: :git
14
+ type: direct
15
+ dir:
16
+ handler: :common
17
+ type: dir
8
18
  acquia:
9
- build_types:
10
- root: repo
11
- drupal: drupal
12
- repo: subrepo
13
- dir: dir
19
+ handler: GitDeployer
20
+ deploy_action: git_push
21
+ builders:
22
+ root:
23
+ handler: :git
24
+ type: direct
25
+ after_build_actions:
26
+ - git_commit
27
+ drupal:
28
+ handler: :drupal
29
+ type: drupal
30
+ after_build_actions:
31
+ - git_commit
32
+ repo:
33
+ handler: :git
34
+ type: strip
35
+ after_build_actions:
36
+ - git_commit
37
+ dir:
38
+ handler: :common
39
+ type: dir
40
+ after_build_actions:
41
+ - git_commit
14
42
 
15
43
  environments:
16
44
  local:
17
- deploy_target:
18
- local
45
+ deploy_target: local
46
+ state: development
19
47
  dev:
20
- deploy_target:
21
- acquia
48
+ deploy_target: acquia
49
+ state: development
22
50
  test:
23
- deploy_target:
24
- acquia
51
+ deploy_target: acquia
52
+ state: staging
25
53
  prod:
26
- deploy_target:
27
- acquia
28
-
29
- states:
30
- - development
31
- - staging
32
- - stable
54
+ deploy_target: acquia
55
+ state: stable
@@ -23,5 +23,4 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "aruba"
24
24
 
25
25
  spec.add_dependency 'thor'
26
- spec.add_dependency 'configliere'
27
26
  end
@@ -1,4 +1,4 @@
1
- Feature: Docroot management (deploy to local)
1
+ Feature: Docroot management
2
2
 
3
3
  In order to manage docroot
4
4
  As a developer using Cucumber
@@ -0,0 +1,37 @@
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
+
7
+ @announce
8
+ @no-clobber
9
+ Scenario: Local deploy sample project 1 develop
10
+ Given I cd to "sample-docroot"
11
+ Then I run `docman deploy local sample_project1 branch develop`
12
+ Then the exit status should be 0
13
+ Then the following directories should exist:
14
+ | master |
15
+ | master/docroot |
16
+ | master/docroot/sites |
17
+ | master/hooks |
18
+ | master/profiles |
19
+ | master/profiles/sample_profile |
20
+ | master/projects/sample_project1 |
21
+ | master/projects/sample_project2 |
22
+
23
+ @announce
24
+ @no-clobber
25
+ Scenario: Local deploy sample project 2 master
26
+ Given I cd to "sample-docroot"
27
+ Then I run `docman deploy local sample_project2 branch master`
28
+ Then the exit status should be 0
29
+ Then the following directories should exist:
30
+ | master |
31
+ | master/docroot |
32
+ | master/docroot/sites |
33
+ | master/hooks |
34
+ | master/profiles |
35
+ | master/profiles/sample_profile |
36
+ | master/projects/sample_project1 |
37
+ | master/projects/sample_project2 |
@@ -1,5 +1,6 @@
1
1
  require 'aruba/cucumber'
2
2
 
3
3
  Before do
4
+ @dirs = ['/Users/alex/dev/dm/aruba']
4
5
  @aruba_timeout_seconds = 600
5
6
  end
@@ -5,17 +5,17 @@
5
5
  # end
6
6
  # end
7
7
  #
8
- # When(/^I store bump version from file "(.*?)"$/) do |file|
9
- # ENV['DM_BUMPED_VERSION'] = IO.read(file)
10
- # end
11
- #
12
- # When(/^I change repo state to last bumped tag for "(.*?)" version$/) do |state|
13
- # version = ENV["DM_BUMPED_VERSION"]
14
- # run "state.sh tag #{version} #{state}"
15
- # end
16
- #
17
- # Then(/^the file "(.*?)" should contain last bumped tag$/) do |file|
18
- # version = ENV["DM_BUMPED_VERSION"]
19
- # puts "Last bumped tag: #{version}"
20
- # prep_for_fs_check { expect(IO.read(file)).to eq version }
21
- # end
8
+ When(/^I store bump version from file "(.*?)"$/) do |file|
9
+ ENV['DM_BUMPED_VERSION'] = IO.read(file)
10
+ end
11
+
12
+ When(/^I change repo state to last bumped tag for "(.*?)" version$/) do |state|
13
+ version = ENV["DM_BUMPED_VERSION"]
14
+ run "state.sh tag #{version} #{state}"
15
+ end
16
+
17
+ Then(/^the file "(.*?)" should contain last bumped tag$/) do |file|
18
+ version = ENV["DM_BUMPED_VERSION"]
19
+ puts "Last bumped tag: #{version}"
20
+ prep_for_fs_check { expect(IO.read(file)).to eq version }
21
+ end
@@ -0,0 +1,56 @@
1
+ require 'docman/version'
2
+ require 'yaml'
3
+ require 'pathname'
4
+ require 'fileutils'
5
+ require 'docman/git_util'
6
+ require 'docman/docroot_config'
7
+ require 'docman/docroot_controller'
8
+ require 'docman/exec'
9
+ require 'singleton'
10
+
11
+ module Docman
12
+ class Application
13
+
14
+ attr_reader :config, :options
15
+ attr_accessor :deploy_target
16
+
17
+ include Singleton
18
+
19
+ def initialize
20
+ # TODO: Define workspace properly
21
+ @workspace_dir = Dir.pwd
22
+ @config = YAML::load_file(File.join(Pathname(__FILE__).dirname.parent, 'config', 'config.yaml'))
23
+ end
24
+
25
+ def init(name, repo)
26
+ `mkdir #{name} && cd #{name} && git clone #{repo} config`
27
+ end
28
+
29
+ def build(deploy_target, state, options = false)
30
+ @options = options
31
+ DocrootController.new(@workspace_dir, deploy_target, options).build(state)
32
+ end
33
+
34
+ def deploy(deploy_target, name, type, version)
35
+ DocrootController.new(@workspace_dir, deploy_target).deploy(name, type, version)
36
+ end
37
+
38
+ def state(name, type, version)
39
+ DocrootController.new(@workspace_dir, deploy_target).state(name, type, version)
40
+ end
41
+
42
+ def self.root
43
+ Pathname(__FILE__).dirname.parent
44
+ end
45
+
46
+ def self.bin
47
+ File.join root, 'bin'
48
+ end
49
+
50
+ def self.lib
51
+ File.join root, 'lib'
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,79 @@
1
+ require 'yaml'
2
+
3
+ module Docman
4
+ module Builders
5
+ class Builder
6
+ @@subclasses = {}
7
+
8
+ def self.create(type, root, build_type, state, info)
9
+ c = @@subclasses[type]
10
+ if c
11
+ c.new(root, build_type, state, info)
12
+ else
13
+ raise "Bad builder type: #{type}"
14
+ end
15
+ end
16
+
17
+ def self.register_builder(name)
18
+ @@subclasses[name] = self
19
+ end
20
+
21
+ def initialize(root, build_type, state, info)
22
+ @root = root
23
+ @build_type = build_type
24
+ @state = state
25
+ @info = info
26
+ @before_build_actions = @build_type['before_build_actions'].nil? ? [] : @build_type['before_build_actions']
27
+ @after_build_actions = @build_type['after_build_actions'].nil? ? [] : @build_type['after_build_actions']
28
+ @before_build_actions << 'clean_if_changed'
29
+ end
30
+
31
+ def before_build_action_clean_if_changed
32
+ if File.directory? @info['full_build_path']
33
+ FileUtils.rm_r @info['full_build_path'] if @info.need_rebuild?
34
+ end
35
+ end
36
+
37
+ def do
38
+ perform(@before_build_actions, 'before_build_action')
39
+ # Dispatch to corresponding method.
40
+ write_info self.send("#{@build_type['type']}")
41
+ perform(@after_build_actions, 'after_build_action')
42
+ end
43
+
44
+ def write_info(result)
45
+ to_save = {}
46
+ # to_save = @info.clone
47
+ to_save['state'] = @state
48
+ to_save['version_type'] = @info.version_type(@state) unless @info.version_type(@state).nil?
49
+ to_save['version'] = @info.version(@state) unless @info.version(@state).nil?
50
+ to_save['ref'] = result
51
+ to_save['build_type'] = @build_type['type']
52
+ # to_save.delete('full_build_path')
53
+ # to_save.delete('full_path')
54
+ # to_save.delete('temp_path')
55
+ # to_save.delete('repo')
56
+ # to_save.delete('states')
57
+ File.open("#{@info['full_build_path']}/info.yaml", 'w') {|f| f.write to_save.to_yaml}
58
+ end
59
+
60
+ def perform(actions, method_prefix)
61
+ unless actions.nil?
62
+ actions.each do |action|
63
+ method = "#{method_prefix}_#{action}"
64
+ self.send(method)
65
+ end
66
+ end
67
+ end
68
+
69
+ def repo?(path)
70
+ File.directory? File.join(path, '.git')
71
+ end
72
+
73
+ def after_build_action_git_commit
74
+ message = "name: #{@info['name']} updated, state: #{@state}"
75
+ GitUtil.commit(@root['full_build_path'], @info['full_build_path'], message)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,16 @@
1
+ module Docman
2
+ module Builders
3
+ class CommonBuilder < Builder
4
+
5
+ register_builder :common
6
+
7
+ def dir
8
+ if File.directory? @info['full_build_path']
9
+ FileUtils.rm_r(@info['full_build_path']) if self.repo? @info['full_build_path']
10
+ end
11
+ FileUtils::mkdir_p @info['full_build_path']
12
+ @info['build_path']
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require 'yaml'
2
+
3
+ module Docman
4
+ module Builders
5
+ class GitBuilder < Builder
6
+
7
+ register_builder :git
8
+
9
+ def direct
10
+ puts 'Do direct'
11
+ GitUtil.get(@info['repo'], @info['full_build_path'], version_type, version)
12
+ end
13
+
14
+ def strip
15
+ puts 'Do strip'
16
+ FileUtils.rm_r(@info['full_build_path']) if File.directory? @info['full_build_path']
17
+ result = GitUtil.get(@info['repo'], @info['temp_path'], version_type, version)
18
+ FileUtils.mkdir_p(@info['full_build_path'])
19
+ FileUtils.cp_r(Dir["#{@info['temp_path']}/."], @info['full_build_path'])
20
+ FileUtils.rm_r(File.join(@info['full_build_path'], '.git'))
21
+ result
22
+ end
23
+
24
+ # TODO: need to refactor into into @info class.
25
+ def version
26
+ @info['states'][@state]['version']
27
+ end
28
+
29
+ def version_type
30
+ @info['states'][@state]['type']
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,26 +1,51 @@
1
1
  require 'thor'
2
- require 'docman'
2
+ require 'application'
3
3
 
4
4
  module Docman
5
5
  class CLI < Thor
6
+
7
+ # TODO: add proper descriptions.
8
+
6
9
  desc 'init NAME', 'init to NAME'
7
10
  def init(name, repo)
8
- puts "Init docroot directory #{name} and retrieve config from provided repo."
9
11
  if File.directory? "#{name}"
10
- `rm -fR #{name}`
12
+ say("Complete!", :green)
13
+ $stderr.puts "Directory #{name} already exists"
14
+ choice = ask('Are you sure you want do delete existing docroot?')
15
+ FileUtils.rm_r(name) if choice == 'yes'
11
16
  end
12
- `mkdir #{name} && cd #{name} && git clone #{repo} config`
17
+
18
+ puts "Init docroot directory #{name} and retrieve config from provided repo."
19
+ Application.instance.init(name, repo)
13
20
  end
14
21
 
15
22
  desc 'build NAME', 'init to NAME'
16
- def build(target, state)
17
- unless File.directory?('config')
18
- $stderr.puts 'ERROR: No config directory in docroot'
19
- exit 1
20
- end
23
+ method_option :force, :aliases => '-f', :desc => 'Force full rebuild'
24
+ def build(deploy_target, state)
25
+ config_dir?
21
26
 
22
- `cd config && git reset --hard && git clean -f -d && git pull origin master`
23
- Docman.new.build(target, state)
27
+ Application.instance.build(deploy_target, state, options)
24
28
  end
29
+
30
+ desc 'deploy NAME', 'init to NAME'
31
+ def deploy(deploy_target, name, type, version)
32
+ config_dir?
33
+ Application.instance.deploy(deploy_target, name, type, version)
34
+ end
35
+
36
+ desc 'state NAME', 'init to NAME'
37
+ def state(name, type, version)
38
+ config_dir?
39
+ Application.instance.state(name, type, version)
40
+ end
41
+
42
+ no_commands {
43
+ def config_dir?
44
+ unless File.directory?('config')
45
+ $stderr.puts 'ERROR: No config directory in docroot'
46
+ exit 1
47
+ end
48
+ end
49
+ }
25
50
  end
26
51
  end
@@ -0,0 +1,25 @@
1
+ module Docman
2
+ module Deployers
3
+ class Deployer
4
+
5
+ attr_reader :deploy_target
6
+
7
+ def build(root, state, info)
8
+ return if @deployed.include? info['name']
9
+ build_type = build_type(info['type'])
10
+ Docman::Builders::Builder.create(build_type['handler'], root, build_type, state, info).do()
11
+ @deployed << info['name']
12
+ end
13
+
14
+ def initialize(deploy_target)
15
+ @deployed = []
16
+ @deploy_target = deploy_target
17
+ end
18
+
19
+ def build_type(type)
20
+ @deploy_target['builders'][type]
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ module Docman
2
+ module Deployers
3
+ class GitDeployer < Deployer
4
+ def push(info, state_name)
5
+ version = info['states'][state_name]['version']
6
+ GitUtil.push(info['full_build_path'], version)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Docman
2
+ module Deployers
3
+ class LocalDeployer < Deployer
4
+ def push(info)
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,91 @@
1
+ require 'fileutils'
2
+ require 'docman/info'
3
+
4
+ module Docman
5
+
6
+ class DocrootConfig
7
+
8
+ attr_reader :structure
9
+
10
+ def initialize(docroot_dir, deploy_target)
11
+ @docroot_dir = docroot_dir
12
+ @deploy_target = deploy_target
13
+ @docroot_config_dir = File.join(docroot_dir, 'config')
14
+ update
15
+ @names = {}
16
+ @structure = structure_build File.join(@docroot_config_dir, 'master')
17
+ end
18
+
19
+ def update
20
+ GitUtil.update @docroot_config_dir
21
+ end
22
+
23
+ def structure_build(path, prefix = '', parent = nil)
24
+ return unless File.file? File.join(path, 'info.yaml')
25
+
26
+ info = YAML::load_file(File.join(path, 'info.yaml'))
27
+ name = File.basename path
28
+ prefix = prefix.size > 0 ? File.join(prefix, name) : name
29
+ info['full_path'] = path
30
+ info['build_path'] = prefix
31
+ info['full_build_path'] = File.join(@docroot_dir, prefix)
32
+ info['temp_path'] = File.join(@docroot_dir, 'tmp', info['build_path'])
33
+ info['name'] = name
34
+ info['parent'] = parent
35
+
36
+ i = Docman::Info.new(info)
37
+
38
+ @names[name.to_s] = i
39
+
40
+ data = {:data => info, :info => i}
41
+ data[:children] = children = []
42
+ Dir.foreach(path) do |entry|
43
+ next if (entry == '..' || entry == '.')
44
+ full_path = File.join(path, entry)
45
+ if File.directory?(full_path)
46
+ dir_hash = structure_build(full_path, prefix, i)
47
+ unless dir_hash == nil
48
+ children << dir_hash
49
+ end
50
+ end
51
+ end
52
+ data
53
+ end
54
+
55
+
56
+ def chain(info)
57
+ chain = {}
58
+ chain[info['name']] = info
59
+ while info['parent'] do
60
+ chain[info['parent']['name']] = info['parent']
61
+ info = info['parent']
62
+ end
63
+ Hash[chain.to_a.reverse!]
64
+ end
65
+
66
+ def root(info)
67
+ chain(info).each do |name, item|
68
+ if item['type'] == 'root'
69
+ return item
70
+ end
71
+ end
72
+ end
73
+
74
+ def root_dir
75
+ @structure[:data]
76
+ end
77
+
78
+ def info_by(name)
79
+ @names[name]
80
+ end
81
+
82
+ def states_dependin_on(name, version)
83
+ states = {}
84
+ @names[name]['states'].each do |state, info|
85
+ states[state] = info if info['version'] == version
86
+ end
87
+ states
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,65 @@
1
+ require 'docman/builders/builder'
2
+ require 'docman/builders/common_builder'
3
+ require 'docman/builders/git_builder'
4
+ require 'docman/deployers/deployer'
5
+ require 'docman/deployers/git_deployer'
6
+ require 'docman/deployers/local_deployer'
7
+
8
+ # TODO: refactor info into class.
9
+ # TODO: make universal logging class.
10
+
11
+ module Docman
12
+ class DocrootController
13
+
14
+ attr_reader :docroot_dir, :temp_dir
15
+
16
+ def initialize(docroot_dir, deploy_target_name, options = {})
17
+ @deploy_target = Docman::Application.instance.config['deploy_targets'][deploy_target_name]
18
+ Docman::Application.instance.deploy_target = @deploy_target
19
+ docroot_config = DocrootConfig.new(docroot_dir, @deploy_target)
20
+ @deployer = Object.const_get("Docman::Deployers::#{@deploy_target['handler']}").new(@deploy_target)
21
+ @docroot_dir = docroot_dir
22
+ @temp_dir = File.join(docroot_dir, 'tmp')
23
+ @docroot_config = docroot_config
24
+ end
25
+
26
+ def deploy(name, type, version)
27
+ puts "Deploy #{name}, type: #{type}"
28
+ @docroot_config.states_dependin_on(name, version).each do |state_name, state|
29
+ deploy_dir_chain(state_name, @docroot_config.info_by(name))
30
+ @deployer.push(@docroot_config.root_dir, state_name)
31
+ end
32
+ end
33
+
34
+ def build(state)
35
+ build_recursive(state)
36
+ @deployer.push(@docroot_config.root_dir, state)
37
+ end
38
+
39
+ def build_recursive(state, dir = nil)
40
+ dir = dir ? dir : @docroot_config.structure
41
+ build_dir(state, dir[:info])
42
+
43
+ dir[:children].each do |child|
44
+ build_recursive(state, child)
45
+ end
46
+ end
47
+
48
+ def deploy_dir_chain(state, info)
49
+ @docroot_config.chain(info).each do |name, item|
50
+ if item.need_rebuild?
51
+ build_recursive(state, item)
52
+ return
53
+ elsif
54
+ build_dir(state, item)
55
+ end
56
+ end
57
+ end
58
+
59
+ def build_dir(state, info)
60
+ @deployer.build(@docroot_config.root(info), state, info)
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,12 @@
1
+ module Docman
2
+
3
+ class Exec
4
+
5
+ def Exec.do(cmd)
6
+ `#{cmd}`
7
+ $?.exitstatus == 0
8
+ end
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,47 @@
1
+ module Docman
2
+
3
+ class GitUtil
4
+
5
+ def self.get(repo, path, type, version)
6
+ if File.directory? path
7
+ Dir.chdir path
8
+ `git checkout #{version} && git pull origin #{version}` if type == 'branch'
9
+ if type == 'tag'
10
+ `git fetch --tags`
11
+ `git checkout "tags/#{version}"`
12
+ end
13
+ else
14
+ `git clone #{repo} #{path}`
15
+ Dir.chdir path
16
+ `git checkout #{version}`
17
+ end
18
+ result = `git rev-parse --short HEAD`
19
+ result.delete!("\n")
20
+ end
21
+
22
+ def self.update(path)
23
+ `cd #{path} && git pull`
24
+ end
25
+
26
+ 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}"`
34
+ end
35
+ end
36
+
37
+ def self.repo_changed?(path)
38
+ not Exec.do "#{Application::bin}/dm_repo_clean.sh #{path}"
39
+ end
40
+
41
+ def self.push(root_path, version)
42
+ Dir.chdir root_path
43
+ `git push origin #{version}`
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,35 @@
1
+ module Docman
2
+ class Info < Hash
3
+ def initialize(hash = {})
4
+ super
5
+ hash.each_pair do |k, v|
6
+ self[k] = v
7
+ end
8
+ set_build_type
9
+ # self['rebuild'] = need_rebuild?
10
+ end
11
+
12
+ def version(state)
13
+ self['states'][state].nil? ? nil : self['states'][state]['version']
14
+ end
15
+
16
+ def version_type(state)
17
+ self['states'][state].nil? ? nil : self['states'][state]['type']
18
+ end
19
+
20
+ def need_rebuild?
21
+ return TRUE if Docman::Application.instance.options[:force]
22
+ return TRUE unless File.directory? self['full_build_path']
23
+ info_filename = File.join(self['full_build_path'], 'info.yaml')
24
+ return TRUE unless File.file?(info_filename)
25
+ version = YAML::load_file(info_filename)
26
+ return TRUE if version['type'] != self['type']
27
+ return TRUE if version['build_type'] != self['build_type']
28
+ false
29
+ end
30
+
31
+ def set_build_type
32
+ Docman::Application.instance.deploy_target['builders'][self['type']]['type']
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Docman
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Tolstikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-25 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,25 +80,14 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: configliere
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  description:
98
84
  email:
99
85
  - atolstikov@adyax.com
100
86
  executables:
87
+ - bump-version.sh
88
+ - dm_repo_clean.sh
101
89
  - docman
90
+ - docman.rb
102
91
  extensions: []
103
92
  extra_rdoc_files: []
104
93
  files:
@@ -107,15 +96,29 @@ files:
107
96
  - LICENSE.txt
108
97
  - README.md
109
98
  - Rakefile
99
+ - bin/bump-version.sh
100
+ - bin/dm_repo_clean.sh
110
101
  - bin/docman
102
+ - bin/docman.rb
111
103
  - config/config.yaml
112
104
  - docman.gemspec
113
105
  - features/local.feature
106
+ - features/local_deploy.feature
114
107
  - features/support/env.rb
115
108
  - features/support/step_definitions/dm_steps.rb
116
- - lib/docman.rb
109
+ - lib/application.rb
110
+ - lib/docman/builders/builder.rb
111
+ - lib/docman/builders/common_builder.rb
112
+ - lib/docman/builders/git_builder.rb
117
113
  - lib/docman/cli.rb
118
- - lib/docman/git.rb
114
+ - lib/docman/deployers/deployer.rb
115
+ - lib/docman/deployers/git_deployer.rb
116
+ - lib/docman/deployers/local_deployer.rb
117
+ - lib/docman/docroot_config.rb
118
+ - lib/docman/docroot_controller.rb
119
+ - lib/docman/exec.rb
120
+ - lib/docman/git_util.rb
121
+ - lib/docman/info.rb
119
122
  - lib/docman/version.rb
120
123
  homepage: ''
121
124
  licenses:
@@ -143,5 +146,6 @@ specification_version: 4
143
146
  summary: Docman made for DOCroot MANagement for Drupal projects
144
147
  test_files:
145
148
  - features/local.feature
149
+ - features/local_deploy.feature
146
150
  - features/support/env.rb
147
151
  - features/support/step_definitions/dm_steps.rb
@@ -1,117 +0,0 @@
1
- require 'docman/version'
2
- require 'yaml'
3
- require 'configliere'
4
- require 'pathname'
5
- require 'fileutils'
6
- require 'docman/git'
7
-
8
- module Docman
9
- class Docman
10
-
11
- def initialize()
12
- @app_root_dir = Pathname(__FILE__).dirname.parent
13
- @current_dir = Dir.pwd
14
- # TODO: Define workspace properly
15
- @workspace_dir = @current_dir
16
- @docroot_dir = @workspace_dir
17
- @docroot_config_dir = File.join(@docroot_dir, 'config')
18
- @docroot_structure = directory_hash File.join(@docroot_config_dir, 'master')
19
-
20
- Settings.read File.join(@app_root_dir, 'config', 'config.yaml')
21
- Settings.resolve!
22
- @app_settings = Settings
23
- @environments = Settings['environments']
24
- @deploy_targets = Settings['deploy_targets']
25
- end
26
-
27
- def directory_hash(path, prefix = '')
28
- return unless File.file? File.join(path, 'info.yaml')
29
-
30
- name = File.basename path
31
- prefix = prefix.size > 0 ? File.join(prefix, name) : name
32
- info = YAML::load_file(File.join(path, 'info.yaml'))
33
- info['full_path'] = path
34
- info['build_path'] = prefix
35
- info['name'] = name
36
-
37
- data = {:data => info}
38
- data[:children] = children = []
39
- Dir.foreach(path) do |entry|
40
- next if (entry == '..' || entry == '.' || entry == '_states')
41
- full_path = File.join(path, entry)
42
- if File.directory?(full_path)
43
- dir_hash = directory_hash(full_path, prefix)
44
- unless dir_hash == nil
45
- children << dir_hash
46
- end
47
- end
48
- end
49
-
50
- data
51
- end
52
-
53
- def build(target, state)
54
- @target = target
55
- @state = state
56
- traverse_docroot_structure
57
- end
58
-
59
- def deploy
60
-
61
- end
62
-
63
- def traverse_docroot_structure(dir = nil)
64
- dir = dir ? dir : @docroot_structure
65
-
66
- build_dir dir[:data]
67
-
68
- dir[:children].each do |child|
69
- traverse_docroot_structure child
70
- end
71
- end
72
-
73
- def build_dir(info)
74
- case get_build_type info
75
- when 'dir'
76
- build_dir_dir info
77
- when 'repo'
78
- build_dir_repo info
79
- when 'subrepo'
80
- build_dir_subrepo info
81
- end
82
- end
83
-
84
- def get_version(info)
85
- info['states'][@state]
86
- end
87
-
88
- def get_deploy_target
89
- @deploy_targets[@environments[@target]['deploy_target']]
90
- end
91
-
92
- def get_build_type(info)
93
- get_deploy_target['build_types'][info['type']]
94
- end
95
-
96
- def build_dir_dir(info)
97
- FileUtils::mkdir_p get_path_in_docroot info['build_path']
98
- end
99
-
100
- def build_dir_repo(info)
101
- repo = info['repo']
102
- build_path = get_path_in_docroot info['build_path']
103
- version_type = get_version(info)['type']
104
- version = get_version(info)['version']
105
- Git.new.get_repo(repo, build_path, version_type, version)
106
- end
107
-
108
- def build_dir_subrepo(info)
109
-
110
- end
111
-
112
- def get_path_in_docroot(path)
113
- File.join(@docroot_dir, path)
114
- end
115
- end
116
-
117
- end
@@ -1,21 +0,0 @@
1
- module Docman
2
-
3
- class Git
4
- def get_repo(repo, path, type, version)
5
- if File.directory? path
6
- Dir.chdir path
7
- `git checkout #{version} && git pull origin #{version}` if type == 'branch'
8
- `git checkout #{version}` if type == 'tag'
9
- else
10
- `git clone #{repo} #{path}`
11
- Dir.chdir path
12
- `git checkout #{version}`
13
- end
14
-
15
- # if result.nil?
16
- # puts "Error: #{$?}"
17
- # end
18
- end
19
- end
20
-
21
- end