vx-builder 0.2.2 → 0.3.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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vx/builder.rb +15 -2
  3. data/lib/vx/builder/build_configuration.rb +12 -13
  4. data/lib/vx/builder/build_configuration/deploy.rb +10 -17
  5. data/lib/vx/builder/build_configuration/deploy/base.rb +64 -0
  6. data/lib/vx/builder/build_configuration/deploy/shell.rb +21 -0
  7. data/lib/vx/builder/build_configuration/env.rb +11 -4
  8. data/lib/vx/builder/deploy_builder.rb +59 -0
  9. data/lib/vx/builder/{matrix.rb → matrix_builder.rb} +8 -20
  10. data/lib/vx/builder/script_builder.rb +127 -0
  11. data/lib/vx/builder/script_builder/base.rb +59 -0
  12. data/lib/vx/builder/{script/base.rb → script_builder/base.rb-e} +13 -10
  13. data/lib/vx/builder/{script/artifacts.rb → script_builder/cache.rb} +13 -30
  14. data/lib/vx/builder/{script/cache.rb → script_builder/cache.rb-e} +0 -0
  15. data/lib/vx/builder/script_builder/clojure.rb +34 -0
  16. data/lib/vx/builder/{script/clojure.rb → script_builder/clojure.rb-e} +0 -0
  17. data/lib/vx/builder/script_builder/deploy.rb +34 -0
  18. data/lib/vx/builder/script_builder/deploy.rb-e +34 -0
  19. data/lib/vx/builder/script_builder/env.rb +39 -0
  20. data/lib/vx/builder/{script/env.rb → script_builder/env.rb-e} +0 -0
  21. data/lib/vx/builder/script_builder/java.rb +31 -0
  22. data/lib/vx/builder/{script/java.rb → script_builder/java.rb-e} +0 -0
  23. data/lib/vx/builder/script_builder/prepare.rb +72 -0
  24. data/lib/vx/builder/{script/prepare.rb → script_builder/prepare.rb-e} +0 -0
  25. data/lib/vx/builder/script_builder/ruby.rb +80 -0
  26. data/lib/vx/builder/{script/ruby.rb → script_builder/ruby.rb-e} +0 -0
  27. data/lib/vx/builder/script_builder/scala.rb +50 -0
  28. data/lib/vx/builder/{script/scala.rb → script_builder/scala.rb-e} +0 -0
  29. data/lib/vx/builder/script_builder/script.rb +32 -0
  30. data/lib/vx/builder/script_builder/script.rb-e +32 -0
  31. data/lib/vx/builder/script_builder/services.rb +26 -0
  32. data/lib/vx/builder/{script/services.rb → script_builder/services.rb-e} +0 -0
  33. data/lib/vx/builder/task.rb +1 -7
  34. data/lib/vx/builder/version.rb +1 -1
  35. data/spec/fixtures/integration/ruby/deploy/config.yml +6 -2
  36. data/spec/fixtures/integration/ruby/deploy/d.after_script.sh +1 -1
  37. data/spec/fixtures/integration/ruby/deploy/d.before_script.sh +3 -1
  38. data/spec/fixtures/integration/ruby/deploy/d.script.sh +6 -2
  39. data/spec/fixtures/integration/ruby/matrix/config.yml +4 -1
  40. data/spec/fixtures/integration/ruby/matrix/d.after_script.sh +1 -1
  41. data/spec/fixtures/integration/ruby/matrix/d.before_script.sh +1 -1
  42. data/spec/fixtures/integration/ruby/matrix/d.script.sh +6 -2
  43. data/spec/fixtures/travis.yml +2 -7
  44. data/spec/integration/ruby_spec.rb +14 -19
  45. data/spec/lib/builder/build_configuration/cache_spec.rb +35 -0
  46. data/spec/lib/builder/build_configuration/deploy/base_spec.rb +33 -0
  47. data/spec/lib/builder/build_configuration/deploy/shell_spec.rb +61 -0
  48. data/spec/lib/builder/build_configuration/deploy_spec.rb +50 -0
  49. data/spec/lib/builder/build_configuration/env_spec.rb +43 -0
  50. data/spec/lib/builder/build_configuration_spec.rb +4 -124
  51. data/spec/lib/builder/deploy_builder_spec.rb +82 -0
  52. data/spec/lib/builder/{matrix_spec.rb → matrix_builder_spec.rb} +9 -67
  53. data/spec/lib/builder/{script → script_builder}/cache_spec.rb +1 -1
  54. data/spec/lib/builder/{script → script_builder}/clojure_spec.rb +1 -1
  55. data/spec/lib/builder/{script → script_builder}/env_spec.rb +1 -1
  56. data/spec/lib/builder/{script → script_builder}/java_spec.rb +1 -1
  57. data/spec/lib/builder/{script → script_builder}/prepare_spec.rb +2 -2
  58. data/spec/lib/builder/{script → script_builder}/ruby_spec.rb +1 -1
  59. data/spec/lib/builder/{script → script_builder}/scala_spec.rb +1 -1
  60. data/spec/lib/builder/{script_spec.rb → script_builder_spec.rb} +1 -1
  61. data/spec/lib/builder/task_spec.rb +0 -2
  62. data/spec/support/create.rb +24 -11
  63. metadata +59 -38
  64. data/lib/vx/builder/build_configuration/artifacts.rb +0 -68
  65. data/lib/vx/builder/build_configuration/deploy/provider.rb +0 -58
  66. data/lib/vx/builder/script.rb +0 -145
  67. data/lib/vx/builder/script/deploy.rb +0 -40
  68. data/lib/vx/builder/script/script.rb +0 -39
  69. data/spec/lib/builder/script/artifacts_spec.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77885525e3428656f31703eadeaae66bada00a79
