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
@@ -0,0 +1,59 @@
1
+ module Vx
2
+ module Builder
3
+ class ScriptBuilder
4
+
5
+ Base = Struct.new(:app) do
6
+
7
+ include Helper::TraceShCommand
8
+
9
+ def do_cache_key(env)
10
+ yield env.cache_key
11
+ end
12
+
13
+ def do_script(env)
14
+ if env.source.script.empty? && !env.source.deploy_modules?
15
+ yield env.script
16
+ end
17
+ end
18
+
19
+ def do_cached_directories(env)
20
+ if env.source.cached_directories != false
21
+ yield env.cached_directories
22
+ end
23
+ end
24
+
25
+ def do_announce(env)
26
+ yield env.announce
27
+ end
28
+
29
+ def do_before_install(env)
30
+ yield env.before_install
31
+ end
32
+
33
+ def do_install(env)
34
+ yield env.install
35
+ end
36
+
37
+ def do_deploy_script(env)
38
+ if env.source.deploy_modules?
39
+ yield env.script
40
+ end
41
+ end
42
+
43
+ def do_before_deploy(env)
44
+ if env.source.deploy_modules?
45
+ yield env.before_script
46
+ end
47
+ end
48
+
49
+ def do_after_deploy(env)
50
+ if env.source.deploy_modules?
51
+ yield env.after_success
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -11,7 +11,7 @@ module Vx
11
11
  end
12
12
 
13
13
  def do_script(env)
14
- if env.source.script.empty?
14
+ if env.source.script.empty? && !env.source.deploy_modules?
15
15
  yield env.script
16
16
  end
17
17
  end
@@ -34,21 +34,24 @@ module Vx
34
34
  yield env.install
35
35
  end
36
36
 
37
- def do_before_deploy(env)
38
- yield env.before_deploy
37
+ def do_deploy_script(env)
38
+ if env.source.deploy_modules?
39
+ yield env.script
40
+ end
39
41
  end
40
42
 
41
- def do_after_deploy(env)
42
- yield env.after_deploy
43
+ def do_before_deploy(env)
44
+ if env.source.deploy_modules?
45
+ yield env.before_script
46
+ end
43
47
  end
44
48
 
45
- def do_deploy(env)
46
- yield env.deploy
49
+ def do_after_deploy(env)
50
+ if env.source.deploy_modules?
51
+ yield env.after_success
52
+ end
47
53
  end
48
54
 
49
- def deploy?
50
- env.task.deploy?
51
- end
52
55
  end
53
56
 
54
57
  end
@@ -1,30 +1,23 @@
1
1
  module Vx
2
2
  module Builder
3
- class Script
3
+ class ScriptBuilder
4
4
 
5
- class Artifacts < Base
5
+ Cache = Struct.new(:app) do
6
6
 
7
- FIND='find . -type f -path "./%s" | sed "s/^\.\///g"'
7
+ include Helper::Config
8
+
9
+ CASHER_URL = "https://raw2.github.com/dima-exe/casher/master/bin/casher"
10
+ CASHER_BIN = "$HOME/.casher/bin/casher"
8
11
 
9
12
  def call(env)
10
13
  rs = app.call env
11
14
 
