dply 0.0.8 → 0.1.0

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: 5ac8e20957d086e8f5f4a48b0b3c3a1ef308ccc5
4
- data.tar.gz: a9987cb85411214aeb580a463178a319ae110ba6
3
+ metadata.gz: 0cb8b78720dfacebae2f3c70eb5a73ee9c8355ed
4
+ data.tar.gz: a428544177c09f38238a5bf2128ea2dd82038749
5
5
  SHA512:
6
- metadata.gz: cb9e410e9f28f7bb913a2582cef14348908fda6ac2812ef8842c6babfffb2bf8e6a845652679ae468ea4a69d3a737f3d5945b4d3fe0c01f7e2e7ea5c06f8989a
7
- data.tar.gz: 80cdf25110010a27123b7620296dffceffb71008dda9fa868e3d2a8278bcec3668b576b1583a2e5fc4008efc5b81ae2b02aff4bdaca61c319bf992ba2b2df871
6
+ metadata.gz: 508041596cef6f13c18a66532a7875c022784d8df7e158693c33433b049f0593139ef340e6b7ebfd2722d6c17111b97b864cf241889d46b02dfe70bf0b5fd772
7
+ data.tar.gz: 6146f87d6669c0e813ab3e4f85fc287263d586749c7d395b22162e7701f5126c760c1fe5bd3d84ad35f1f07c7cbd81c2f077c38ffb22ca57f2d3204a5bd483cd
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ - packages.yml
2
+ - rpm -V --nofiles --nodeps --noscripts rbgem-bundler rbgem-unicorn ImageMagick-devel ImageMagick readline-devel zlib-devel nodejs geos1-devel
3
+ - sudo yum install
data/bin/dplyr CHANGED
@@ -5,7 +5,7 @@ require 'optparse'
5
5
  require 'dply/error'
6
6
  require 'dply/version'
7
7
  require 'dply/logger'
8
- require 'dply/dplyr'
8
+ require 'dplyr/cli'
9
9
  require 'pathname'
10
10
 
11
11
  logger = ::Dply::Logger.logger
@@ -57,7 +57,7 @@ begin
57
57
 
58
58
  stage = ARGV.shift
59
59
 
60
- dplyr = ::Dply::Dplyr.new(stage, ARGV)
60
+ dplyr = ::Dplyr::Cli.new(stage, ARGV)
61
61
  dplyr.run
62
62
 
63
63
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument, ::Dply::Error => e
data/bin/drake CHANGED
@@ -54,8 +54,10 @@ opts_parser = OptionParser.new do |opts|
54
54
  end
55
55
 
56
56
  def run_cli(command, argv)
57
+ command = command.to_s.gsub("-", "_")
57
58
  require "dply/cli/#{command}"
58
- const = "::Dply::Cli::#{command.capitalize}"
59
+ klass_name = command.split('_').collect(&:capitalize).join
60
+ const = "::Dply::Cli::#{klass_name}"
59
61
  klass = Module.const_get const
60
62
  cli = klass.new(argv)
61
63
  cli.run
@@ -67,7 +69,7 @@ begin
67
69
 
68
70
  command = (ARGV.shift || "").to_sym
69
71
  case command
70
- when :deploy, :reload, :task, :build
72
+ when :deploy, :reload, :task, :build, :depcheck, :"install-pkgs"
71
73
  run_cli command, ARGV
72
74
  when /[a-zA-Z_\-0-9]+[:][a-zA-Z_\-0-9]+/
73
75
  require 'dply/task_runner'
data/dply.gemspec CHANGED
@@ -16,6 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
+ spec.add_dependency "ruby-elf", "~> 1.0"
20
+ spec.add_dependency "ruby-filemagic", "~> 0.6"
19
21
 
20
22
  spec.add_development_dependency "bundler", "~> 1.6"
21
23
  spec.add_development_dependency "rake"
data/lib/dply/build.rb CHANGED
@@ -30,7 +30,7 @@ module Dply
30
30
  git.clean
31
31
  link_dirs
32
32
  link_config