4
- data.tar.gz: bb410c3d75561213d19d39b7406672fcddd35b96
3
+ metadata.gz: 4931a543965ca9828a090a0d2fee1cec1e7bedca
4
+ data.tar.gz: 916c04fd44e0df9dbb26ed7de24fe356fc58660a
5
5
  SHA512:
6
- metadata.gz: 00e81d97fc6b8e3a19a3a7828f65c271667cf269f548e77753e39b6bdfd9e2a34acecd8b80568e7a0de15aaf89e76909db10fe88a451675a4063d12bc48ea11c
7
- data.tar.gz: ac02d67d24d4e6869c8f27a137ea6cd22bdd4c89292bb3d311773fefee039bfaa7bd721d77e74827400b59a1cac3658c24fb54180ca052e4f63633a752a4e083
6
+ metadata.gz: fa0e9cc22069c4d13042252a10d08dbeb356ab81800d1dccae33e77504dfe57f062a9ba3b4c1565a8f09e71ce189f8112f0588b77d8542660eb1e6b83db4e44e
7
+ data.tar.gz: 1e7a835fbfbf8d4b254bfaab6de087b4ecec84ee16cf7407c1ff38c055254c17ca5648b54f264c97f2c1bd8ce161a2afcb1f03395dfbe8b3a6b5680d23379456
data/lib/vx/builder.rb CHANGED
@@ -3,11 +3,12 @@ require File.expand_path("../builder/version", __FILE__)
3
3
  module Vx
4
4
  module Builder
5
5
  autoload :Source, File.expand_path("../builder/source", __FILE__)
6
- autoload :Script, File.expand_path("../builder/script", __FILE__)
7
6
  autoload :Task, File.expand_path("../builder/task", __FILE__)
8
7
  autoload :Configuration, File.expand_path("../builder/configuration", __FILE__)
9
8
  autoload :BuildConfiguration, File.expand_path("../builder/build_configuration", __FILE__)
10
- autoload :Matrix, File.expand_path("../builder/matrix", __FILE__)
9
+ autoload :MatrixBuilder, File.expand_path("../builder/matrix_builder", __FILE__)
10
+ autoload :DeployBuilder, File.expand_path("../builder/deploy_builder", __FILE__)
11
+ autoload :ScriptBuilder, File.expand_path("../builder/script_builder", __FILE__)
11
12
 
12
13
  module Helper
13
14
  autoload :Config, File.expand_path("../builder/helper/config", __FILE__)
@@ -31,5 +32,17 @@ module Vx
31
32
  @config = nil
32
33
  end
33
34
 
35
+ def matrix(build_configuration)
36
+ MatrixBuilder.new(build_configuration)
37
+ end
38
+
39
+ def deploy(matrix_builder, options = {})
40
+ DeployBuilder.new(matrix_builder, options)
41
+ end
42
+
43
+ def script(task, build_configuration)
44
+ ScriptBuilder.new task, build_configuration
45
+ end
46
+
34
47
  end
35
48
  end
@@ -41,15 +41,15 @@ module Vx
41
41
  end
42
42
  end
43
43
 
