vx-builder 0.5.61 → 0.5.62

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vx/builder/script_builder_v2/clone.rb +1 -2
  3. data/lib/vx/builder/task.rb +3 -3
  4. data/lib/vx/builder/version.rb +1 -1
  5. data/lib/vx/builder.rb +0 -5
  6. data/spec/fixtures/script_builder_v2/simple.sh +1 -1
  7. data/spec/fixtures/script_builder_v2/simple.yml +85 -30
  8. data/spec/fixtures/test_key1 +27 -0
  9. data/spec/fixtures/test_key2 +27 -0
  10. data/spec/lib/builder/task_spec.rb +1 -1
  11. data/spec/support/create.rb +3 -1
  12. metadata +6 -38
  13. data/lib/vx/builder/script_builder/base.rb +0 -77
  14. data/lib/vx/builder/script_builder/cache.rb +0 -95
  15. data/lib/vx/builder/script_builder/clojure.rb +0 -34
  16. data/lib/vx/builder/script_builder/defaults.rb +0 -34
  17. data/lib/vx/builder/script_builder/deploy.rb +0 -34
  18. data/lib/vx/builder/script_builder/env.rb +0 -50
  19. data/lib/vx/builder/script_builder/go.rb +0 -60
  20. data/lib/vx/builder/script_builder/java.rb +0 -31
  21. data/lib/vx/builder/script_builder/nodejs.rb +0 -64
  22. data/lib/vx/builder/script_builder/parallel.rb +0 -19
  23. data/lib/vx/builder/script_builder/prepare.rb +0 -94
  24. data/lib/vx/builder/script_builder/python.rb +0 -82
  25. data/lib/vx/builder/script_builder/ruby.rb +0 -92
  26. data/lib/vx/builder/script_builder/rust.rb +0 -48
  27. data/lib/vx/builder/script_builder/scala.rb +0 -50
  28. data/lib/vx/builder/script_builder/services.rb +0 -26
  29. data/lib/vx/builder/script_builder/timeouts.rb +0 -21
  30. data/lib/vx/builder/script_builder.rb +0 -145
  31. data/spec/lib/builder/script_builder/cache_spec.rb +0 -12
  32. data/spec/lib/builder/script_builder/clojure_spec.rb +0 -34
  33. data/spec/lib/builder/script_builder/env_spec.rb +0 -22
  34. data/spec/lib/builder/script_builder/java_spec.rb +0 -23
  35. data/spec/lib/builder/script_builder/prepare_spec.rb +0 -46
  36. data/spec/lib/builder/script_builder/python_spec.rb +0 -32
  37. data/spec/lib/builder/script_builder/ruby_spec.rb +0 -39
  38. data/spec/lib/builder/script_builder/scala_spec.rb +0 -33
  39. data/spec/lib/builder/script_builder_spec.rb +0 -60