33
- yum_install
33
+ install_pkgs
34
34
  clean_build_dir
35
35
  link_build_dir
36
36
  tasks.build config.task
@@ -77,8 +77,8 @@ module Dply
77
77
  linker.create_symlinks
78
78
  end
79
79
 
80
- def yum_install
81
- Yum.new("pkgs.yml").install
80
+ def install_pkgs
81
+ tasks.install_pkgs(build_mode: true, use_yum: config.use_yum)
82
82
  end
83
83
 
84
84
  def clean_build_dir
@@ -52,6 +52,10 @@ module Dply
52
52
  config.no_pull = true
53
53
  end
54
54
 
55
+ opts.on("--use-yum", "use yum to install packages") do |e|
56
+ config.use_yum = true
57
+ end
58
+
55
59
  opts.on("--skip-git", "Disable git") do |e|
56
60
  config.git = false
57
61
  end
@@ -0,0 +1,26 @@
1
+ require 'dply/pkgs_config'
2
+ require 'dply/deplist'
3
+ require 'dply/helper'
4
+
5
+ module Dply
6
+ module Cli
7
+ class Depcheck
8
+
9
+ include Helper
10
+
11
+ def initialize(argv)
12
+ @argv = argv
13
+ end
14
+
15
+ def run
16
+ tar_path = @argv.shift
17
+ error "tar path not specified" if not tar_path
18
+ tar_path = "#{Dir.pwd}/#{tar_path}"
19
+ pkgs = PkgsConfig.new.pkgs
20
+ deplist = Deplist.new(tar_path)
21
+ deplist.verify! pkgs
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -58,6 +58,10 @@ module Dply
58
58
  options[:skip_bundler] = true
59
59
  end
60
60
 
61
+ opts.on("--use-yum", "use yum to install packages") do |e|
62
+ options[:use_yum] = true
63
+ end
64
+
61
65
  opts.on("-h", "--help", "Help") do
62
66
  puts opts
63
67
  exit
@@ -0,0 +1,42 @@
1
+ require 'dply/pkgs_config'
2
+ require 'dply/yum'
3
+ require 'dply/helper'
4
+
5
+ module Dply
6
+ module Cli
7
+ class InstallPkgs
8
+
9
+ include Helper
10
+
11
+ def initialize(argv)
12
+ @argv = argv
13
+ @options = {}
14
+ end
15
+
16
+ def run
17
+ opts.parse!(@argv)
18
+ error "pkgs.yml cannot be a symlink" if File.symlink? "pkgs.yml"
19
+ pkgs = PkgsConfig.new(build_mode: @options[:build_mode]).pkgs
20
+ Yum.new(pkgs).install
21
+ end
22
+
23
+ def opts
24
+ OptionParser.new do |opts|
25
+
26
+ opts.banner = "Usage: drake install-pkgs [options] [target]"
27
+
28
+ opts.on("-b" , "Build mode") do |b|
29
+ @options[:build_mode] = true
30
+ end
31
+
32
+ opts.on("-h", "--help", "Help") do
33
+ puts opts
34
+ exit
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ end
41
+ end
42
+ end
data/lib/dply/config.rb CHANGED
@@ -90,8 +90,13 @@ module Dply
90
90
  end
91
91
  end
92
92
 
93
- def revision(&block)
93
+ def revision(revision = nil, &block)
94
+ if revision
95
+ set :revision, revision
96
+ return
97
+ end
94
98
  set :revision_proc , block
99
+ set :revision, :latest
95
100
  end
96
101
 
97
102
  def build_url(&block)
@@ -17,7 +17,11 @@ module Dply
17
17
  end
18
18
 
19
19
  def revision
20
- @revision ||= instance_eval(&revision_proc)
20
+ if @revision == :latest
21
+ @revision = instance_eval(&revision_proc)
22
+ else
23
+ @revision
24
+ end
21
25
  end
22
26
 
23
27
  def build_url