44
- attr_reader :env, :cache, :artifacts, :deploy, :attributes
44
+ attr_reader :env, :cache, :deploy, :attributes, :deploy_modules
45
45
 
46
46
  def initialize(new_attributes = {}, matrix_attributes = {})
47
47
  new_attributes = {} unless new_attributes.is_a?(Hash)
48
48
 
49
- @env = Env.new(new_attributes["env"])
50
- @cache = Cache.new(new_attributes["cache"])
51
- @artifacts = Artifacts.new(new_attributes["artifacts"])
52
- @deploy = Deploy.new(new_attributes["deploy"])
49
+ @env = Env.new new_attributes.delete("env")
50
+ @cache = Cache.new new_attributes.delete("cache")
51
+ @deploy = Deploy.new new_attributes.delete("deploy")
52
+ @deploy_modules = new_attributes.delete("deploy_modules") || []
53
53
 
54
54
  @matrix_attributes = matrix_attributes
55
55
 
@@ -70,11 +70,11 @@ module Vx
70
70
  end
71
71
 
72
72
  def deploy?
73
- !deploy.attributes.empty?
73
+ deploy.attributes.any?
74
74
  end
75
75
 
76
- def deploy_attributes= (val)
77
- @deploy = Deploy.new(val)
76
+ def deploy_modules?
77
+ deploy_modules.any?
78
78
  end
79
79
 
80
80
  # for tests
@@ -83,10 +83,9 @@ module Vx
83
83
  end
84
84
 
85
85
  def to_hash
86
- attributes.merge("env" => env.attributes)
87
- .merge("cache" => cache.attributes)
88
- .merge("artifacts" => artifacts.attributes)
89
- .merge("deploy" => deploy.attributes)
86
+ attributes.merge("env" => env.attributes)
87
+ .merge("cache" => cache.attributes)
88
+ .merge("deploy" => deploy.attributes)
90
89
  end
91
90
 
92
91
  def to_yaml
@@ -102,7 +101,7 @@ module Vx
102
101
  end
103
102
 
104
103
  def cached_directories
105
- @cache.enabled? and @cache.directories
104
+ cache.enabled? and cache.directories
106
105
  end
107
106
 
108
107
  (ATTRIBUTES - %w{ language }).each do |attr|
@@ -13,10 +13,16 @@ module Vx
13
13
  @attributes
14
14
  end
15
15
 
16
- def providers
17
- @providers ||= @attributes.map do |a|
18
- Deploy::Provider.new(a)
16
+ def find_modules(branch)
17
+ modules = []
18
+ Base.loaded.each do |l|
19
+ attributes.each do |attr|
20
+ if l.detect(attr)
21
+ modules << l.new(attr)
22
+ end
23
+ end
19
24
  end
25
+ modules.select{ |m| m.branch?(branch) }
20
26
  end
21
27
 
22
28
  private
@@ -28,8 +34,6 @@ module Vx
28
34
  new_env
29
35
  when Hash
30
36
  [new_env]
31
- when String
32
- [new_env]
33
37
  else
34
38
  []
35
39
  end
@@ -39,18 +43,7 @@ module Vx
39
43
 
40
44
  def normalize_each(new_env)
41
45
  @attributes = []
42
- new_env.each do |env|
43
- case env
44
- when Hash
45
- if env["provider"]
46
- @attributes.push env
47
- else
48
- @attributes.push env.merge("provider" => "shell")
49
- end
50
- when String
51
- @attributes.push("provider" => "shell", "command" => env)
52
- end
53
- end
46
+ @attributes = new_env.select{|i| i.is_a?(Hash) }
54
47
  end
55
48
 
56
49
  end
@@ -0,0 +1,64 @@
1
+ module Vx
2
+ module Builder
3
+ class BuildConfiguration
4
+ class Deploy
5
+
6
+ class Base
7
+
8
+ class << self
9
+
10
+ @@loaded = []
11
+
12
+ def loaded
13
+ @@loaded
14
+ end
15
+
16
+ def provide(val)
17
+ loaded.push self
18
+ @key = val
19
+ end
20
+
21
+ def key
22
+ @key
23
+ end
24
+
25
+ def detect(params)
26
+ params.key?(key.to_s) if key
27
+ end
28
+ end
29
+
30
+ attr_reader :params, :branch
31
+
32
+ def initialize(params)
33
+ @params = params.is_a?(Hash) ? params : {}
34
+ self.branch = params["branch"]
35
+ end
36
+
37
+ def branch=(value)
38
+ @branch = Array(value).map(&:to_s)
39
+ end
40
+
41
+ def branch?(name)
42
+ if branch.empty?
43
+ true
44
+ else
45
+ branch.include?(name)
46
+ end
47
+ end
48
+
49
+ def key
50
+ if self.class.key
51
+ Array(params[self.class.key.to_s])
52
+ end
53
+ end
54
+
55
+ def to_commands
56
+ nil
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path("../base", __FILE__)
2
+
3
+ module Vx
4
+ module Builder
5
+ class BuildConfiguration
6
+ class Deploy
7
+
8
+ class Shell < Base
9
+
10
+ provide :shell
11
+
12
+ def to_commands
13
+ key.map(&:to_s)
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -23,16 +23,23 @@ module Vx
23
23
 
