dply 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ require 'fileutils'
2
+
3
+ module Dply
4
+ class SharedDirs
5
+
6
+ def initialize(extra_dirs)
7
+ dirs << extra_dirs
8
+ end
9
+
10
+ def create
11
+ FileUtils.mkdir_p dirs
12
+ end
13
+
14
+ def create_in(dir)
15
+ Dir.chdir(dir) { create }
16
+ end
17
+
18
+ def dirs
19
+ @dirs ||= [
20
+ "tmp",
21
+ "log",
22
+ "tmp/pids",
23
+ "tmp/sockets"
24
+ ]
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,47 @@
1
+ require 'dply/error'
2
+
3
+ module Dply
4
+ module Shell
5
+
6
+ include Logger
7
+
8
+ def cmd(command, display: true, error_msg: nil, return_output: false)
9
+ if display
10
+ puts "#{"\u2219".bold.blue} #{command}"
11
+ else
12
+ logger.debug command
13
+ end
14
+ if return_output
15
+ output = `#{command}`
16
+ else
17
+ output = ""
18
+ system "#{command} 2>&1"
19
+ end
20
+ return_value = $?.exitstatus
21
+ error_msg ||= "non zero exit for \"#{command}\""
22
+ raise ::Dply::Error, error_msg if return_value !=0
23
+ return output
24
+ end
25
+
26
+ def symlink(src, dst)
27
+ if File.symlink? dst
28
+ FileUtils.rm dst
29
+ FileUtils.ln_s src, dst
30
+ elsif File.exist? dst
31
+ raise "cannot create symlink #{dst} => #{src}"
32
+ else
33
+ FileUtils.ln_s src, dst
34
+ end
35
+ end
36
+
37
+ def symlink_in_dir(src,destdir)
38
+ if not Dir.exist? destdir
39
+ raise "symlink destination not a dir"
40
+ end
41
+ src_path = Pathname.new(src)
42
+ dst = "#{destdir}/#{src_path.basename}"
43
+ symlink src, dst
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,94 @@
1
+ require 'dply/helper'
2
+
3
+ module Dply
4
+ class StagesConfig
5
+
6
+ include Helper
7
+ attr_reader :config_file
8
+ attr_accessor :current_stage
9
+
10
+ def initialize(config_file)
11
+ @config_file = config_file
12
+ end
13
+
14
+ def config
15
+ return @config if @config
16
+ @config = {
17
+ stages: {}
18
+ }
19
+ read_from_file
20
+ @config
21
+ end
22
+
23
+
24
+ def user(user)
25
+ set_in_current_stage :user, user
26
+ end
27
+
28
+ def deploy_dir(deploy_dir)
29
+ set_in_current_stage :deploy_dir, deploy_dir
30
+ end
31
+
32
+ def host(host, user: nil, deploy_dir: nil, id: nil)
33
+ hosts = get_from_current_stage(:hosts)
34
+ host_info = {
35
+ host: host,
36
+ user: user || get_from_current_stage(:user),
37
+ deploy_dir: deploy_dir || get_from_current_stage(:deploy_dir),
38
+ id: id || "unnamed"
39
+ }
40
+ hosts << host_info
41
+ end
42
+
43
+ def parallel_runs(parallel_runs)
44
+ set_in_current_stage :parallel_runs, parallel_runs
45
+ end
46
+
47
+ def set_in_current_stage(key, value)
48
+ stages[current_stage][key] = value
49
+ end
50
+
51
+ def get_from_current_stage(key)
52
+ stages[current_stage][key]
53
+ end
54
+
55
+ def stages
56
+ config[:stages]
57
+ end
58
+
59
+ def get_stage(stage)
60
+ stage = stage.to_sym
61
+ config[:stages][stage]
62
+ end
63
+
64
+ def stage(name)
65
+ begin
66
+ name = name.to_sym
67
+ self.current_stage = name
68
+ init_stage name
69
+ yield
70
+ ensure
71
+ self.current_stage = nil
72
+ end
73
+ end
74
+
75
+ def init_stage(name)
76
+ stages[name] = {}
77
+ stages[name][:hosts] = []
78
+ stages[name][:parallel_runs] = 1
79
+ end
80
+
81
+
82
+ def read_from_file
83
+ if not File.readable? config_file
84
+ raise error "#{config_file} not readable"
85
+ return
86
+ end
87
+ instance_eval(File.read(config_file), config_file)
88
+ rescue NoMethodError => e
89
+ raise "invalid option used in config: #{e.name} #{e.message}"
90
+ end
91
+
92
+
93
+ end
94
+ end
@@ -0,0 +1,12 @@
1
+ module Dply
2
+ module Strategy
3
+
4
+ def self.load(config, options)
5
+ require_relative "strategy/#{config.strategy}"
6
+ const = "::Dply::Strategy::#{config.strategy.capitalize}"
7
+ const = Module.const_get(const)
8
+ return const.new(config, options)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,50 @@
1
+ require 'dply/helper'
2
+ require 'dply/setup'
3
+ require 'dply/linker'
4
+
5
+
6
+ module Dply
7
+ module Strategy
8
+ class Default
9
+
10
+ include Helper
11
+ attr_reader :config, :options
12
+
13
+ def initialize(config, options)
14
+ @config = config
15
+ @options = options
16
+ end
17
+
18
+ def deploy
19
+ Dir.chdir deploy_dir do
20
+ git_step
21
+ tasks.deploy config.target
22
+ end
23
+ end
24
+
25
+ def switch
26
+
27
+ end
28
+
29
+ private
30
+
31
+ def deploy_dir
32
+ config.deploy_dir
33
+ end
34
+
35
+ def branch
36
+ config.branch
37
+ end
38
+
39
+ def git_step
40
+ return if options[:skip_git]
41
+ if options[:no_pull]
42
+ git.checkout branch
43
+ else
44
+ git.pull branch
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,85 @@
1
+ require 'dply/helper'
2
+ require 'dply/setup'
3
+ require 'dply/linker'
4
+ require 'forwardable'
5
+
6
+
7
+ module Dply
8
+ module Strategy
9
+ class Git
10
+
11
+ extend Forwardable
12
+ include Helper
13
+
14
+ def_delegators :config, :target, :branch, :link_config,
15
+ :config_dir, :config_map, :dir_map
16
+
17
+ attr_reader :config, :options
18
+
19
+ def initialize(config, options)
20
+ @config = config
21
+ @options = options
22
+ end
23
+
24
+ def deploy
25
+ setup.run
26
+ Dir.chdir current_dir do
27
+ git_step
28
+ link_dirs
29
+ link_config_files
30
+ tasks.deploy target
31
+ end
32
+ end
33
+
34
+ def switch
35
+ end
36
+
37
+ private
38
+
39
+ def current_dir
40
+ @current_dir ||= "#{config.deploy_dir}/current"
41
+ end
42
+
43
+ def git_step
44
+ return if options[:skip_git]
45
+ if options[:no_pull]
46
+ git.checkout branch
47
+ else
48
+ git.pull branch
49
+ end
50
+ end
51
+
52
+ def link_config_files
53
+ return if not link_config
54
+ logger.bullet "symlinking config files"
55
+ config_linker.create_symlinks
56
+ end
57
+
58
+ def link_dirs
59
+ return if not dir_map
60
+ logger.bullet "symlinking shared dirs"
61
+ dir_linker.create_symlinks
62
+ end
63
+
64
+ def config_linker
65
+ return @config_linker if @config_linker
66
+ dir_prefix = config_dir || "config"
67
+ source = "#{config.deploy_dir}/config"
68
+ dest = current_dir
69
+ @config_linker ||= ::Dply::Linker.new(source, dest, map: config_map, dir_prefix: dir_prefix)
70
+ end
71
+
72
+ def dir_linker
73
+ return @dir_linker if @dir_linker
74
+ source = "#{config.deploy_dir}/shared"
75
+ dest = current_dir
76
+ @dir_linker ||= ::Dply::Linker.new(source, dest, map: dir_map)
77
+ end
78
+
79
+ def setup
80
+ @setup ||= Setup.load(:git, config)
81
+ end
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,37 @@
1
+ require 'dply/shell'
2
+ module Dply
3
+ class Tasks
4
+
5
+ include Shell
6
+
7
+ def deploy(target)
8
+ bundle_install
9
+ cmd "#{rake_command} #{target}:deploy"
10
+ end
11
+
12
+ def switch(target)
13
+ bundle_install
14
+ cmd "#{rake_command} #{target}:switch"
15
+ end
16
+
17
+ def gemfile_exists?
18
+ File.exists? "Gemfile"
19
+ end
20
+
21
+ def rake_command
22
+ if gemfile_exists?
23
+ "bundle exec rake -R dply"
24
+ else
25
+ "rake -R dply"
26
+ end
27
+ end
28
+
29
+ def bundle_install
30
+ return if not gemfile_exists?
31
+ exitstatus = system "bundle check > /dev/null"
32
+ return if exitstatus
33
+ cmd "bundle install"
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Dply
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dply
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Neeraj
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: rake based deploy tool
42
+ email:
43
+ executables:
44
+ - dplyr
45
+ - drake
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/dplyr
55
+ - bin/drake
56
+ - code_dump/alt_remote_task.rb
57
+ - code_dump/old_remote_task.rb
58
+ - dply.gemspec
59
+ - lib/dply.rb
60
+ - lib/dply/cli/deploy.rb
61
+ - lib/dply/config.rb
62
+ - lib/dply/custom_logger.rb
63
+ - lib/dply/deploy.rb
64
+ - lib/dply/dplyr.rb
65
+ - lib/dply/error.rb
66
+ - lib/dply/ext/string.rb
67
+ - lib/dply/git.rb
68
+ - lib/dply/helper.rb
69
+ - lib/dply/linker.rb
70
+ - lib/dply/lock.rb
71
+ - lib/dply/logger.rb
72
+ - lib/dply/release.rb
73
+ - lib/dply/remote_task.rb
74
+ - lib/dply/repo.rb
75
+ - lib/dply/report.rb
76
+ - lib/dply/setup.rb
77
+ - lib/dply/setup/default.rb
78
+ - lib/dply/setup/git.rb
79
+ - lib/dply/setup/release.rb
80
+ - lib/dply/shared_dirs.rb
81
+ - lib/dply/shell.rb
82
+ - lib/dply/stages_config.rb
83
+ - lib/dply/strategy.rb
84
+ - lib/dply/strategy/default.rb
85
+ - lib/dply/strategy/git.rb
86
+ - lib/dply/tasks.rb
87
+ - lib/dply/version.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: rake based deploy tool
112
+ test_files: []