@@ -0,0 +1,85 @@
1
+ require 'filemagic'
2
+ require 'elf'
3
+ require 'dply/helper'
4
+ require 'dply/rpm'
5
+ require 'tmpdir'
6
+
7
+ module Dply
8
+ class Deplist
9
+
10
+ include Helper
11
+
12
+ def initialize(path)
13
+ @path = path
14
+ end
15
+
16
+ def deps
17
+ @deps ||= load_deps
18
+ end
19
+
20
+ def verify!(pkgs_list)
21
+ deps.each do |pkgs|
22
+ if not pkgs.any? { |pkg| pkgs_list.include? pkg }
23
+ logger.error "missing from pkgs.yml : any of #{pkgs}"
24
+ @error = true
25
+ end
26
+ end
27
+ error "packages dependencies not satisfied" if @error
28
+ puts "all dependencies satisfied".green
29
+ end
30
+
31
+ private
32
+
33
+ def magic
34
+ @magic ||= begin
35
+ flags = FileMagic::FLAGS_BY_SYM.select { |k,v| k.to_s =~ /no_check_/ }.keys
36
+ not_required_flags = [:no_check_soft, :no_check_elf, :no_check_builtin]
37
+ not_required_flags.each {|x| flags.delete(x) }
38
+ fm = FileMagic.new
39
+ fm.flags = flags
40
+ fm
41
+ end
42
+ end
43
+
44
+ def load_deps
45
+ error "#{@path} not readable" if not File.readable? @path
46
+ tmp_dir do
47
+ logger.info "(in #{Dir.pwd})"
48
+ cmd "tar xf #{@path}"
49
+ @libs = get_libs
50
+ logger.debug @libs.inspect
51
+ @deps = rpm.libs_to_packages @libs
52
+ end
53
+ end
54
+
55
+ def tmp_dir(&block)
56
+ dir = File.exist?("tmp") ? "tmp" : "/tmp"
57
+ Dir.mktmpdir(nil, dir) do |d|
58
+ Dir.chdir(d) { yield }
59
+ end
60
+ end
61
+
62
+ def get_libs
63
+ libs = Set.new
64
+ Dir["./**/*"].each do |f|
65
+ type = magic.file(f)
66
+ if type =~ /ELF/
67
+ dynamic_libs(f).each { |k| libs << k }
68
+ end
69
+ end
70
+ return libs
71
+ end
72
+
73
+ def dynamic_libs(file)
74
+ Elf::File.open(file) do |ef|
75
+ return [] if not ef.has_section? ".dynamic"
76
+ ef[".dynamic"].needed_libraries.keys
77
+ end
78
+ end
79
+
80
+ def rpm
81
+ @rpm ||= Rpm.new
82
+ end
83
+
84
+ end
85
+ end
data/lib/dply/helper.rb CHANGED
@@ -1,9 +1,7 @@
1
- require 'dply/tasks'
2
1
  require 'dply/shell'
3
2
  require 'dply/git'
4
3
  require 'dply/error'
5
4
 
6
-
7
5
  module Dply
8
6
  module Helper
9
7
 
data/lib/dply/linker.rb CHANGED
@@ -19,6 +19,7 @@ module Dply
19
19
  source = link_source(f)
20
20
  relative_source = link_relative_source(source, target)
21
21
  logger.debug "linking #{target} -> #{source}"
22
+ error "source #{source} doesn't exist" if not File.exist? source
22
23
  symlink(relative_source, target)
23
24
  end
24
25
  end