@@ -1,34 +0,0 @@
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
@@ -1,50 +0,0 @@
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=1"
29
- collection << "export CI_JOB_ID=#{env.task.job_id}"
30
- collection << "export CI_JOB_NUMBER=#{env.task.job_number}"
31
- collection << "export CI_BUILD_ID=#{env.task.build_id}"
32
- collection << "export CI_BUILD_NUMBER=#{env.task.build_number}"
33
- collection << "export CI_PROJECT_NAME=#{env.task.name}"
34
- collection << "export CI_BUILD_SHA=#{env.task.sha}"
35
- collection << "export CI_PROJECT_TOKEN=#{env.task.project_token}" if env.task.project_token
36
- collection << "export DISPLAY=:99"
37
-
38
- if p = env.task.pull_request_id
39
- collection << "export CI_PULL_REQUEST_ID=#{p}"
40
- end
41
-
42
- if b = env.task.branch
43
- collection << "export CI_BRANCH=#{b}"
44
- end
45
- end
46
-
47
- end
48
- end
49
- end
50
- end
@@ -1,60 +0,0 @@
1
- module Vx
2
- module Builder
3
- class ScriptBuilder
4
-
5
- class Go < Base
6
-
7
- DEFAULT_GO = '1.2'
8
-
9
- def call(env)
10
- if enabled?(env)
11
- vxvm_install(env, 'go', go_version(env))
12
-
13
- do_before_install(env) do |i|
14
- i << trace_sh_command('export GOPATH=$VX_ROOT/gopath:$GOPATH')
15
- i << trace_sh_command('export PATH=$VX_ROOT/gopath/bin:$PATH')
16
- i << trace_sh_command('export VX_ORIG_CODE_ROOT=$(pwd)')
17
- i << trace_sh_command("export VX_NEW_CODE_ROOT=$VX_ROOT/gopath/src/#{project_path env}")
18
-
19
- i << trace_sh_command('mkdir -p $VX_NEW_CODE_ROOT')
20
- i << trace_sh_command('rmdir $VX_NEW_CODE_ROOT')
21
- i << trace_sh_command('mv $VX_ORIG_CODE_ROOT $VX_NEW_CODE_ROOT')
22
- i << trace_sh_command('ln -s $VX_NEW_CODE_ROOT $VX_ORIG_CODE_ROOT')
23
- i << trace_sh_command('cd $VX_NEW_CODE_ROOT')
24
- end
25
-
26
- do_announce(env) do |i|
27
- i << trace_sh_command("go version")
28
- i << trace_sh_command("go env")
29
- end
30
-
31
- do_install(env) do |i|
32
- i << trace_sh_command("go get -v ./...")
33
- end
34
-
35
- do_script(env) do |i|
36
- i << trace_sh_command("go test -v ./...")
37
- end
38
- end
39
-
40
- app.call(env)
41
- end
42
-
43
- private
44
-
45
- def project_path(env)
46
- "#{env.task.project_host}/#{env.task.name}"
47
- end
48
-
49
- def enabled?(env)
50
- env.source.go.first || env.source.language == 'go'
51
- end
52
-
53
- def go_version(env)
54
- env.source.go.first || DEFAULT_GO
55
- end
56
-
57
- end
58
- end
59
- end
60
- end
@@ -1,31 +0,0 @@
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
@@ -1,64 +0,0 @@
1
- module Vx
2
- module Builder
3
- class ScriptBuilder
4
-
5
- class Nodejs < Base
6
-
7
- DEFAULT_NODE = '0.10'
8
- NPM_PACKAGES = '~/.npm-packages'
9
- BOWER_COMPONENTS = '~/.bower_components'
10
-
11
- def call(env)
12
- if enabled?(env)
13
-
14
- vxvm_install(env, 'nodejs', node_version(env))
15
-
16
- do_cache_key(env) do |i|
17
- i << "nodejs-#{node_version env}"
18
- end
19
-
20
- do_announce(env) do |i|
21
- i << trace_sh_command("node --version")
22
- i << trace_sh_command("npm --version")
23
- end
24
-
25
- do_before_install(env) do |i|
26
- i << "mkdir -p #{NPM_PACKAGES}"
27
- i << "mkdir -p #{BOWER_COMPONENTS}"
28
- i << trace_sh_command("npm config set prefix=#{NPM_PACKAGES}")
29
- i << trace_sh_command("npm config set spin false")
30
- i << "test -f .bowerrc || (" + trace_sh_command("export bower_directory=#{BOWER_COMPONENTS}") + ")"
31
- i << "export PATH=$PATH:#{NPM_PACKAGES}/bin"
32
- end
33
-
34
- do_install(env) do |i|
35
- i << trace_sh_command("npm install")
36
- end
37
-
38
- do_script(env) do |i|
39
- i << trace_sh_command("npm test")
40
- end
41
-
42
- do_cached_directories(env) do |i|
43
- i << NPM_PACKAGES
44
- i << BOWER_COMPONENTS
45
- end
46
- end
47
-
48
- app.call(env)
49
- end
50
-
51
- private
52
-
53
- def enabled?(env)
54
- env.source.node_js.first || env.source.language == 'node_js'
55
- end
56
-
57
- def node_version(env)
58
- env.source.node_js.first || DEFAULT_NODE
59
- end
60
-
61
- end
62
- end
63
- end
64
- end
@@ -1,19 +0,0 @@
1
- module Vx
2
- module Builder
3
- class ScriptBuilder
4
-
5
- class Parallel < Base
6
-
7
- def call(env)
8
- if env.source.parallel?
9
- env.init << trace_sh_command("export CI_PARALLEL_JOBS=#{env.source.parallel}")
10
- env.init << trace_sh_command("export CI_PARALLEL_JOB_NUMBER=#{env.source.parallel_job_number}")
11
- end
12
-
13
- app.call(env)
14
- end
15
-
16
- end
17
- end
18
- end
19
- end
@@ -1,94 +0,0 @@
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
- i << 'export PATH=$VX_ROOT/bin:$PATH'
28
-
29
- i << "mkdir -p $VX_ROOT/bin"
30
- i << "mkdir -p #{data_path}"
31
- i << "mkdir -p #{repo_path}"
32
-
33
- %w{ vx_parallel_rspec vx_parallel_spinach vx_builder }.each do |bin|
34
- src = File.expand_path("../../../../../bin/#{bin}", __FILE__)
35
- bin.sub!("vx_", '') unless bin == 'vx_builder'
36
- dst = "$(pwd)/bin/#{bin}"
37
- i << upload_sh_command(dst, File.read(src))
38
- i << "chmod 0750 #{dst}"
39
- end
40
-
41
- i << 'echo "starting SSH Agent"'
42
- i << 'eval "$(ssh-agent)" > /dev/null'
43
-
44
- if deploy_key
45
- i << upload_sh_command(key_file, deploy_key)
46
- i << "chmod 0600 #{key_file}"
47
- i << "export VX_PRIVATE_KEY=#{key_file}"
48
- i << "ssh-add $VX_PRIVATE_KEY 2> /dev/null"
49
- end
50
-
51
- #i << upload_sh_command(git_ssh_file, git_ssh)
52
- #i << "chmod 0750 #{git_ssh_file}"
53
-
54
- #i << "export GIT_SSH=#{git_ssh_file}"
55
- i << "#{scm.fetch_cmd} || exit 1"
56
- #i << "unset GIT_SSH"
57
-
58
- i << "cd #{repo_path}"
59
-
60
- i << 'echo "download latest version of vxvm"'
61
- i << "curl --tcp-nodelay --retry 3 --fail --silent --show-error -o $VX_ROOT/bin/vxvm https://raw.githubusercontent.com/vexor/vx-packages/master/vxvm"
62
- i << "chmod +x $VX_ROOT/bin/vxvm"
63
- end
64
-
65
- env.after_script_init.tap do |i|
66
- i << 'export VX_ROOT=$(pwd)'
67
- i << "test -d #{repo_path} || exit 1"
68
- i << "cd #{repo_path}"
69
- end
70
-
71
- app.call env
72
- end
73
-
74
- private
75
-
76
- def build_scm(env, sha, path)
77
- Common::Git.new(env.task.src,
78
- sha,
79
- path,
80
- branch: branch_name(env),
81
- pull_request_id: env.task.pull_request_id)
82
- end
83
-
84
- def branch_name(env)
85
- b = env.task && env.task.branch
86
- if b && b != 'HEAD'
87
- b
88
- end
89
- end
90
-
91
- end
92
- end
93
- end
94
- end
@@ -1,82 +0,0 @@
1
- module Vx
2
- module Builder
3
- class ScriptBuilder
4
-
5
- class Python < Base
6
-
7
- DEFAULT_PYTHON = '2.7'
8
- VIRTUALENV_ROOT = "~/.python-virtualenv"
9
- PIP_DOWNLOADS = "~/.pip-downloads"
10
- PIP_OPTS = " --download-cache=#{PIP_DOWNLOADS}"
11
-
12
- def call(env)
13
- if enabled?(env)
14
-
15
- py_v = python_version(env)
16
-
17
- vxvm_install(env, 'python', py_v)
18
-
19
- do_init(env) do |i|
20
- i << "export TRAVIS_PYTHON_VERSION=#{py_v}" # for tornado
21
- end
22
-
23
- do_before_install(env) do |i|
24
- i << trace_sh_command("virtualenv #{VIRTUALENV_ROOT}")
25
- i << trace_sh_command("source #{VIRTUALENV_ROOT}/bin/activate")
26
- end
27
-
28
- do_announce(env) do |i|
29
- i << trace_sh_command("python --version")
30
- i << trace_sh_command("pip --version")
31
- end
32
-
33
- do_install(env) do |i|
34
- i << "if [ -f Requirements.txt ] ; then \n #{trace_sh_command "pip install -r Requirements.txt #{PIP_OPTS}"}\nfi"
35
- i << "if [ -f requirements.txt ] ; then \n #{trace_sh_command "pip install -r requirements.txt #{PIP_OPTS}"}\nfi"
36
- i << "if [ -f setup.py ] ; then \n #{trace_sh_command "python setup.py install"}\nfi"
37
- end
38
-
39
- do_before_script(env) do |i|
40
- i << trace_sh_command("vx_builder python:django:settings")
41
- end
42
-
43
- do_script(env) do |i|
44
- script =<<EOF
45
- if [[ -f manage.py ]] ; then
46
- #{trace_sh_command 'python manage.py test'}
47
- elif [[ -f setup.py ]] ; then
48
- #{trace_sh_command 'python setup.py test'}
49
- else
50
- #{trace_sh_command 'nosetests'}
51
- fi
52
- EOF
53
- i << script
54
- end
55
-
56
- do_cache_key(env) do |i|
57
- i << "python-#{py_v}"
58
- end
59
-
60
- do_cached_directories(env) do |i|
61
- i << PIP_DOWNLOADS
62
- end
63
- end
64
-
65
- app.call(env)
66
- end
67
-
68
- private
69
-
70
- def enabled?(env)
71
- env.source.python.first || env.source.language == 'python'
72
- end
73
-
74
- def python_version(env)
75
- v = env.source.python.first
76
- v || DEFAULT_PYTHON
77
- end
78
-
79
- end
80
- end
81
- end
82
- end
@@ -1,92 +0,0 @@
1
- module Vx
2
- module Builder
3
- class ScriptBuilder
4
-
5
- class Ruby < Base
6
-
7
- DEFAULT_RUBY = '2.0.0'
8
- DEFAULT_BUNDLE_INSTALL_ARGS = "--clean --retry=3 --jobs=4"
9
-
10
- ALIASES = {
11
- 'jruby-19mode' => 'jruby'
12
- }
13
-
14
- def call(env)
15
- if enabled?(env)
16
-
17
- do_cache_key(env) do |i|
18
- ruby_v = ruby_version(env) || 'default'
19
- i << "rvm-#{ruby_v}"
20
- i << gemfile(env)
21
- end
22
-
23
- do_init(env) do |i|
24
- if jruby?(env)
25
- i << trace_sh_command('export JRUBY_OPTS="-Xcext.enabled=true"')
26
- end
27
- i << trace_sh_command("export RAILS_ENV=test")
28
- i << trace_sh_command("export RACK_ENV=test")
29
- i << trace_sh_command("export BUNDLE_GEMFILE=${PWD}/#{gemfile(env)}")
30
- i << trace_sh_command('export GEM_HOME=~/.rubygems')
31
- end
32
-
33
- do_before_install(env) do |i|
34
- i << trace_sh_command("vx_builder ruby:install #{ruby_version env}")
35
- i << "source $(cat .ruby-activate)"
36
- end
37
-
38
- do_announce(env) do |i|
39
- i << trace_sh_command("ruby --version")
40
- i << trace_sh_command("gem --version")
41
- i << trace_sh_command("bundle --version")
42
- end
43
-
44
- do_install(env) do |i|
45
- bundler_args = env.source.bundler_args.first || DEFAULT_BUNDLE_INSTALL_ARGS
46
- i << trace_sh_command("bundle install #{bundler_args}")
47
- end
48
-
49
- do_before_script(env) do |i|
50
- i << trace_sh_command("vx_builder ruby:rails:install")
51
- end
52
-
53
- do_script(env) do |i|
54
- script = "if [ -f Rakefile ] ; then \n #{trace_sh_command "bundle exec rake"}\nfi"
55
- i << script
56
- end
57
-
58
- do_cached_directories(env) do |i|
59
- i << "~/.rubygems"
60
- end
61
- end
62
-
63
- app.call(env)
64
- end
65
-
66
- private
67
-
68
- def auto_build?(env)
69
- env.source.empty?
70
- end
71
-
72
- def enabled?(env)
73
- env.source.rvm.first || env.source.language == 'ruby'
74
- end
75
-
76
- def ruby_version(env)
77
- v = env.source.rvm.first
78
- ALIASES[v] || v
79
- end
80
-
81
- def jruby?(env)
82
- ruby_version(env) =~ /jruby/
83
- end
84
-
85
- def gemfile(env)
86
- env.source.gemfile.first || "Gemfile"
87
- end
88
-
89
- end
90
- end
91
- end
92
- end
@@ -1,48 +0,0 @@
1
- module Vx
2
- module Builder
3
- class ScriptBuilder
4
-
5
- class Rust < Base
6
-
7
- DEFAULT_RUST = '0.11.0'
8
-
9
- def call(env)
10
- if enabled?(env)
11
-
12
- vxvm_install(env, 'rust', rust_version(env))
13
-
14
- do_cache_key(env) do |i|
15
- i << "rust-#{rust_version env}"
16
- end
17
-
18
- do_install(env) do |i|
19
- i << trace_sh_command("git submodule init")
20
- i << trace_sh_command("git submodule update")
21
- end
22
-
23
- do_announce(env) do |i|
24
- i << trace_sh_command("rustc --version")
25
- end
26
-
27
- do_script(env) do |i|
28
- i << trace_sh_command("if [ -f Makefile ] ; then make ; fi", trace: "make")
29
- end
30
- end
31
-
32
- app.call(env)
33
- end
34
-
35
- private
36
-
37
- def enabled?(env)
38
- env.source.rust.first || env.source.language == 'rust'
39
- end
40
-
41
- def rust_version(env)
42
- env.source.rust.first || DEFAULT_RUST
43
- end
44
-
45
- end
46
- end
47
- end
48
- end
@@ -1,50 +0,0 @@
1
- module Vx
2
- module Builder
3
- class ScriptBuilder
4
-
5
- class Scala < Base
6
-
7
- DEFAULT_SCALA = '2.10.3'
8
-
9
- def call(env)
10
- if enabled?(env)
11
- do_cache_key(env) do |i|
12
- i << "scala-#{scala env}"
13
- end
14
-
15
- do_announce(env) do |i|
16
- i << trace_sh_command("export SCALA_VERSION=#{scala env}")
17
- end
18
-
19
- do_install(env) do |i|
20
- i << "if [[ -d project || -f build.sbt ]] ; then #{trace_sh_command "sbt ++#{scala env} update"} ; fi"
21
- end
22
-
23
- do_script(env) do |i|
24
- i << "if [[ -d project || -f build.sbt ]] ; then #{trace_sh_command "sbt ++#{scala env} test"} ; fi"
25
- end
26
-
27
- do_cached_directories(env) do |i|
28
- i << "~/.sbt"
29
- i << "~/.ivy2"
30
- end
31
- end
32
-
33
- app.call(env)
34
- end
35
-
36
- private
37
-
38
- def enabled?(env)
39
- env.source.scala.first || env.source.language == 'scala'
40
- end
41
-
42
- def scala(env)
43
- env.source.scala.first || DEFAULT_SCALA
44
- end
45
-
46
-
47
- end
48
- end
49
- end
50
- end
@@ -1,26 +0,0 @@
1
- module Vx
2
- module Builder
3
- class ScriptBuilder
4
-
5
- class Services < Base
6
-
7
- ALIASES = {
8
- 'rabbitmq' => 'rabbitmq-server'
9
- }
10
-
11
- def call(env)
12
- env.source.services.each do |srv|
13
- srv = ALIASES[srv] || srv
14
- env.init << trace_sh_command("sudo service #{srv} start")
15
- end
16
- unless env.source.services.empty?
17
- env.init << trace_sh_command("sleep 3")
18
- end
19
-
20
- app.call(env)
21
- end
22
-
23
- end
24
- end
25
- end
26
- end
@@ -1,21 +0,0 @@
1
- module Vx
2
- module Builder
3
- class ScriptBuilder
4
-
5
- class Timeouts < Base
6
-
7
- def call(env)
8
- if tm = env.source.vexor.read_timeout
9
- env.init << "echo Vexor: set read timeout to #{tm} seconds"
10
- end
11
- if tm = env.source.vexor.timeout
12
- env.init << "echo Vexor: set timeout to #{tm} seconds"
13
- end
14
-
15
- app.call(env)
16
- end
17
-
18
- end
19
- end
20
- end
21
- end