vx-builder 0.0.28 → 0.0.29

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: 84b253cffa5e036ddd0fb814840cf117f33f282f
4
- data.tar.gz: d2d046cb4c403a212810654fd4b9dfe7a35a07e1
3
+ metadata.gz: 2f04d4731464414b121f1418f4fada916c797e3b
4
+ data.tar.gz: 1d7c01fe5104d38d215cfb806245943376d8d39a
5
5
  SHA512:
6
- metadata.gz: 05d0a7efa18bd2bd798703874cc8604e33e0debf81df8219bb082a576f01984ee747247c8200560994a05d5df0d3052a38d5dde190657c52696d031e71444edf
7
- data.tar.gz: e95b0904223534d3ae08b96cf7c51429d1a337ce1a109bd0191598245dde5738744948aed6a96e4c6252967796ffa0301f828055f15648ee47292f7cda0188d3
6
+ metadata.gz: 54df9e7aa3c473ae2564e07b4f8bf4acd6917d98c46bdd551bdbddda5c88b22bd2d5501891f66a0e8f916f84b2763336e85e6f0e862ff16594bdcaeb51c0bbb6
7
+ data.tar.gz: 527e9b0e283e7976ed50e04b7dede18412345711165f9bfbb9098624c823c282b31a507e3a5d68586e0693d816081152b440a8ae368afb283a2f1fcb268c2098
@@ -0,0 +1,38 @@
1
+ module Vx
2
+ module Builder
3
+ class BuildConfiguration
4
+ class Artifacts
5
+
6
+ attr_reader :attributes
7
+
8
+ def initialize(new_env)
9
+ normalize_attributes(new_env)
10
+ end
11
+
12
+ def artifacts
13
+ @attributes
14
+ end
15
+
16
+ private
17
+
18
+ def normalize_attributes(new_env)
19
+
20
+ @attributes =
21
+ case new_env
22
+ when Array
23
+ new_env.map(&:to_s)
24
+ else
25
+ Array(new_env).map(&:to_s)
26
+ end
27
+
28
+ @attributes.map! do |attr|
29
+ attr.gsub(/^\.*(\/)/, '')
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -37,13 +37,15 @@ module Vx
37
37
  end
38
38
  end
39
39
 
40
- attr_reader :env, :cache
40
+ attr_reader :env, :cache, :artifacts
41
41
 
42
42
  def initialize(new_attributes = {}, matrix_attributes = {})
43
43
  new_attributes = {} unless new_attributes.is_a?(Hash)
44
44
 
45
- @env = Env.new(new_attributes["env"])
46
- @cache = Cache.new(new_attributes["cache"])
45
+ @env = Env.new(new_attributes["env"])
46
+ @cache = Cache.new(new_attributes["cache"])
47
+ @artifacts = Artifacts.new(new_attributes["artifacts"])
48
+
47
49
  @matrix_attributes = matrix_attributes
48
50
 
49
51
  build_attributes new_attributes
@@ -68,8 +70,9 @@ module Vx
68
70
  end
69
71
 
70
72
  def to_hash
71
- attributes.merge("env" => env.attributes)
72
- .merge("cache" => cache.attributes)
73
+ attributes.merge("env" => env.attributes)
74
+ .merge("cache" => cache.attributes)
75
+ .merge("artifacts" => artifacts.attributes)
73
76
  end
74
77
 
75
78
  def to_yaml