@@ -0,0 +1,63 @@
1
+ require 'set'
2
+ require 'yaml'
3
+ require 'dply/helper'
4
+
5
+ module Dply
6
+ class PkgsConfig
7
+
8
+ include Helper
9
+
10
+ def initialize(pkgs_yml = nil, build_mode: false)
11
+ @pkgs_yml = pkgs_yml || "pkgs.yml"
12
+ @build_mode = build_mode
13
+ @pkgs = Set.new
14
+ end
15
+
16
+ def pkgs
17
+ populate_all if not @populated
18
+ @pkgs
19
+ end
20
+
21
+ private
22
+
23
+ def config
24
+ @config ||= load_yml
25
+ end
26
+
27
+ def load_yml
28
+ if not File.readable? @pkgs_yml
29
+ logger.debug "skipping yum pkgs"
30
+ return {}
31
+ end
32
+ YAML.safe_load(File.read(@pkgs_yml))
33
+ rescue => e
34
+ error "error loading pkgs list"
35
+ end
36
+
37
+ def populate_all
38
+ populate :pkgs
39
+ populate :build_pkgs if @build_mode
40
+ @populated = true
41
+ end
42
+
43
+ def populate(pkg_set)
44
+ list = config[pkg_set.to_s] || []
45
+ list.each { |x| add x }
46
+ end
47
+
48
+ def add(pkg)
49
+ pkg = pkg.strip
50
+ validate! pkg
51
+ @pkgs << pkg
52
+ end
53
+
54
+ def validate!(pkg)
55
+ msg = "invalid pkg name #{pkg}"
56
+ error msg if pkg =~ /\.rpm\z/i
57
+ error msg if pkg =~/\A[A-Za-z_0-9\.\-]\z/
58
+ end
59
+
60
+ end
61
+ end
62
+
63
+
data/lib/dply/rpm.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'dply/helper'
2
+
3
+ module Dply
4
+ class Rpm
5
+ include Helper
6
+
7
+ def libs_to_packages(libs)
8
+ packages = Set.new
9
+ libs.each do |l|
10
+ lib = "#{l}()(64bit)"
11
+ command = %(rpm --queryformat "%{NAME} " -q --whatprovides "#{lib}")
12
+ logger.debug command
13
+ output = `#{command}`
14
+ error "running command #{command}" if not $?.exitstatus == 0
15
+ list = output.strip.split.select {|pkg| not filtered? pkg }
16
+ packages << list if not list.empty?
17
+ end
18
+ return packages
19
+ end
20
+
21
+ def filtered?(pkg)
22
+ @filtered ||= ["glibc", "libgcc", "libstdc++", "openssl", "ruby-alt"]
23
+ @filtered.include? pkg.strip
24
+ end
25
+
26
+ end
27
+ end
@@ -1,4 +1,5 @@
1
1
  require 'dply/helper'
2
+ require 'dply/tasks'
2
3
  require 'dply/setup'
3
4
  require 'dply/linker'
4
5
  require 'dply/config_downloader'
@@ -28,8 +29,8 @@ module Dply
28
29
  setup.archive
29
30
  download_configs if config_download_url
30
31
  install_release
31
- release.make_current
32
32
  previous_version = get_release
33
+ release.make_current
33
34
  Dir.chdir current_dir do
34
35
  tasks.deploy target
35
36
  end
@@ -53,6 +54,7 @@ module Dply
53
54
  end
54
55
 
55
56
  def get_release
57
+ return "NA" if not File.symlink? current_dir
56
58
  File.basename (File.readlink current_dir)
57
59
  end
58
60
 
@@ -77,14 +79,10 @@ module Dply
77
79
  Dir.chdir release.path do
78
80
  link_dirs
79
81
  link_config
80
- yum_install
82
+ tasks.install_pkgs(use_yum: options[:use_yum])
81
83
  end
82
84
  end
83
85
 
84
- def yum_install
85
- Yum.new("pkgs.yml").install
86
- end
87
-
88
86
  def git_step
89
87
  return if options[:skip_git]
90
88
  if options[:no_pull]
@@ -118,7 +116,6 @@ module Dply
118
116
  linker.create_symlinks
119
117
  end
120
118
 
121
-
122
119
  end
123
120
  end
124
121
  end
@@ -32,9 +32,9 @@ module Dply
32
32
  current_version = git.commit_id
33
33
  link_dirs
34
34
  link_config
35
- yum_install
35
+ install_pkgs
36
36
  tasks.deploy target
37
- # tasks.report_changes(previous_version, current_version)
37
+ tasks.report_changes(previous_version, current_version)
38
38
  end
39
39
  end
40
40
 
@@ -42,7 +42,7 @@ module Dply
42
42
  download_configs if config_download_url
43
43
  Dir.chdir current_dir do
44
44
  link_dirs
