volley 0.1.0.alpha9 → 0.1.0.alpha10

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.
data/Rakefile CHANGED
@@ -9,6 +9,12 @@ require 'volley'
9
9
  desc 'Default: run specs.'
10
10
  task :default => :test
11
11
 
12
+ task :uninstall do
13
+ exec "gem uninstall -a -x volley"
14
+ end
15
+
16
+ ### TEST STUFF
17
+
12
18
  desc "Run specs"
13
19
  RSpec::Core::RakeTask.new(:spec) do |t|
14
20
  t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
data/bin/volley CHANGED
@@ -33,6 +33,7 @@ Options:
33
33
  -d --debug show debug output, change log level to debug
34
34
  -c --config FILE load additional Volleyfile [default: ~/.Volleyfile]
35
35
  -p --primary FILE load primary Volleyfile [default: ./Volleyfile]
36
+ -F --force force operations (redeploy version, republish artifact)
36
37
 
37
38
  -f --fork fork process into background and exit
38
39
  -l --log LOG log file [default: /opt/volley/volley.log]
@@ -53,6 +54,8 @@ module Volley
53
54
  fork = options[:fork]
54
55
  log = options[:log]
55
56
  level = options[:level]
57
+ force = options[:force]
58
+ args = {}
56
59
 
57
60
  Volley::Dsl::VolleyFile.init
58
61
  Volley::Dsl::VolleyFile.load(config, :optional => true)
@@ -79,6 +82,9 @@ module Volley
79
82
  plan = "#{project}:#{plan}"
80
83
  end
81
84
 
85
+ args = kvs.inject({}) {|h, e| (k, v) = e.split(/=/); h[k.to_sym] = v; h }
86
+ args[:force] = force
87
+
82
88
  if debug
83
89
  Volley::Log.debug "## OPTIONS ##"
84
90
  Volley::Log.debug "plan: #{plan}"
@@ -88,9 +94,9 @@ module Volley
88
94
  end
89
95
 
90
96
  Volley::Log.info "processing '#{plan}' plan for '#{desc}'"
91
- Volley.process(:plan => plan, :descriptor => desc, :args => kvs)
97
+ Volley.process(plan, desc, args)
92
98
  rescue => e
93
- Volley::Log.error "exception: #{e.message} at #{e.backtrace.first}"
99
+ Volley::Log.error "error: #{e.message} at #{e.backtrace.first}"
94
100
  if debug
95
101
  Volley::Log.error e
96
102
  else
@@ -34,16 +34,6 @@ project :volley do
34
34
  default do
35
35
  (project, branch, version) = args.descriptor.get
36
36
 