24
24
  @attributes =
25
25
  case new_env
26
+ when String
27
+ {
28
+ "matrix" => [],
29
+ "global" => Array(new_env)
30
+ }
26
31
  when Hash
27
32
  {
28
33
  "matrix" => Array(new_env['matrix']),
29
34
  "global" => Array(new_env['global'])
30
35
  }
31
36
  else
32
- {
33
- "matrix" => Array(new_env).flatten.map(&:to_s),
34
- "global" => []
35
- }
37
+ env = Array(new_env).flatten.map(&:to_s)
38
+ if env.size == 1
39
+ { "matrix" => [], "global" => env }
40
+ else
41
+ { "matrix" => env, "global" => [] }
42
+ end
36
43
  end
37
44
 
38
45
  end
@@ -0,0 +1,59 @@
1
+ module Vx
2
+ module Builder
3
+ class DeployBuilder
4
+
5
+ BLACK_LIST = %w{
6
+ image
7
+ before_script
8
+ after_success
9
+ script
10
+ }
11
+
12
+ attr_reader :base_build_configuration, :matrix_build_configuration, :branch
13
+
14
+ def initialize(matrix_builder, options = {})
15
+ @base_build_configuration = matrix_builder.build_configuration
16
+ @matrix_build_configuration = matrix_builder.build.first
17
+ @branch = options[:branch]
18
+ end
19
+
20
+ def build
21
+ @build ||= begin
22
+ return false unless valid?
23
+
24
+ hash = matrix_build_configuration.to_hash
25
+
26
+ BLACK_LIST.each do |key|
27
+ hash.delete key
28
+ end
29
+
30
+ hash["env"]["matrix"] = []
31
+
32
+ BuildConfiguration.new(
33
+ hash.merge(
34
+ "deploy_modules" => deploy_modules,
35
+ "deploy" => nil
36
+ )
37
+ )
38
+ end
39
+ end
40
+
41
+ def valid?
42
+ deploy? and deploy_modules.any?
43
+ end
44
+
45
+ def deploy_modules
46
+ @deploy_modules ||= deploy.find_modules(branch)
47
+ end
48
+
49
+ def deploy
50
+ base_build_configuration.deploy
51
+ end
52
+
53
+ def deploy?
54
+ deploy.attributes.any?
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -1,6 +1,6 @@
1
1
  module Vx
2
2
  module Builder
3
- Matrix = Struct.new(:build_configuration) do
3
+ MatrixBuilder = Struct.new(:build_configuration) do
4
4
 