45
- link_config_files
45
+ link_config
46
46
  tasks.reload target
47
47
  end
48
48
  end
@@ -77,8 +77,8 @@ module Dply
77
77
  link "#{config.dir}/config", config_map
78
78
  end
79
79
 
80
- def yum_install
81
- Yum.new("pkgs.yml").install
80
+ def install_pkgs
81
+ tasks.install_pkgs(use_yum: options[:use_yum])
82
82
  end
83
83
 
84
84
  def setup
data/lib/dply/tasks.rb CHANGED
@@ -1,6 +1,9 @@
1
+ require 'json'
1
2
  require 'dply/shell'
2
3
  require 'dply/bundle'
3
- require 'json'
4
+ require 'dply/yum'
5
+ require 'dply/pkgs_config'
6
+
4
7
  module Dply
5
8
  class Tasks
6
9
 
@@ -39,7 +42,16 @@ module Dply
39
42
  info = {}
40
43
  info[:current] = current_version
41
44
  info[:previous] = previous_version
42
- logger.remote "#{JSON.dump info}"
45
+ logger.remote "#{previous_version} => #{current_version}"
46
+ end
47
+
48
+ def install_pkgs(build_mode: false, use_yum: false)
49
+ drake_exists = File.exists? (drake_command)
50
+ if use_yum || !drake_exists
51
+ yum_install build_mode
52
+ else
53
+ command_install build_mode
54
+ end
43
55
  end
44
56
 
45
57
  private
@@ -48,5 +60,20 @@ module Dply
48
60
  @bundle ||= Bundle.new(deployment: @deployment)
49
61
  end
50
62
 
63
+ def yum_install(build_mode)
64
+ pkgs = PkgsConfig.new(build_mode: build_mode).pkgs
65
+ Yum.new(pkgs, sudo: true).install
66
+ end
67
+
68
+ def command_install(build_mode)
69
+ command = "sudo -n #{drake_command} install-pkgs"
70
+ command << " -b" if build_mode
71
+ cmd command
72
+ end
73
+
74
+ def drake_command
75
+ @drake_command ||= (ENV["DRAKE_COMMAND"] || "/opt/ruby/bin/drake")
76
+ end
77
+
51
78
  end
52
79
  end
data/lib/dply/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dply
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/dply/yum.rb CHANGED
@@ -1,28 +1,31 @@
1
1
  require 'dply/helper'
2
- require 'yaml'
3
2
 
4
3
  module Dply
5
4
  class Yum
6
5
 
7
6
  include Helper
8
7
 
9
- def initialize(pkgs_yml)
10
- @pkgs_yml = pkgs_yml
11
- end
12
-
13
- def pkgs
14
- @pkgs ||= load_pkgs
8
+ def initialize(pkgs, sudo: false)
9
+ if pkgs.is_a? Set
10
+ @pkgs = pkgs.to_a
11
+ else
12
+ @pkgs = pkgs
13
+ end
14
+ @sudo = sudo
15
15
  end
16
16
 
17
17
  def install
18
18
  return if installed?
19
- cmd "sudo -n yum install -y #{not_installed_pkgs.join(' ')}"
19
+ command = ""
20
+ command << "sudo -n " if @sudo
21
+ command << "yum install -y #{not_installed_pkgs.join(' ')}"
22
+ cmd command
20
23
  end
21
24
 
22
25
  private
23
26
 
24
27
  def pkgs_str
25
- pkgs.join " "
28
+ @pkgs.join " "
26
29
  end
27
30
 
28
31
  def not_installed_pkgs
@@ -39,15 +42,5 @@ module Dply
39
42
  not_installed_pkgs.size == 0
40
43
  end
41
44
 
42
- def load_pkgs
43
- if not File.readable? @pkgs_yml
44
- logger.debug "skipping yum pkgs"
45
- return []
46
- end
47
- YAML.load_file(@pkgs_yml)
48
- rescue => e
49
- error "error loading pkgs list"
50
- end
51
-
52
45
  end
53
46
  end
