evrone-ci-worker 0.2.0.pre0 → 0.2.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/evrone-ci-worker +4 -9
- data/lib/evrone/ci/worker.rb +16 -8
- data/lib/evrone/ci/worker/cli.rb +67 -0
- data/lib/evrone/ci/worker/configuration.rb +7 -0
- data/lib/evrone/ci/worker/docker.rb +0 -1
- data/lib/evrone/ci/worker/initializers/amqp.rb +1 -0
- data/lib/evrone/ci/worker/local.rb +0 -1
- data/lib/evrone/ci/worker/middlewares/docker_script.rb +27 -5
- data/lib/evrone/ci/worker/middlewares/docker_start_container.rb +2 -1
- data/lib/evrone/ci/worker/middlewares/local_script.rb +27 -3
- data/lib/evrone/ci/worker/version.rb +1 -1
- data/spec/lib/worker/docker_spec.rb +2 -2
- data/spec/lib/worker/middlewares/docker_script_spec.rb +18 -10
- data/spec/lib/worker/middlewares/docker_start_container_spec.rb +1 -1
- data/spec/lib/worker/middlewares/local_script_spec.rb +18 -9
- metadata +7 -12
- data/lib/evrone/ci/worker/middlewares/docker_before_script.rb +0 -38
- data/lib/evrone/ci/worker/middlewares/local_before_script.rb +0 -29
- data/spec/lib/worker/middlewares/docker_before_script_spec.rb +0 -30
- data/spec/lib/worker/middlewares/local_before_script_spec.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58f2ff7f63d54397ceceb915a1beead7603abb5d
|
4
|
+
data.tar.gz: 3bca9c6de4a0b62ce144e5c2e3356bb66ab88135
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b23970e35db6cb112cbda92597ee903444a6ef54e282244d283532f8aaf64e736db833175836797f0f3eac39d9a3c87b2ecda31b2010cf0be6d0be9a8c542a2c
|
7
|
+
data.tar.gz: 7f725fc9fbeca95f22d7d1f48e99b6b1debb405576e05f72f3117d8d8fa32615558c96f3d61e04a4e03822edfe3f90021eec96d2b1c1f235d37add55d32f1fa5
|
data/bin/evrone-ci-worker
CHANGED
@@ -2,12 +2,9 @@
|
|
2
2
|
|
3
3
|
require File.expand_path("../../lib/evrone/ci/worker", __FILE__)
|
4
4
|
|
5
|
-
|
6
|
-
Thread.new do
|
7
|
-
Evrone::Common::AMQP.shutdown
|
8
|
-
end.join
|
9
|
-
}
|
5
|
+
cli = Evrone::CI::Worker::CLI.new
|
10
6
|
|
7
|
+
=begin
|
11
8
|
Evrone::CI::Worker.configure do |c|
|
12
9
|
c.docker.ssh.port = 2223
|
13
10
|
c.docker.ssh.host = 'localhost'
|
@@ -15,8 +12,6 @@ Evrone::CI::Worker.configure do |c|
|
|
15
12
|
'PortSpecs' => ['2022:22']
|
16
13
|
}
|
17
14
|
end
|
15
|
+
=end
|
18
16
|
|
19
|
-
|
20
|
-
Evrone::CI::Worker::JobsConsumer => 4,
|
21
|
-
).run
|
22
|
-
|
17
|
+
cli.run
|
data/lib/evrone/ci/worker.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'pathname'
|
3
|
+
require 'thread'
|
4
|
+
|
3
5
|
require 'bundler'
|
4
6
|
Bundler.require :default
|
5
7
|
|
@@ -17,18 +19,17 @@ module Evrone
|
|
17
19
|
autoload :Job, File.expand_path("../worker/job", __FILE__)
|
18
20
|
autoload :Local, File.expand_path("../worker/local", __FILE__)
|
19
21
|
autoload :Docker, File.expand_path("../worker/docker", __FILE__)
|
22
|
+
autoload :CLI, File.expand_path("../worker/cli", __FILE__)
|
20
23
|
|
21
24
|
autoload :LogJob, File.expand_path("../worker/middlewares/log_job", __FILE__)
|
22
25
|
autoload :UpdateJobStatus, File.expand_path("../worker/middlewares/update_job_status", __FILE__)
|
23
26
|
|
24
27
|
autoload :LocalCreateDirs, File.expand_path("../worker/middlewares/local_create_dirs", __FILE__)
|
25
28
|
autoload :LocalFetchRepo, File.expand_path("../worker/middlewares/local_fetch_repo", __FILE__)
|
26
|
-
autoload :LocalBeforeScript, File.expand_path("../worker/middlewares/local_before_script", __FILE__)
|
27
29
|
autoload :LocalScript, File.expand_path("../worker/middlewares/local_script", __FILE__)
|
28
30
|
|
29
31
|
autoload :DockerStartContainer, File.expand_path("../worker/middlewares/docker_start_container", __FILE__)
|
30
32
|
autoload :DockerFetchRepo, File.expand_path("../worker/middlewares/docker_fetch_repo", __FILE__)
|
31
|
-
autoload :DockerBeforeScript, File.expand_path("../worker/middlewares/docker_before_script", __FILE__)
|
32
33
|
autoload :DockerScript, File.expand_path("../worker/middlewares/docker_script", __FILE__)
|
33
34
|
|
34
35
|
module Helper
|
@@ -39,7 +40,7 @@ module Evrone
|
|
39
40
|
extend self
|
40
41
|
|
41
42
|
@@root = Pathname.new File.expand_path('../../../..', __FILE__)
|
42
|
-
@@
|
43
|
+
@@config_mutex = Mutex.new
|
43
44
|
|
44
45
|
def logger
|
45
46
|
if ENV['CI_WORKER_SILENT']
|
@@ -55,7 +56,11 @@ module Evrone
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def config
|
58
|
-
|
59
|
+
@config ||= begin
|
60
|
+
@@config_mutex.synchronize do
|
61
|
+
Configuration.new
|
62
|
+
end
|
63
|
+
end
|
59
64
|
end
|
60
65
|
|
61
66
|
def root
|
@@ -71,14 +76,17 @@ module Evrone
|
|
71
76
|
end
|
72
77
|
|
73
78
|
def reset_config!
|
74
|
-
|
79
|
+
@config = nil
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize!
|
83
|
+
root.join("lib/evrone/ci/worker/initializers").children.each do |e|
|
84
|
+
require e
|
85
|
+
end
|
75
86
|
end
|
76
87
|
|
77
88
|
end
|
78
89
|
end
|
79
90
|
end
|
80
91
|
|
81
|
-
Evrone::CI::Worker.root.join("lib/evrone/ci/worker/initializers").children.each do |e|
|
82
|
-
require e
|
83
|
-
end
|
84
92
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'evrone/common/amqp'
|
3
|
+
|
4
|
+
module Evrone
|
5
|
+
module CI
|
6
|
+
module Worker
|
7
|
+
class CLI
|
8
|
+
|
9
|
+
include Helper::Config
|
10
|
+
include Helper::Logger
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@options = {}
|
14
|
+
parse!
|
15
|
+
Worker.initialize!
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
logger.warn "spawn inside #{config.path_prefix}"
|
20
|
+
|
21
|
+
trap('INT') {
|
22
|
+
Thread.new do
|
23
|
+
Evrone::Common::AMQP.shutdown
|
24
|
+
end.join
|
25
|
+
}
|
26
|
+
|
27
|
+
Evrone::Common::AMQP::Supervisor::Threaded.build(
|
28
|
+
Evrone::CI::Worker::JobsConsumer => config.workers,
|
29
|
+
).run
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def parse!
|
35
|
+
OptionParser.new do |opts|
|
36
|
+
opts.banner = "Usage: evrone-ci-worker [options]"
|
37
|
+
opts.on("-w", "--workers NUM", "Number of workers, default 1") do |v|
|
38
|
+
@options[:workers] = v.to_i
|
39
|
+
end
|
40
|
+
opts.on("-p", "--path PATH", "Working directory, default current directory") do |v|
|
41
|
+
@options[:path_prefix] = v.to_s
|
42
|
+
end
|
43
|
+
opts.on("-c", "--config FILE", "Path to configuration file") do |v|
|
44
|
+
read_configuration v
|
45
|
+
end
|
46
|
+
end.parse!
|
47
|
+
|
48
|
+
@options.each_pair do |k,v|
|
49
|
+
config.public_send("#{k}=", v)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def read_configuration(file)
|
54
|
+
file = File.expand_path(file)
|
55
|
+
buf = File.read(file)
|
56
|
+
|
57
|
+
buf.split("\n").each do |line|
|
58
|
+
puts line
|
59
|
+
env, value = line.split("=").map(&:strip)
|
60
|
+
ENV[env] = value
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -25,6 +25,9 @@ module Evrone
|
|
25
25
|
|
26
26
|
sleep_after_job: 5,
|
27
27
|
|
28
|
+
workers: 1,
|
29
|
+
path_prefix: nil,
|
30
|
+
|
28
31
|
docker: {
|
29
32
|
remote_dir: "/home/ci",
|
30
33
|
init: %w{ /usr/local/bin/runsvdir -P /etc/service },
|
@@ -48,6 +51,10 @@ module Evrone
|
|
48
51
|
self[:run].to_sym
|
49
52
|
end
|
50
53
|
|
54
|
+
def path_prefix
|
55
|
+
self[:path_prefix] || Dir.pwd
|
56
|
+
end
|
57
|
+
|
51
58
|
def null_logger
|
52
59
|
@@null_logger
|
53
60
|
end
|
@@ -14,7 +14,12 @@ module Evrone
|
|
14
14
|
if code == 0
|
15
15
|
app.call env
|
16
16
|
else
|
17
|
-
|
17
|
+
case read_state(env)
|
18
|
+
when "script"
|
19
|
+
code
|
20
|
+
else
|
21
|
+
code * -1
|
22
|
+
end
|
18
23
|
end
|
19
24
|
else
|
20
25
|
app.call env
|
@@ -25,10 +30,27 @@ module Evrone
|
|
25
30
|
|
26
31
|
def run_script(env)
|
27
32
|
scp = ::Net::SCP.new(env.ssh.connection)
|
28
|
-
script = [env.docker_repo_dir, ".
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
script = [env.docker_repo_dir, ".ci_build.sh"].join("/")
|
34
|
+
scp.upload! StringIO.new(content(env)), script
|
35
|
+
env.ssh.spawn "env - HOME=$HOME bash #{script}", chdir: env.docker_repo_dir, &env.job.method(:add_to_output)
|
36
|
+
end
|
37
|
+
|
38
|
+
def content(env)
|
39
|
+
buf = ["set -e"]
|
40
|
+
buf << "echo before_script > #{env.docker_repo_dir}/.ci_state"
|
41
|
+
buf << env.job.message.before_script
|
42
|
+
buf << "echo script > #{env.docker_repo_dir}/.ci_state"
|
43
|
+
buf << env.job.message.script
|
44
|
+
buf.join("\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
def read_state(env)
|
48
|
+
buf = ""
|
49
|
+
state_file = env.docker_repo_dir.join(".ci_state")
|
50
|
+
env.ssh.spawn "cat #{state_file}" do |out|
|
51
|
+
buf << out
|
52
|
+
end
|
53
|
+
buf.strip
|
32
54
|
end
|
33
55
|
|
34
56
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'docker'
|
2
2
|
require 'evrone/common/spawn'
|
3
3
|
require 'socket'
|
4
|
+
require 'pathname'
|
4
5
|
|
5
6
|
module Evrone
|
6
7
|
module CI
|
@@ -52,7 +53,7 @@ module Evrone
|
|
52
53
|
|
53
54
|
env.container_addr = config.docker.ssh.host
|
54
55
|
env.container_addr ||= env.container.json['NetworkSettings']['IPAddress']
|
55
|
-
env.docker_repo_dir =
|
56
|
+
env.docker_repo_dir = Pathname.new(config.docker.remote_dir).join(env.job.message.name)
|
56
57
|
|
57
58
|
logger.tagged "DOCKER #{env.container.id}" do
|
58
59
|
begin
|
@@ -9,18 +9,42 @@ module Evrone
|
|
9
9
|
include Common::Helper::Shell
|
10
10
|
|
11
11
|
def call(env)
|
12
|
-
script = env.
|
13
|
-
write_file script, env
|
12
|
+
script = env.tmp_dir.join("build.sh")
|
13
|
+
write_file script, content(env), 0700
|
14
14
|
|
15
15
|
code = bash file: script, chdir: env.work_dir, &env.job.method(:add_to_output)
|
16
16
|
|
17
17
|
if code == 0
|
18
18
|
app.call env
|
19
19
|
else
|
20
|
-
|
20
|
+
state = read_state(env)
|
21
|
+
case state
|
22
|
+
when "script"
|
23
|
+
code
|
24
|
+
else
|
25
|
+
code * -1
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
30
|
+
private
|
31
|
+
|
32
|
+
def content(env)
|
33
|
+
buf = ["set -e"]
|
34
|
+
buf << "echo before_script > #{env.tmp_dir}/state"
|
35
|
+
buf << env.job.message.before_script
|
36
|
+
buf << "echo script > #{env.tmp_dir}/state"
|
37
|
+
buf << env.job.message.script
|
38
|
+
buf.join("\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
def read_state(env)
|
42
|
+
state_file = env.tmp_dir.join("state")
|
43
|
+
if File.readable? state_file
|
44
|
+
File.read(state_file).strip
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
24
48
|
end
|
25
49
|
end
|
26
50
|
end
|
@@ -16,12 +16,12 @@ describe Evrone::CI::Worker::Docker do
|
|
16
16
|
it { should eq 0 }
|
17
17
|
|
18
18
|
context "when fail before_script" do
|
19
|
-
let(:options) { { before_script: "
|
19
|
+
let(:options) { { before_script: "false" } }
|
20
20
|
it { should eq(-1) }
|
21
21
|
end
|
22
22
|
|
23
23
|
context "when fail script" do
|
24
|
-
let(:options) { { script: "
|
24
|
+
let(:options) { { script: "false" } }
|
25
25
|
it { should eq(1) }
|
26
26
|
end
|
27
27
|
end
|
@@ -1,18 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Evrone::CI::Worker::DockerScript, run_docker: true do
|
4
|
-
let(:exit_code)
|
5
|
-
let(:app)
|
6
|
-
let(:script)
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
let(:
|
4
|
+
let(:exit_code) { 0 }
|
5
|
+
let(:app) { ->(_) { exit_code } }
|
6
|
+
let(:script) { "echo script" }
|
7
|
+
let(:before_script) { "echo before_script" }
|
8
|
+
let(:job) { create :job, script: script, before_script: before_script }
|
9
|
+
let(:env) { OpenStruct.new job: job }
|
10
|
+
let(:mid) { described_class.new app }
|
11
|
+
let(:docker_mid) { Evrone::CI::Worker::DockerStartContainer.new(mid) }
|
11
12
|
|
12
13
|
subject { docker_mid.call env }
|
13
14
|
|
14
15
|
before do
|
15
|
-
stub(env).docker_repo_dir { '/tmp' }
|
16
|
+
stub(env).docker_repo_dir { Pathname.new '/tmp' }
|
16
17
|
end
|
17
18
|
|
18
19
|
it "should be" do
|
@@ -20,11 +21,18 @@ describe Evrone::CI::Worker::DockerScript, run_docker: true do
|
|
20
21
|
expect(job.output).to match("script")
|
21
22
|
end
|
22
23
|
|
23
|
-
context "when
|
24
|
-
let(:script) { "
|
24
|
+
context "when script failed" do
|
25
|
+
let(:script) { "false" }
|
25
26
|
it "should be" do
|
26
27
|
expect(subject).to eq(1)
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
31
|
+
context "when before_script failed" do
|
32
|
+
let(:before_script) { "false" }
|
33
|
+
it "should be" do
|
34
|
+
expect(subject).to eq(-1)
|
35
|
+
end
|
36
|
+
end
|
29
37
|
end
|
30
38
|
|
@@ -14,7 +14,7 @@ describe Evrone::CI::Worker::DockerStartContainer, run_docker: true do
|
|
14
14
|
|
15
15
|
expect(env.ssh).to be
|
16
16
|
expect(env.container).to be
|
17
|
-
expect(env.docker_repo_dir).to eq "/home/ci/evrone/test-repo"
|
17
|
+
expect(env.docker_repo_dir.to_s).to eq "/home/ci/evrone/test-repo"
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
@@ -3,33 +3,42 @@ require 'pathname'
|
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
5
|
describe Evrone::CI::Worker::LocalScript do
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
let(:
|
6
|
+
let(:before_script) { "echo before_script" }
|
7
|
+
let(:script) { "echo script" }
|
8
|
+
let(:app) { ->(_) { 0 } }
|
9
|
+
let(:job) { create :job, script: script, before_script: before_script }
|
10
|
+
let(:path_prefix) { Pathname.new "/tmp/.ci" }
|
11
|
+
let(:work_dir) { path_prefix.join("work") }
|
12
|
+
let(:tmp_dir) { path_prefix.join("tmp") }
|
13
|
+
let(:env) { OpenStruct.new job: job, work_dir: work_dir, tmp_dir: tmp_dir }
|
14
|
+
let(:mid) { described_class.new app }
|
12
15
|
|
13
16
|
subject { mid.call env }
|
14
17
|
|
15
18
|
after do
|
16
|
-
FileUtils.rm_rf
|
19
|
+
FileUtils.rm_rf path_prefix
|
17
20
|
end
|
18
21
|
|
19
22
|
before do
|
20
23
|
FileUtils.mkdir_p work_dir
|
24
|
+
FileUtils.mkdir_p tmp_dir
|
21
25
|
end
|
22
26
|
|
23
27
|
it { should eq 0 }
|
24
28
|
|
25
29
|
it "should capture output" do
|
26
30
|
subject
|
27
|
-
expect(job.output).to eq "
|
31
|
+
expect(job.output).to eq "before_script\nscript\n"
|
28
32
|
end
|
29
33
|
|
30
34
|
context "when script failed" do
|
31
|
-
let(:
|
35
|
+
let(:script) { 'false' }
|
32
36
|
it { should satisfy { |n| [1,127].include?(n) } }
|
33
37
|
end
|
38
|
+
|
39
|
+
context "when before_script failed" do
|
40
|
+
let(:before_script) { 'false' }
|
41
|
+
it { should satisfy { |n| [-1,-127].include?(n) } }
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evrone-ci-worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.
|
4
|
+
version: 0.2.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Galinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evrone-ci-common
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.0.
|
19
|
+
version: 0.2.0.pre1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.2.0.
|
26
|
+
version: 0.2.0.pre1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: evrone-ci-message
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.2.0.
|
33
|
+
version: 0.2.0.pre1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.2.0.
|
40
|
+
version: 0.2.0.pre1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: evrone-common-amqp
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- docker/sv-gen
|
171
171
|
- evrone-ci-worker.gemspec
|
172
172
|
- lib/evrone/ci/worker.rb
|
173
|
+
- lib/evrone/ci/worker/cli.rb
|
173
174
|
- lib/evrone/ci/worker/configuration.rb
|
174
175
|
- lib/evrone/ci/worker/consumers/job_logs_consumer.rb
|
175
176
|
- lib/evrone/ci/worker/consumers/job_status_consumer.rb
|
@@ -181,11 +182,9 @@ files:
|
|
181
182
|
- lib/evrone/ci/worker/initializers/amqp.rb
|
182
183
|
- lib/evrone/ci/worker/job.rb
|
183
184
|
- lib/evrone/ci/worker/local.rb
|
184
|
-
- lib/evrone/ci/worker/middlewares/docker_before_script.rb
|
185
185
|
- lib/evrone/ci/worker/middlewares/docker_fetch_repo.rb
|
186
186
|
- lib/evrone/ci/worker/middlewares/docker_script.rb
|
187
187
|
- lib/evrone/ci/worker/middlewares/docker_start_container.rb
|
188
|
-
- lib/evrone/ci/worker/middlewares/local_before_script.rb
|
189
188
|
- lib/evrone/ci/worker/middlewares/local_create_dirs.rb
|
190
189
|
- lib/evrone/ci/worker/middlewares/local_fetch_repo.rb
|
191
190
|
- lib/evrone/ci/worker/middlewares/local_script.rb
|
@@ -198,11 +197,9 @@ files:
|
|
198
197
|
- spec/lib/worker/docker_spec.rb
|
199
198
|
- spec/lib/worker/job_spec.rb
|
200
199
|
- spec/lib/worker/local_spec.rb
|
201
|
-
- spec/lib/worker/middlewares/docker_before_script_spec.rb
|
202
200
|
- spec/lib/worker/middlewares/docker_fetch_repo_spec.rb
|
203
201
|
- spec/lib/worker/middlewares/docker_script_spec.rb
|
204
202
|
- spec/lib/worker/middlewares/docker_start_container_spec.rb
|
205
|
-
- spec/lib/worker/middlewares/local_before_script_spec.rb
|
206
203
|
- spec/lib/worker/middlewares/local_create_dirs_spec.rb
|
207
204
|
- spec/lib/worker/middlewares/local_fetch_repo_spec.rb
|
208
205
|
- spec/lib/worker/middlewares/local_script_spec.rb
|
@@ -241,11 +238,9 @@ test_files:
|
|
241
238
|
- spec/lib/worker/docker_spec.rb
|
242
239
|
- spec/lib/worker/job_spec.rb
|
243
240
|
- spec/lib/worker/local_spec.rb
|
244
|
-
- spec/lib/worker/middlewares/docker_before_script_spec.rb
|
245
241
|
- spec/lib/worker/middlewares/docker_fetch_repo_spec.rb
|
246
242
|
- spec/lib/worker/middlewares/docker_script_spec.rb
|
247
243
|
- spec/lib/worker/middlewares/docker_start_container_spec.rb
|
248
|
-
- spec/lib/worker/middlewares/local_before_script_spec.rb
|
249
244
|
- spec/lib/worker/middlewares/local_create_dirs_spec.rb
|
250
245
|
- spec/lib/worker/middlewares/local_fetch_repo_spec.rb
|
251
246
|
- spec/lib/worker/middlewares/local_script_spec.rb
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'net/scp'
|
2
|
-
|
3
|
-
module Evrone
|
4
|
-
module CI
|
5
|
-
module Worker
|
6
|
-
|
7
|
-
DockerBeforeScript = Struct.new(:app) do
|
8
|
-
|
9
|
-
include Helper::Logger
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
if env.ssh && env.docker_repo_dir
|
13
|
-
code = run_before_script(env)
|
14
|
-
if code == 0
|
15
|
-
app.call env
|
16
|
-
else
|
17
|
-
-1
|
18
|
-
end
|
19
|
-
else
|
20
|
-
app.call env
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def run_before_script(env)
|
27
|
-
scp = ::Net::SCP.new(env.ssh.connection)
|
28
|
-
script = [env.docker_repo_dir, ".ci_before_script.sh"].join("/")
|
29
|
-
scp.upload! StringIO.new(env.job.message.before_script), script
|
30
|
-
env.ssh.spawn "env - bash #{script}", chdir: env.docker_repo_dir, &env.job.method(:add_to_output)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'evrone/ci/common'
|
2
|
-
|
3
|
-
module Evrone
|
4
|
-
module CI
|
5
|
-
module Worker
|
6
|
-
|
7
|
-
LocalBeforeScript = Struct.new(:app) do
|
8
|
-
|
9
|
-
include Common::Helper::Shell
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
script = env.work_dir.join(".ci_before_script.sh")
|
13
|
-
write_file script, env.job.message.before_script, 0700
|
14
|
-
|
15
|
-
code = bash file: script, chdir: env.work_dir, &env.job.method(:add_to_output)
|
16
|
-
|
17
|
-
if code == 0
|
18
|
-
app.call env
|
19
|
-
else
|
20
|
-
-1
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Evrone::CI::Worker::DockerBeforeScript, run_docker: true do
|
4
|
-
let(:exit_code) { 0 }
|
5
|
-
let(:app) { ->(_) { exit_code } }
|
6
|
-
let(:script) { "echo before_script" }
|
7
|
-
let(:job) { create :job, before_script: script }
|
8
|
-
let(:env) { OpenStruct.new job: job }
|
9
|
-
let(:mid) { described_class.new app }
|
10
|
-
let(:docker_mid) { Evrone::CI::Worker::DockerStartContainer.new(mid) }
|
11
|
-
|
12
|
-
subject { docker_mid.call env }
|
13
|
-
|
14
|
-
before do
|
15
|
-
stub(env).docker_repo_dir { '/tmp' }
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should be" do
|
19
|
-
expect(subject).to eq 0
|
20
|
-
expect(job.output).to match("before_script")
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when fail to execute" do
|
24
|
-
let(:script) { "/bin/false" }
|
25
|
-
it "should be" do
|
26
|
-
expect(subject).to eq(-1)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pathname'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
describe Evrone::CI::Worker::LocalBeforeScript do
|
6
|
-
let(:command) { "echo before_script" }
|
7
|
-
let(:app) { ->(_) { 0 } }
|
8
|
-
let(:job) { create :job, before_script: command }
|
9
|
-
let(:work_dir) { Pathname.new '/tmp/.ci' }
|
10
|
-
let(:env) { OpenStruct.new job: job, work_dir: work_dir }
|
11
|
-
let(:mid) { described_class.new app }
|
12
|
-
|
13
|
-
subject { mid.call env }
|
14
|
-
|
15
|
-
after do
|
16
|
-
FileUtils.rm_rf work_dir
|
17
|
-
end
|
18
|
-
|
19
|
-
before do
|
20
|
-
FileUtils.mkdir_p work_dir
|
21
|
-
end
|
22
|
-
|
23
|
-
it { should eq 0 }
|
24
|
-
|
25
|
-
it "should capture output" do
|
26
|
-
subject
|
27
|
-
expect(job.output).to eq "before_script\n"
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when script failed" do
|
31
|
-
let(:command) { '/bin/false' }
|
32
|
-
it { should eq(-1) }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|