5
5
  KEYS = %w{
6
6
  rvm
@@ -16,24 +16,12 @@ module Vx
16
16
  extract_keys_from_builds_configuration.map(&:first).sort
17
17
  end
18
18
 
19
- def build_configurations
20
- new_attributes = build_configuration.to_hash.dup
21
- attributes_for_new_build_configurations_with_merged_env.map do |matrix_attributes|
22
- new_attributes.merge!(matrix_attributes)
23
- BuildConfiguration.new new_attributes, matrix_attributes
24
- end
25
- end
26
-
27
- def deploy_configuration(branch)
28
- return unless build_configuration.deploy?
29
-
30
- availabled_providers = build_configuration.deploy.providers.select do |provider|
31
- provider.branch?(branch)
32
- end
33
-
34
- unless availabled_providers.empty?
35
- build_configurations.first.dup.tap do |config|
36
- config.deploy_attributes = availabled_providers.map(&:to_hash)
19
+ def build
20
+ @build ||= begin
21
+ new_attributes = build_configuration.to_hash.dup
22
+ attributes_for_new_build_configurations_with_merged_env.map do |matrix_attributes|
23
+ new_attributes.merge!(matrix_attributes)
24
+ BuildConfiguration.new new_attributes, matrix_attributes
37
25
  end
38
26
  end
39
27
  end
@@ -44,7 +32,7 @@ module Vx
44
32
  attrs.map! do |a|
45
33
  env = a["env"]
46
34
  a["env"] = {
47
- "global" => Array(env) + build_configuration.env.global,
35
+ "global" => build_configuration.env.global,
48
36
  "matrix" => Array(env)
49
37
  }
50
38
  a
@@ -0,0 +1,127 @@
1
+ require 'vx/common'
2
+
3
+ module Vx
4
+ module Builder
5
+ class ScriptBuilder
6
+
7
+ autoload :Base, File.expand_path("../script_builder/base", __FILE__)
8
+ autoload :Env, File.expand_path("../script_builder/env", __FILE__)
9
+ autoload :Ruby, File.expand_path("../script_builder/ruby", __FILE__)
10
+ autoload :Java, File.expand_path("../script_builder/java", __FILE__)
11
+ autoload :Scala, File.expand_path("../script_builder/scala", __FILE__)
12
+ autoload :Clojure, File.expand_path("../script_builder/clojure", __FILE__)
13
+ autoload :Script, File.expand_path("../script_builder/script", __FILE__)
14
+ autoload :Prepare, File.expand_path("../script_builder/prepare", __FILE__)
15
+ autoload :Databases, File.expand_path("../script_builder/databases", __FILE__)
16
+ autoload :Cache, File.expand_path("../script_builder/cache", __FILE__)
17
+ autoload :Services, File.expand_path("../script_builder/services", __FILE__)
18
+ autoload :Deploy, File.expand_path("../script_builder/deploy", __FILE__)
19
+
20
+ include Common::Helper::Middlewares
21
+
22
+ middlewares do
23
+ use Builder::ScriptBuilder::Cache
24
+ use Builder::ScriptBuilder::Env
25
+ use Builder::ScriptBuilder::Services
26
+ use Builder::ScriptBuilder::Prepare
27
+ use Builder::ScriptBuilder::Java
28
+ use Builder::ScriptBuilder::Scala
29
+ use Builder::ScriptBuilder::Clojure
30
+ use Builder::ScriptBuilder::Ruby
31
+ use Builder::ScriptBuilder::Deploy
32
+ use Builder::ScriptBuilder::Script
33
+ end
34
+
35
+ attr_reader :source, :task
36
+
37
+ def initialize(task, source)
38
+ @source = source
39
+ @task = task
40
+ end
41
+
42
+ def image
43
+ source.image.first
44
+ end
45
+
46
+ def to_before_script
47
+ a = []
48
+ a << "\n# init"
49
+ a += env.init
50
+
51
+ a << "\n# before install"
52
+ a += env.before_install
53
+
54
+ a << "\n# announce"
55
+ a += env.announce
56
+
57
+ a << "\n# install"
58
+ a += env.install
59
+
60
+ a << "\n# before script"
61
+ a += env.before_script
62
+
63
+ a.join("\n")
64
+ end
65
+
66
+ def to_after_script
67
+ a = []
68
+ a << "\n# after script init"
69
+ a += env.after_script_init
70
+
71
+ a << "\n# after script"
72
+ a += env.after_script
73
+ a.join("\n")
74
+ end
75
+
76
+ def to_script
77
+ a = []
78
+
79
+ a << "\n# script"
80
+ a += env.script
81
+
82
+ a << "\n# after success"
83
+ a += env.after_success
84
+
85
+ a.join("\n")
86
+ end
87
+
88
+ private
89
+
90
+ def env
91
+ @env ||= run_middlewares(default_env) {|_| _ }
92
+ end
93
+
94
+ def default_env
95
+ OpenStruct.new(
96
+ # initialization, repo does not exists
97
+ init: [],
98
+
99
+ # before instalation, using for system setup
100
+ before_install: [],
101
+
102
+ # instalation, using for application setup
103
+ install: [],
104
+
105
+ # announce software and services version
106
+ announce: [],
107
+
108
+ before_script: [],
109
+ script: [],
110
+ after_success: [],
111
+
112
+ after_script_init: [],
113
+ after_script: [],
114
+
115
+ before_deploy: [],
116
+ deploy: [],
117
+
118
+ source: source,
119
+ task: task,
120
+ cache_key: [],
121
+ cached_directories: []
122
+ )
123
+ end
124
+
125
+ end
126
+ end
127
+ end