@@ -1,11 +1,11 @@
1
- require 'dply/stages_config'
2
- require 'dply/remote_task'
1
+ require 'dplyr/stages_config'
2
+ require 'dplyr/remote_task'
3
3
  require 'dply/logger'
4
4
 
5
- module Dply
6
- class Dplyr
5
+ module Dplyr
6
+ class Cli
7
7
 
8
- include Logger
8
+ include ::Dply::Logger
9
9
 
10
10
  attr_reader :stage, :argv
11
11
  def initialize(stage, argv)
@@ -28,7 +28,7 @@ module Dply
28
28
  end
29
29
 
30
30
  def stage_data
31
- @stage_data ||= StagesConfig.new("stages.rb").get_stage(stage)
31
+ @stage_data ||= StagesConfig.new.fetch(@stage).data
32
32
  end
33
33
 
34
34
  def hosts
@@ -52,7 +52,7 @@ module Dply
52
52
  end
53
53
 
54
54
  def run_remote_task
55
- remote_task = ::Dply::RemoteTask.new(hosts, argv_str, parallel_jobs: parallel_jobs, env: env_str)
55
+ remote_task = RemoteTask.new(hosts, argv_str, parallel_jobs: parallel_jobs, env: env_str)
56
56
  remote_task.run
57
57
  end
58
58
 
@@ -1,11 +1,11 @@
1
1
  require 'pty'
2
- require 'dply/report'
2
+ require 'dplyr/report'
3
3
  require 'dply/logger'
4
4
 
5
- module Dply
5
+ module Dplyr
6
6
  class RemoteTask
7
7
 
8
- include Logger
8
+ include ::Dply::Logger
9
9
 
10
10
  attr_reader :hosts, :parallel_jobs, :task, :env
11
11
 
@@ -77,23 +77,28 @@ module Dply
77
77
  def remote_cmd(host_info)
78
78
  user = host_info[:user]
79
79
  host = host_info[:host]
80
- deploy_dir = host_info[:deploy_dir]
80
+ dir = host_info[:dir]
81
81
  if logger.debug?