37
- if project.nil? && argv.count
38
- first = argv.first
39
- (p, b, v) = first.split(/\//) if first
40
- if p
41
- project = p
42
- branch = b
43
- version = v
44
- end
45
- end
46
-
47
37
  pub = Volley::Dsl.publisher
48
38
  data = []
49
39
  if args.all
@@ -2,13 +2,13 @@ def publish(desc)
2
2
  pwd = Dir.pwd
3
3
  Dir.chdir("test/project")
4
4
  Volley::Dsl::VolleyFile.load("Volleyfile")
5
- Volley.process(:plan => "publish", :descriptor => desc)
5
+ Volley.process("publish", desc, {})
6
6
  Dir.chdir(pwd)
7
7
  end
8
8
 
9
9
  def deploy(desc)
10
10
  pwd = Dir.pwd
11
- Volley.process(:plan => "deploy", :descriptor => desc)
11
+ Volley.process("deploy", desc, {})
12
12
  Dir.chdir(pwd)
13
13
  end
14
14
 
@@ -13,9 +13,7 @@ module Volley
13
13
  raise "error parsing descriptor: #{desc}" if (list.count < 2 || list.count > 3) && !@options[:partial]
14
14
  (@project, @branch, @version) = list
15
15
  @version ||= "latest"
16
- #if @version.nil? || @version == "latest"
17
- # @version = Volley.publisher.latest(@project, @branch).split("/").last || nil rescue nil
18
- #end
16
+
19
17
  raise "error parsing descriptor: #{desc}" unless (@project && @branch && @version) || @options[:partial]
20
18
  end
21
19
  end
@@ -29,7 +27,7 @@ module Volley
29
27
  end
30
28
 
31
29
  def to_s
32
- "#@project@#@branch#{":#@version" unless @version == "latest"}"
30
+ "#@project@#@branch:#@version"
33
31
  end
34
32
  end
35
33
  end
@@ -45,6 +45,7 @@ module Volley
45
45
  end
46
46
 
47
47
  def call(options={ })
48
+ @mode = @name.to_s =~ /deploy/i ? :deploy : :publish
48
49
  Volley::Log.debug "## #{@project.name} : #@name"
49
50
  @origargs = options[:args]
50
51
  data = @origargs
@@ -59,6 +60,14 @@ module Volley
59
60
  [branch, version].join(":")
60
61
  end
61
62
 
63
+ def deploying?
64
+ @mode == :deploy
65
+ end
66
+
67
+ def publishing?
68
+ @mode == :publish
69
+ end
70
+
62
71
  def usage
63
72
  out = []
64
73
  @arguments.each do |n, arg|
@@ -87,7 +96,7 @@ module Volley
87
96
  end
88
97
 
89
98
  def remote(tf)
90
- raise "remote can only be set to true or false" unless [true,false].include?(tf)
99
+ raise "remote can only be set to true or false" unless [true, false].include?(tf)
91
100
  @attributes.remote = tf
92
101
  end
93
102
 
@@ -97,8 +106,18 @@ module Volley
97
106
 
98
107
  def version
99
108
  v = args.descriptor ? args.descriptor.version : nil
100
- if v == "latest"
101
- v = source.revision || nil
109
+ if v.nil? || v == "latest"
110
+ v = begin
111
+ if deploying?
112
+ Volley::Dsl.publisher.latest_version(args.descriptor.project, args.descriptor.branch) || v
113
+ elsif publishing?
114
+ source.revision || v
115
+ end
116
+ rescue => e
117
+ Volley::Log.debug "failed to get version? #{v.inspect} : #{e.message}"
118
+ Volley::Log.debug e
119
+ v
120
+ end
102
121
  end
103
122
  v
104
123
  end
@@ -197,16 +216,11 @@ module Volley
197
216
  private
198
217
  def process_arguments(raw)
199
218
  Volley::Log.debug ".. process arguments: #{raw.inspect}"
200
- if raw
201
- kvs = raw.select { |e| e =~ /\=/ }
202
- raw = raw.reject { |e| e =~ /\=/ }
203
- @argv = raw
204
- kvs.each do |a|
205
- (k, v) = a.split(/\=/)
206
- if @arguments[k.to_sym]
207
- Volley::Log.debug ".. .. setting argument: #{k} = #{v}"
208
- @arguments[k.to_sym].value = v
209
- end
219
+ @argv = raw
220
+ raw.each do |k, v|
221
+ if @arguments[k.to_sym]
222
+ Volley::Log.debug ".. .. setting argument: #{k} = #{v}"
223
+ @arguments[k.to_sym].value = v
210
224
  end
211
225
  end
212
226
  @arguments.each do |k, v|
data/lib/volley/meta.rb CHANGED
@@ -3,20 +3,33 @@ module Volley
3
3
  class Meta
4
4
  def initialize(file="#{Volley.config.directory}/meta.yaml")
5
5
  @file = file
6
- raise "file does not exist" unless File.file?(@file)
7
- @data = YAML.load_file(@file)
6
+ dir = File.dirname(file)
7
+ unless File.directory?(dir)
8
+ Volley::Log.warn "meta file directory does not exist: #{dir}"
9
+ FileUtils.mkdir_p(dir)
10
+ end
11
+ @data = YAML.load_file(@file) || {} rescue {}
8
12
  end
9
13
 
10
14
  def [](project)
11
- @data[project.to_sym]
15
+ @data[:projects] ||= {}
16
+ @data[:projects][project.to_sym]
12
17
  end
13
18
 
14
19
  def []=(project, version)
15
- @data[project.to_sym] = version
20
+ @data[:projects] ||= {}
21
+ @data[:projects][project.to_sym] = version
16
22
  end
17
23
 
18
24
  def save
19
- File.open(@file, "w") {|f| f.write(@data.to_yaml)}
25
+ @data[:volley] ||= {}
26
+ @data[:volley][:version] = Volley::Version::STRING
27
+ File.open(@file, "w+") {|f| f.write(@data.to_yaml)}
28
+ end
29
+
30
+ def check(project, branch, version)
31
+ version = Volley::Dsl.publisher.latest_version(project, branch) if version.nil? || version == 'latest'
32
+ self[project] == "#{branch}:#{version}"
20
33
  end
21
34
  end
22
35
  end
@@ -5,6 +5,10 @@ module Volley
5
5
  class Amazons3 < Base
6
6
  attr_accessor :key, :secret
7
7
 
8
+ def all
9
+ files[:all]
10
+ end
11
+
8
12
  def projects
9
13
  files[:desc].keys
10
14
  rescue => e
@@ -76,10 +80,10 @@ module Volley
76
80
 
77
81
  contents = f.body
78
82
 
83
+ log "<= #{dir}/#{file}"
79
84
  if localdir
80
85
  FileUtils.mkdir_p(localdir)
81
86
  local = "#{localdir}/#{file}"
82
- log "<= #{local}"
83
87
  File.open(local, "w") { |lf| lf.write(contents) }
84
88
  else
85
89
  contents
@@ -115,10 +119,6 @@ module Volley
115
119
  #ap hash
116
120
  hash
117
121
  end
118
-
119
- def all
120
- files[:all]
121
- end
122
122
  end
123
123
  end
124
124
  end
@@ -43,11 +43,15 @@ module Volley
43
43
  @latest["#{project}/#{branch}"] ||= pull_file(dir(project,branch), "latest")
44
44
  end
45
45
 
46
+ def latest_version(project, branch)
47
+ latest(project, branch).split("/").last
48
+ end
49
+
46
50
  def volleyfile(project, branch, version="latest")
47
51
  d = dir(project,branch,version)
48
52
  contents = pull_file(d, "Volleyfile")
49
53
 
50
- dest = "#{@options[:local]}/Volleyfile-#{Time.now.to_i}-#{$$}"
54
+ dest = "#@local/Volleyfile-#{Time.now.to_i}-#{$$}"
51
55
  raise "File #{dest} already exists" if File.exists?(dest)
52
56
 
53
57
  log "saving Volleyfile: #{dest}"
@@ -129,7 +133,7 @@ module Volley
129
133
  end
130
134
 
131
135
  def dir(project, branch, version=nil)
132
- version = version == 'latest' ? latest(project, branch).split("/").last : version
136
+ version = version == 'latest' ? latest_version(project, branch) : version
133
137
  [project, branch, version].compact.join("/")
134
138
  end
135
139
 
@@ -2,6 +2,10 @@ module Volley
2
2
  module Publisher
3
3
  class Local < Base
4
4
 
5
+ def all
6
+ #TODO: make this work like the S3 version
7
+ end
8
+
5
9
  def projects
6
10
  l = Dir["#@directory/*"]
7
11
  l.map {|e| e.gsub(/#@directory\//,"")}
@@ -41,7 +45,6 @@ module Volley
41
45
 
42
46
  def load_configuration
43
47
  @directory = requires(:directory)
44
- @local = requires(:local)
45
48
  @debug = optional(:debug, false)
46
49
  end
47
50
 
@@ -62,9 +65,10 @@ module Volley
62
65
  def pull_file(dir, file, localdir=nil)
63
66
  remote = "#@directory/#{dir}"
64
67
  raise ArtifactMissing, "missing: #{remote}" unless File.exists?("#{remote}/#{file}")
68
+
69
+ log "<= #@local/#{dir}/#{file}"
65
70
  if localdir
66
71
  FileUtils.mkdir_p(localdir)
67
- log "<= #@local/#{dir}/#{file}"
68
72
  FileUtils.copy("#{remote}/#{file}", "#@local/#{dir}")
69
73
  else
70
74
  File.read("#{remote}/#{file}")
data/lib/volley.rb CHANGED
@@ -29,11 +29,8 @@ module Volley
29
29
  Volley::Dsl::Project.unload
30
30
  end
31
31
 
32
- def process(opts)
33
- plan = opts[:plan]
34
- args = opts[:args] || []
35
- desc = opts[:descriptor]
36
- second = opts[:second]
32
+ def process(plan, desc, args)
33
+ second = args.delete(:second)
37
34
 
38
35
  (runpr, plan) = plan.split(/:/) if plan =~ /\:/
39
36
  (project, branch, version) = Volley::Descriptor.new(desc).get rescue [nil,nil,nil]
@@ -43,32 +40,40 @@ module Volley
43
40
  if Volley::Dsl.project?(runpr)
44
41
  # we have the project locally
45
42
  pr = Volley::Dsl.project(runpr)
43
+
46
44
  if pr.plan?(plan)
47
45
  # plan is defined
48
- pl = pr.plan(plan)
49
- args << "descriptor=#{desc}"
50
- data = pl.call(:args => args)
46
+
47
+ if plan == "deploy" && Volley.meta.check(project, branch, version) && !args[:force]
48
+ raise "project #{project} is already #{branch}:#{version}"
49
+ end
50
+
51
+ args[:descriptor] = desc
52
+ data = pr.plan(plan).call(:args => args)
51
53
 
52
54
  if plan == "deploy"
53
55
  Volley.meta[project] = data
56
+ Volley::Log.debug "== #{runpr} = #{data}"
54
57
  end
55
58
  Volley.meta.save
56
- Volley::Log.debug "== #{runpr} = #{data}"
57
59
  else
58
60
  # plan is not defined
59
61
  raise "could not find plan #{plan} in project #{project}"
60
62
  end
61
63
  else
62
- raise "second loop, downloaded volleyfile failed?" if second
63
64
  # we dont have the project locally, search the publisher
65
+ raise "second loop, downloaded volleyfile failed?" if second
66
+
64
67
  pub = Volley::Dsl.publisher
65
68
  if pub
66
69
  if pub.projects.include?(project) && branch
67
70
  vf = pub.volleyfile(project, branch, version)
68
- version = pub.latest(project, branch).split("/").last if version.nil? || version == "latest"
71
+ version = pub.latest_version(project, branch) if version.nil? || version == "latest"
72
+
69
73
  Volley::Log.debug "downloaded volleyfile: #{vf}"
70
74
  Volley::Dsl::VolleyFile.load(vf)
71
- process(:plan => "#{project}:#{plan}", :descriptor => "#{project}@#{branch}:#{version}", :args => args, :second => true)
75
+ args[:second] = true
76
+ process("#{project}:#{plan}", desc.to_s, args)
72
77
  else
73
78
  raise "project #{project} does not exist in configured publisher #{pub.class}"
74
79
  end
@@ -77,8 +82,8 @@ module Volley
77
82
  end
78
83
  end
79
84
  rescue => e
80
- Volley::Log.error "error while processing: #{e.message}"
81
- Volley::Log.debug e
85
+ #Volley::Log.error "error while processing: #{e.message}"
86
+ #Volley::Log.debug e
82
87
  raise e
83
88
  end
84
89
  end
@@ -18,7 +18,9 @@ describe Volley::Descriptor do
18
18
  expect(d).not_to be(nil)
19
19
  expect(d.project).to eq(project)
20
20
  expect(d.branch).to eq(branch)
21
- expect(d.version).to eq(version)
21
+ if version != "latest"
22
+ expect(d.version).to eq(version)
23
+ end
22
24
  end
23
25
  end
24
26
 
@@ -58,33 +58,33 @@ describe Volley::Dsl::Plan do
58
58
  it "should handle arguments" do
59
59
  @plan.argument(:testarg)
60
60
  expect(@plan.arguments.count).to eq(2) # descriptor and testarg
61
- @plan.call(:args => ["descriptor=test@trunk/1","testarg=true"])
61
+ @plan.call(:args => {:descriptor => "test@trunk/1",:testarg => "true"})
62
62
  expect(@plan.args.testarg).to eq("true")
63
63
  end
64
64
 
65
65
  it "should handle arguments (with remote false)" do
66
66
  @notremote.argument(:testarg)
67
67
  expect(@notremote.arguments.count).to eq(2) # descriptor and testarg
68
- @notremote.call(:args => ["testarg=true"])
68
+ @notremote.call(:args => {:testarg => "true"})
69
69
  expect(@notremote.args.testarg).to eq("true")
70
70
  end
71
71
 
72
72
  # boolean as strings because we test conversion later
73
73
  it "should handle argument defaults" do
74
74
  @plan.argument(:testarg, :default => "false")
75
- expect {@plan.call(:args => ["descriptor=test@trunk/2"])}.not_to raise_exception
75
+ expect {@plan.call(:args => {:descriptor => "test@trunk/2"})}.not_to raise_exception
76
76
  expect(@plan.args.testarg).to eq("false")
77
77
  end
78
78
 
79
79
  # boolean as strings because we test conversion later
80
80
  it "should handle arguments overriding defaults" do
81
81
  @plan.argument(:testarg, :default => "false")
82
- expect {@plan.call(:args => ["descriptor=test@trunk/3","testarg=true"])}.not_to raise_exception
82
+ expect {@plan.call(:args => {:descriptor => "test@trunk/3",:testarg => "true"})}.not_to raise_exception
83
83
  expect(@plan.args.testarg).to eq("true")
84
84
  end
85
85
 
86
86
  it "should fail if required arguments aren't specified" do
87
- expect {@plan.call(:args => [])}.to raise_exception
87
+ expect {@plan.call(:args => {})}.to raise_exception
88
88
  end
89
89
 
90
90
  [
@@ -96,7 +96,7 @@ describe Volley::Dsl::Plan do
96
96
  (type, original, value) = arg
97
97
  it "should handle converting argument: #{type}" do
98
98
  @plan.argument(type, :convert => type.to_sym)
99
- @plan.call(:args => ["descriptor=test@trunk/6","#{type}=#{original}"])
99
+ @plan.call(:args => {:descriptor => "test@trunk/6",type.to_sym => "#{original}"})
100
100
  expect(@plan.args.send(type.to_sym)).to eq(value)
101
101
  end
102
102
  end
@@ -9,7 +9,7 @@ Volley::Log.console_disable
9
9
  shared_examples_for Volley::Publisher::Base do
10
10
  before(:all) do
11
11
  @remote = "#{root}/test/publisher/remote"
12
- @local = "#{root}/test/publisher/local"
12
+ @local = "/opt/volley"
13
13
  FileUtils.mkdir_p(@remote)
14
14
  FileUtils.mkdir_p(@local)
15
15
  [@local, @remote].each { |d| %x{rm -rf #{d}/*} }
@@ -76,7 +76,7 @@ describe Volley::Publisher::Local do
76
76
  it_behaves_like Volley::Publisher::Base
77
77
 
78
78
  before(:each) do
79
- @pub = Volley::Publisher::Local.new(:directory => @remote, :local => @local)
79
+ @pub = Volley::Publisher::Local.new(:directory => @remote)
80
80
  end
81
81
  end
82
82
 
@@ -86,7 +86,6 @@ describe Volley::Publisher::Amazons3 do
86
86
  before(:each) do
87
87
  @pub = Volley::Publisher::Amazons3.new(:aws_access_key_id => "AKIAIWUGNGSUZWW5XVCQ",
88
88
  :aws_secret_access_key => "NOggEVauweMiJDWyRIlgikEAtlwnFAzd8ZSL13Lt",
89
- :bucket => "inqcloud-volley-test",
90
- :local => @local)
89
+ :bucket => "inqcloud-volley-test")
91
90
  end
92
91
  end
data/test/meta.yml CHANGED
@@ -1,3 +1,4 @@
1
1
 
2
- :spec: trunk:2
3
- :test: staging:3
2
+ :projects:
3
+ :spec: trunk:2
4
+ :test: staging:3
data/volley.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "volley"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = "#{Volley::Version::STRING}.alpha9"
16
+ gem.version = "#{Volley::Version::STRING}.alpha10"
17
17
 
18
18
  gem.add_dependency "clamp"
19
19
  gem.add_dependency "fog"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha9
4
+ version: 0.1.0.alpha10
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-07 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clamp