@@ -0,0 +1,111 @@
1
+ module Vx
2
+ module Builder
3
+ class Script
4
+
5
+ Artifacts = Struct.new(:app) do
6
+
7
+ include Helper::TraceShCommand
8
+
9
+ FIND='find . -type f -path "./%s" | sed "s/^\.\///g"'
10
+
11
+ def call(env)
12
+ rs = app.call env
13
+
14
+ if enabled?(env)
15
+ env.after_success << "echo"
16
+ env.source.artifacts.attributes.map{|a| compile(a) }.each do |artifact|
17
+ find = FIND % artifact
18
+ prefix = env.task.artifacts_url_prefix
19
+ cmd = %{
20
+ for i in $(#{find}) ; do
21
+ echo "upload artifact $i"
22
+ curl -s -S -X PUT -T $i #{prefix}/$i > /dev/null
23
+ done
24
+ }
25
+ env.after_success << cmd
26
+ end
27
+ env.after_success << "echo"
28
+ end
29
+
30
+ rs
31
+ end
32
+
33
+ private
34
+
35
+ def compile(artifact)
36
+ case
37
+ when artifact.end_with?("/")
38
+ "#{artifact}*"
39
+ else
40
+ artifact
41
+ end
42
+ end
43
+
44
+ def enabled?(env)
45
+ !env.source.artifacts.attributes.empty? &&
46
+ env.task.artifacts_url_prefix
47
+ end
48
+
49
+ def casher_cmd
50
+ "test -f #{CASHER_BIN} && #{config.casher_ruby} #{CASHER_BIN}"
51
+ end
52
+
53
+ def assign_url_to_env(env)
54
+ urls = []
55
+ branch = env.task.branch
56
+ if branch != 'master'
57
+ urls << url_for(env, branch)
58
+ end
59
+ urls << url_for(env, 'master')
60
+
61
+ env.cache_fetch_url = urls
62
+ env.cache_push_url = url_for(env, branch)
63
+ env
64
+ end
65
+
66
+ def url_for(env, branch)
67
+ name = branch
68
+
69
+ key =
70
+ if env.cache_key.empty?
71
+ "cache"
72
+ else
73
+ env.cache_key.join("-").downcase.gsub(/[^a-z0-9_\-.]/, '-')
74
+ end
75
+
76
+ "#{env.task.cache_url_prefix}/#{name}/#{key}.tgz"
77
+ end
78
+
79
+ def prepare(env)
80
+ cmd = %{
81
+ export CASHER_DIR=$HOME/.casher &&
82
+ ( mkdir -p $CASHER_DIR/bin &&
83
+ /usr/bin/curl #{CASHER_URL} -s -o #{CASHER_BIN} &&
84
+ chmod +x #{CASHER_BIN} ) ||
85
+ true
86
+ }.gsub(/\n/, ' ').gsub(/ +/, ' ')
87
+ env.init << cmd
88
+ end
89
+
90
+ def fetch(env)
91
+ urls = env.cache_fetch_url.join(" ")
92
+ env.init << "#{casher_cmd} fetch #{urls} || true"
93
+ end
94
+
95
+ def add(env)
96
+ env.cached_directories.each do |d|
97
+ env.init << "#{casher_cmd} add #{d} || true"
98
+ end
99
+ env.init << "unset CASHER_DIR"
100
+ end
101
+
102
+ def push(env)
103
+ if env.cache_push_url
104
+ env.after_script << "#{casher_cmd} push #{env.cache_push_url}"
105
+ end
106
+ end
107
+
108
+ end
109
+ end
110
+ end
111
+ end
@@ -17,7 +17,7 @@ module Vx
17
17
  env.script << trace_sh_command(c)
18
18
  end
19
19
  env.source.after_success.each do |c|
20
- env.script << trace_sh_command(c)
20
+ env.after_success << trace_sh_command(c)
21
21
  end
22
22
  app.call(env)
23
23
  end
@@ -14,11 +14,13 @@ module Vx
14
14
  autoload :Databases, File.expand_path("../script/databases", __FILE__)
15
15
  autoload :Cache, File.expand_path("../script/cache", __FILE__)
16
16
  autoload :Services, File.expand_path("../script/services", __FILE__)
17
+ autoload :Artifacts, File.expand_path("../script/artifacts", __FILE__)
17
18
 
18
19
  include Common::Helper::Middlewares
19
20
 
20
21
  middlewares do
21
22
  use Builder::Script::Cache
23
+ use Builder::Script::Artifacts
22
24
  use Builder::Script::Env
23
25
  use Builder::Script::Services
24
26
  use Builder::Script::Prepare
@@ -70,6 +72,10 @@ module Vx
70
72
  a = []
71
73
  a << "\n# script"
72
74
  a += env.script
75
+
76
+ a << "\n# after success"
77
+ a += env.after_success
78
+
73
79
  a.join("\n")
74
80
  end
75
81
 
@@ -95,6 +101,7 @@ module Vx
95
101
 
96
102
  before_script: [],
97
103
  script: [],
104
+ after_success: [],
98
105
  after_script: [],
99
106
 
100
107
  source: source,
@@ -3,16 +3,17 @@ module Vx
3
3
  class Task
4
4
 
5
5
  attr_reader :name, :src, :sha, :deploy_key, :branch, :pull_request_id,
6
- :cache_url_prefix
6
+ :cache_url_prefix, :artifacts_url_prefix
7
7
 
8
8
  def initialize(name, src, sha, options = {})
9
- @name = name
10
- @src = src
11
- @sha = sha
12
- @deploy_key = options[:deploy_key]
13
- @branch = options[:branch]
14
- @pull_request_id = options[:pull_request_id]
15
- @cache_url_prefix = options[:cache_url_prefix]
9
+ @name = name
10
+ @src = src
11
+ @sha = sha
12
+ @deploy_key = options[:deploy_key]
13
+ @branch = options[:branch]
14
+ @pull_request_id = options[:pull_request_id]
15
+ @cache_url_prefix = options[:cache_url_prefix]
16
+ @artifacts_url_prefix = options[:artifacts_url_prefix]
16
17
 
17
18
  validate!
18
19
  end
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module Builder
3
- VERSION = "0.0.28"
3
+ VERSION = "0.0.29"
4
4
  end
5
5
  end
@@ -30,3 +30,7 @@ cache:
30
30
  directories:
31
31
  - ~/.cache
32
32
 
33
+ artifacts:
34
+ - ../app/foo.txt
35
+ - /app/*.txt
36
+ - app/
@@ -42,7 +42,8 @@ describe Vx::Builder::BuildConfiguration do
42
42
  "rvm" => ["2.0.0"],
43
43
  "scala" => ['2.10.3'],
44
44
  "script" => ["RAILS_ENV=test ls -1 && echo DONE!"],
45
- "services" => ['rabbitmq']
45
+ "services" => ['rabbitmq'],
46
+ "artifacts" => ["app/foo.txt", "app/*.txt", "app/"]
46
47
  }
47
48
  ) }
48
49
  end
@@ -96,4 +97,13 @@ describe Vx::Builder::BuildConfiguration do
96
97
  end
97
98
  end
98
99
 
100
+ context "artifacts" do
101
+ subject { config.artifacts }
102
+
103
+ context "when is empty" do
104
+ let(:content) { {} }
105
+ its(:attributes) { should eq [] }
106
+ end
107
+ end
108
+
99
109
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::Builder::Script::Artifacts do
4
+ let(:app) { ->(env) { 0 } }
5
+ let(:script) { described_class.new app }
6
+ let(:task) { }
7
+ let(:env) { create :env }
8
+ let(:run) { script.call env }
9
+ subject { run }
10
+
11
+ it { should eq 0 }
12
+
13
+ it "should create upload script" do
14
+ subject
15
+ expect(env.after_success).to_not be_empty
16
+ end
17
+
18
+ end
@@ -13,7 +13,8 @@ def create(name, options = {})
13
13
  msg.sha,
14
14
  deploy_key: msg.deploy_key,
15
15
  branch: msg.branch,
16
- cache_url_prefix: "http://example.com/"
16
+ cache_url_prefix: "http://example.com/",
17
+ artifacts_url_prefix: "http://example.com/"
17
18
  )
18
19
 
19
20
  when :source
@@ -30,6 +31,7 @@ def create(name, options = {})
30
31
  script: [],
31
32
  after_script: [],
32
33
  source: options[:source] || create(:source),
34
+ after_success: [],
33
35
  task: create(:task),
34
36
  cache_key: [],
35
37
  cached_directories: []
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-10 00:00:00.000000000 Z
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vx-common
@@ -124,6 +124,7 @@ files:
124
124
  - Rakefile
125
125
  - lib/vx/builder.rb
126
126
  - lib/vx/builder/build_configuration.rb
127
+ - lib/vx/builder/build_configuration/artifacts.rb
127
128
  - lib/vx/builder/build_configuration/cache.rb
128
129
  - lib/vx/builder/build_configuration/env.rb
129
130
  - lib/vx/builder/configuration.rb
@@ -131,6 +132,7 @@ files:
131
132
  - lib/vx/builder/helper/trace_sh_command.rb
132
133
  - lib/vx/builder/matrix.rb
133
134
  - lib/vx/builder/script.rb
135
+ - lib/vx/builder/script/artifacts.rb
134
136
  - lib/vx/builder/script/cache.rb
135
137
  - lib/vx/builder/script/clojure.rb
136
138
  - lib/vx/builder/script/env.rb
@@ -150,6 +152,7 @@ files:
150
152
  - spec/lib/builder/build_configuration_spec.rb
151
153
  - spec/lib/builder/configuration_spec.rb
152
154
  - spec/lib/builder/matrix_spec.rb
155
+ - spec/lib/builder/script/artifacts_spec.rb
153
156
  - spec/lib/builder/script/cache_spec.rb
154
157
  - spec/lib/builder/script/clojure_spec.rb
155
158
  - spec/lib/builder/script/env_spec.rb
@@ -197,6 +200,7 @@ test_files:
197
200
  - spec/lib/builder/build_configuration_spec.rb
198
201
  - spec/lib/builder/configuration_spec.rb
199
202
  - spec/lib/builder/matrix_spec.rb
203
+ - spec/lib/builder/script/artifacts_spec.rb
200
204
  - spec/lib/builder/script/cache_spec.rb
201
205
  - spec/lib/builder/script/clojure_spec.rb
202
206
  - spec/lib/builder/script/env_spec.rb