12
- if enabled?(env)
13
- env.after_script << "echo"
14
- env.source.artifacts.files.map{|a| compile(a) }.each do |artifact|
15
- find = FIND % artifact
16
- url = env.task.artifacts_url_prefix
17
- prefix = env.source.artifacts.prefix
18
- name = prefix ? "#{prefix}$i" : "$i"
19
- cmd = %{
20
- for i in $(#{find}) ; do
21
- echo "upload artifact #{name}"
22
- curl -s -S -X PUT -T $i #{url}/#{name} > /dev/null
23
- done
24
- }
25
- env.after_script << cmd
26
- end
27
- env.after_script << "echo"
15
+ if env.task.cache_url_prefix && enabled?(env)
16
+ assign_url_to_env(env)
17
+ prepare(env)
18
+ fetch(env)
19
+ add(env)
20
+ push(env)
28
21
  end
29
22
 
30
23
  rs
@@ -32,18 +25,8 @@ module Vx
32
25
 
33
26
  private
34
27
 
35
- def compile(artifact)
36
- case
37
- when artifact.end_with?("/")
38
- "#{artifact}*"
39
- else
40
- artifact
41
- end
42
- end
43
-
44
28
  def enabled?(env)
45
- !env.source.artifacts.files.empty? &&
46
- env.task.artifacts_url_prefix
29
+ !env.cached_directories.empty?
47
30
  end
48
31
 
49
32
  def casher_cmd
@@ -0,0 +1,34 @@
1
+ module Vx
2
+ module Builder
3
+ class ScriptBuilder
4
+
5
+ class Clojure < Base
6
+
7
+ def call(env)
8
+ if enabled?(env)
9
+ do_announce(env) do |i|
10
+ i << trace_sh_command("lein version")
11
+ end
12
+
13
+ do_install(env) do |i|
14
+ i << trace_sh_command("lein deps")
15
+ end
16
+
17
+ do_script(env) do |i|
18
+ i << trace_sh_command("lein test")
19
+ end
20
+ end
21
+
22
+ app.call(env)
23
+ end
24
+
25
+ private
26
+
27
+ def enabled?(env)
28
+ env.source.language == 'clojure'
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ module Vx
2
+ module Builder
3
+ class ScriptBuilder
4
+
5
+ class Deploy < Base
6
+
7
+ def call(env)
8
+ do_before_deploy(env) do |e|
9
+ env.source.before_deploy.each do |c|
10
+ e << trace_sh_command(c)
11
+ end
12
+ end
13
+
14
+ do_deploy_script(env) do |e|
15
+ env.source.deploy_modules.each do |m|
16
+ m.to_commands.each do |c|
17
+ e << trace_sh_command(c)
18
+ end
19
+ end
20
+ end
21
+
22
+ do_after_deploy(env) do |e|
23
+ env.source.after_deploy.each do |c|
24
+ e << trace_sh_command(c)
25
+ end
26
+ end
27
+
28
+ app.call(env)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ module Vx
2
+ module Builder
3
+ class Script
4
+
5
+ class Deploy < Base
6
+
7
+ def call(env)
8
+ do_before_deploy(env) do |e|
9
+ env.source.before_deploy.each do |c|
10
+ e << trace_sh_command(c)
11
+ end
12
+ end
13
+
14
+ do_deploy_script(env) do |e|
15
+ env.source.deploy_modules.each do |m|
16
+ m.to_commands.each do |c|
17
+ e << trace_sh_command(c)
18
+ end
19
+ end
20
+ end
21
+
22
+ do_after_deploy(env) do |e|
23
+ env.source.after_deploy.each do |c|
24
+ e << trace_sh_command(c)
25
+ end
26
+ end
27
+
28
+ app.call(env)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ module Vx
2
+ module Builder
3
+ class ScriptBuilder
4
+
5
+ class Env < Base
6
+
7
+ def call(env)
8
+ env.init << "set -e"
9
+ env.init << "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
10
+ env.init << 'export LC_ALL=en_US.UTF8'
11
+ env.init << 'export DEBIAN_FRONTEND=noninteractive'
12
+
13
+ export_vars(env, env.init)
14
+ export_vars(env, env.after_script_init)
15
+
16
+ env.source.env.global.each do |e|
17
+ env.init << trace_sh_command("export #{e}")
18
+ end
19
+ env.source.env.matrix.each do |e|
20
+ env.init << trace_sh_command("export #{e}")
21
+ end
22
+ app.call(env)
23
+ end
24
+
25
+ private
26
+
27
+ def export_vars(env, collection)
28
+ collection << "export CI_JOB_ID=#{env.task.job_id}"
29
+ collection << "export CI_BUILD_ID=#{env.task.build_id}"
30
+
31
+ if b = env.task.branch
32
+ collection << "export CI_BRANCH=#{b}"
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ module Vx
2
+ module Builder
3
+ class ScriptBuilder
4
+
5
+ class Java < Base
6
+
7
+ def call(env)
8
+ if java(env)
9
+ do_cache_key(env) do |i|
10
+ i << "jdk-#{java env}"
11
+ end
12
+
13
+ do_before_install(env) do |i|
14
+ i << "source $(which jdk_switcher.sh)"
15
+ i << trace_sh_command("jdk_switcher use #{java env}")
16
+ end
17
+ end
18
+
19
+ app.call(env)
20
+ end
21
+
22
+ private
23
+
24
+ def java(env)
25
+ env.source.jdk.first
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,72 @@
1
+ require 'vx/common'
2
+
3
+ module Vx
4
+ module Builder
5
+ class ScriptBuilder
6
+
7
+ Prepare = Struct.new(:app) do
8
+
9
+ include Helper::TraceShCommand
10
+ include Common::Helper::UploadShCommand
11
+
12
+ def call(env)
13
+ name = env.task.name
14
+ deploy_key = env.task.deploy_key
15
+
16
+ repo_path = "${VX_ROOT}/code/#{name}"
17
+ data_path = "${VX_ROOT}/data/#{name}"
18
+ key_file = "#{data_path}/key"
19
+ git_ssh_file = "#{data_path}/git_ssh"
20
+
21
+ sha = env.task.sha
22
+ scm = build_scm(env, sha, repo_path)
23
+ git_ssh = scm.git_ssh_content(deploy_key && "#{key_file}")
24
+
25
+ env.init.tap do |i|
26
+ i << 'export VX_ROOT=$(pwd)'
27
+
28
+ i << "mkdir -p #{data_path}"
29
+ i << "mkdir -p #{repo_path}"
30
+
31
+ if deploy_key
32
+ i << upload_sh_command(key_file, deploy_key)
33
+ i << "chmod 0600 #{key_file}"
34
+ i << "export VX_PRIVATE_KEY=#{key_file}"
35
+ end
36
+
37
+ i << upload_sh_command(git_ssh_file, git_ssh)
38
+ i << "chmod 0750 #{git_ssh_file}"
39
+
40
+ i << "export GIT_SSH=#{git_ssh_file}"
41
+ i << scm.fetch_cmd
42
+ i << "unset GIT_SSH"
43
+
44
+ i << 'echo "Starting SSH Agent"'
45
+ i << 'eval "$(ssh-agent)"'
46
+ i << "ssh-add $VX_PRIVATE_KEY"
47
+
48
+ i << "cd #{repo_path}"
49
+ end
50
+
51
+ env.after_script_init.tap do |i|
52
+ i << 'export VX_ROOT=$(pwd)'
53
+ i << "cd #{repo_path}"
54
+ end
55
+
56
+ app.call env
57
+ end
58
+
59
+ private
60
+
61
+ def build_scm(env, sha, path)
62
+ Common::Git.new(env.task.src,
63
+ sha,
64
+ path,
65
+ branch: env.task.branch,
66
+ pull_request_id: env.task.pull_request_id)
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,80 @@
1
+ module Vx
2
+ module Builder
3
+ class ScriptBuilder
4
+
5
+ class Ruby < Base
6
+
7
+ DEFAULT_RUBY = '1.9.3'
8
+
9
+ def call(env)
10
+ if enabled?(env)
11
+ do_cache_key(env) do |i|
12
+ i << "rvm-#{ruby env}"
13
+ i << gemfile(env)
14
+ end
15
+
16
+ do_before_install(env) do |i|
17
+ i << 'eval "$(rbenv init -)" || true'
18
+ i << "rbenv shell #{make_rbenv_version_command env}"
19
+ i << trace_sh_command("export BUNDLE_GEMFILE=${PWD}/#{gemfile(env)}")
20
+ i << trace_sh_command('export GEM_HOME=~/.rubygems')
21
+ end
22
+
23
+ do_announce(env) do |i|
24
+ i << trace_sh_command("ruby --version")
25
+ i << trace_sh_command("gem --version")
26
+ i << trace_sh_command("bundle --version")
27
+ end
28
+
29
+ do_install(env) do |i|
30
+ bundler_args = env.source.bundler_args.first
31
+ i << trace_sh_command("bundle install #{bundler_args}")
32
+ i << trace_sh_command("bundle clean --force")
33
+ end
34
+
35
+ do_script(env) do |i|
36
+ script = "if [ -f Rakefile ] ; then \n #{trace_sh_command "bundle exec rake"}\nfi"
37
+ i << script
38
+ end
39
+
40
+ do_cached_directories(env) do |i|
41
+ i << "~/.rubygems"
42
+ end
43
+ end
44
+
45
+ app.call(env)
46
+ end
47
+
48
+ private
49
+
50
+ def enabled?(env)
51
+ env.source.rvm.first || env.source.language == 'ruby'
52
+ end
53
+
54
+ def ruby(env)
55
+ env.source.rvm.first || DEFAULT_RUBY
56
+ end
57
+
58
+ def gemfile(env)
59
+ env.source.gemfile.first || "Gemfile"
60
+ end
61
+
62
+ def make_rbenv_version_command(env)
63
+ select_rbenv_version(env)
64
+ end
65
+
66
+ def select_rbenv_version(env)
67
+ %{
68
+ $(rbenv versions |
69
+ sed -e 's/^\*/ /' |
70
+ awk '{print $1}' |
71
+ grep -v 'system' |
72
+ grep '#{ruby env}' |
73
+ tail -n1)
74
+ }.gsub(/\n/, ' ').gsub(/ +/, ' ').strip
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+ end