82
- %(ssh -tt -oBatchMode=yes -l #{user} #{host} "#{env} drake --debug -d #{deploy_dir} #{task} 2>&1")
82
+ %(ssh -tt -oBatchMode=yes -l #{user} #{host} "#{env} drake --remote --debug -d #{dir} #{task} 2>&1")
83
83
  else
84
- %(ssh -tt -oBatchMode=yes -l #{user} #{host} "#{env} drake -d #{deploy_dir} #{task} 2>&1" 2>/dev/null)
84
+ %(ssh -tt -oBatchMode=yes -l #{user} #{host} "#{env} drake --remote -d #{dir} #{task} 2>&1" 2>/dev/null)
85
85
  end
86
86
  end
87
87
 
88
88
  def pty_read(file, id)
89
89
  file.each do |line|
90
- printf @job_output_template, id, line
90
+ if line =~ /\Adply_msg\|/
91
+ receive_message line
92
+ else
93
+ printf @job_output_template, id, line
94
+ end
91
95
  end
92
96
  rescue EOFError,Errno::ECONNRESET, Errno::EPIPE, Errno::EIO => e
93
97
  end
94
98
 
95
99
  def popen(cmd, host_info)
96
- t = Thread.new do
100
+ t = Thread.new do |t|
101
+ Thread.current[:messages] = []
97
102
  begin
98
103
  r, w, pid = PTY.spawn(cmd)
99
104
  pty_read(r, host_info[:id])
@@ -118,8 +123,25 @@ module Dply
118
123
  end
119
124
  end
120
125
 
126
+ def receive_message(msg_str)
127
+ msg = msg_str.partition("|")[2].strip
128
+ return if msg.empty?
129
+ messages = Thread.current[:messages]
130
+ messages << msg
131
+ end
132
+
121
133
  def report
122
- @report ||= Report.new(hosts, exit_statuses)
134
+ @report ||= Report.new(hosts, exit_statuses, messages)
135
+ end
136
+
137
+ def messages
138
+ @messages ||= begin
139
+ m = {}
140
+ @threads.each do |host, thread|
141
+ m[host] = thread[:messages]
142
+ end
143
+ m
144
+ end
123
145
  end
124
146
 
125
147
  def exit_statuses
@@ -1,11 +1,12 @@
1
- module Dply
1
+ module Dplyr
2
2
  class Report
3
3
 
4
4
  attr_reader :hosts, :exit_statuses
5
5
 
6
- def initialize(hosts, exit_statuses)
6
+ def initialize(hosts, exit_statuses, messages)
7
7
  @hosts = hosts
8
8
  @exit_statuses = exit_statuses
9
+ @messages = messages
9
10
  end
10
11
 
11
12
 
@@ -30,7 +31,10 @@ module Dply
30
31
  def print_successful_jobs
31
32
  puts "succeeded".green
32
33
  succeeded.each do |host|
33
- puts " - #{host[:id]}"
34
+ messages = @messages[host]
35
+ puts " - #{host[:id]}:"
36
+ next if not messages.is_a? Array
37
+ messages.each { |m| puts " #{m}"}
34
38
  end
35
39
  end
36
40
 
@@ -0,0 +1,68 @@
1
+ module Dplyr
2
+ class Stage
3
+
4
+ attr_accessor :config_proc
5
+
6
+ def initialize(name)
7
+ @name = name.to_sym
8
+ @hosts = []
9
+ @parallel_runs = 1
10
+ end
11
+
12
+ def data
13
+ finalize
14
+ return ({
15
+ parallel_runs: @parallel_runs,
16
+ hosts: @hosts,
17
+ env: {}
18
+ })
19
+ end
20
+
21
+ def host(host, user: nil, dir: nil, id: nil)
22
+ @hosts << ({
23
+ host: host,
24
+ user: user,
25
+ dir: dir,
26
+ id: id || host
27
+ })
28
+ end
29
+
30
+ def dir(dir)
31
+ @dir = dir
32
+ end
33
+
34
+ def user(user)
35
+ @user = user
36
+ end
37
+
38
+ def parallel_runs(parallel_runs)
39
+ @parallel_runs = parallel_runs
40
+ end
41
+
42
+ def fill_hosts
43
+ @hosts.each do |host|
44
+ host[:user] ||= fetch(:user)
45
+ host[:dir] ||= fetch(:dir)
46
+ end
47
+ end
48
+
49
+ alias_method :deploy_dir, :dir
50
+
51
+ def fetch(var)
52
+ value = instance_variable_get("@#{var}")
53
+ raise "error accessing var #{var} for stage #{name}" if not value
54
+ return value
55
+ end
56
+
57
+ def finalize
58
+ return if @finalized
59
+ instance_eval &config_proc if config_proc
60
+ fill_hosts
61
+ @hosts.freeze
62
+ @parallel_runs.freeze
63
+ @finalized = true
64
+ end
65
+
66
+ end
67
+ end
68
+
@@ -0,0 +1,39 @@
1
+ require 'dply/helper'
2
+ require 'dplyr/stage'
3
+
4
+ module Dplyr
5
+ class StagesConfig
6
+
7
+ include ::Dply::Helper
8
+ attr_reader :config_file
9
+ attr_accessor :current_stage
10
+
11
+ def initialize(config_file = nil)
12
+ @config_file = config_file || "stages.rb"
13
+ @stages = {}
14
+ end
15
+
16
+ def stage(name, &block)
17
+ name = name.to_sym
18
+ stage = Stage.new(name)
19
+ stage.config_proc = block
20
+ @stages[name] = stage
21
+ end
22
+
23
+ def read_from_file
24
+ return if @read
25
+ error "#{config_file} not readable" if not File.readable? config_file
26
+ instance_eval(File.read(config_file), config_file)
27
+ rescue NoMethodError => e
28
+ error "invalid option used in config: #{e.name} #{e.message}"
29
+ ensure
30
+ @read = true
31
+ end
32
+
33
+ def fetch(stage)
34
+ read_from_file
35
+ @stages[stage.to_sym]
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require 'dply/helper'
2
+ module Dplyr
3
+ class TasksConfig
4
+
5
+ include ::Dply::Helper
6
+
7
+ def initialize(config_file)
8
+ @config_file = config_file || "tasks.rb"
9
+ @tasks = {}
10
+ end
11
+
12
+ def task(name, &block)
13
+ @tasks[name.to_sym] = block
14
+ end
15
+
16
+ def get_task
17
+
18
+ end
19
+
20
+ private
21
+
22
+ def read_from_file
23
+ if not File.readable? @config_file
24
+ error "#{config_file} not readable"
25
+ return
26
+ end
27
+ instance_eval(File.read(config_file), config_file)
28
+ rescue NoMethodError => e
29
+ error "invalid option used in config: #{e.name} #{e.message}"
30
+ end
31
+
32
+ end
33
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dply
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neeraj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-elf
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-filemagic
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -51,6 +79,7 @@ files:
51
79
  - LICENSE.txt
52
80
  - README.md
53
81
  - Rakefile
82
+ - TODO
54
83
  - bin/dplyr
55
84
  - bin/drake
56
85
  - code_dump/alt_remote_task.rb
@@ -67,13 +96,15 @@ files:
67
96
  - lib/dply/build_config.rb
68
97
  - lib/dply/bundle.rb
69
98
  - lib/dply/cli/build.rb
99
+ - lib/dply/cli/depcheck.rb
70
100
  - lib/dply/cli/deploy.rb
101
+ - lib/dply/cli/install_pkgs.rb
71
102
  - lib/dply/cli/reload.rb
72
103
  - lib/dply/config.rb
73
104
  - lib/dply/config_downloader.rb
74
105
  - lib/dply/config_struct.rb
75
106
  - lib/dply/custom_logger.rb
76
- - lib/dply/dplyr.rb
107
+ - lib/dply/deplist.rb
77
108
  - lib/dply/error.rb
78
109
  - lib/dply/ext/string.rb
79
110
  - lib/dply/git.rb
@@ -82,20 +113,25 @@ files:
82
113
  - lib/dply/linker.rb
83
114
  - lib/dply/lock.rb
84
115
  - lib/dply/logger.rb
116
+ - lib/dply/pkgs_config.rb
85
117
  - lib/dply/release.rb
86
- - lib/dply/remote_task.rb
87
118
  - lib/dply/repo.rb
88
- - lib/dply/report.rb
119
+ - lib/dply/rpm.rb
89
120
  - lib/dply/setup.rb
90
121
  - lib/dply/shared_dirs.rb
91
122
  - lib/dply/shell.rb
92
- - lib/dply/stages_config.rb
93
123
  - lib/dply/strategy.rb
94
124
  - lib/dply/strategy/archive.rb
95
125
  - lib/dply/strategy/git.rb
96
126
  - lib/dply/tasks.rb
97
127
  - lib/dply/version.rb
98
128
  - lib/dply/yum.rb
129
+ - lib/dplyr/cli.rb
130
+ - lib/dplyr/remote_task.rb
131
+ - lib/dplyr/report.rb
132
+ - lib/dplyr/stage.rb
133
+ - lib/dplyr/stages_config.rb
134
+ - lib/dplyr/tasks_config.rb
99
135
  homepage: ''
100
136
  licenses:
101
137
  - MIT
@@ -1,103 +0,0 @@
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 || host
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 ask(key)
76
- print "Enter #{key}: "
77
- value = STDIN.gets.chomp
78
- env = get_from_current_stage(:env)
79
- env[key] = value
80
- end
81
-
82
- def init_stage(name)
83
- stages[name] = {
84
- hosts: [],
85
- parallel_runs: 1,
86
- env: {}
87
- }
88
- end
89
-
90
-
91
- def read_from_file
92
- if not File.readable? config_file
93
- error "#{config_file} not readable"
94
- return
95
- end
96
- instance_eval(File.read(config_file), config_file)
97
- rescue NoMethodError => e
98
- error "invalid option used in config: #{e.name} #{e.message}"
99
- end
100
-
101
-
102
- end
103
- end