evrone-ci-worker 0.2.0.pre27 → 0.2.0.pre28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Rakefile +1 -1
- data/evrone-ci-worker.gemspec +3 -3
- data/lib/evrone/ci/worker.rb +2 -6
- data/lib/evrone/ci/worker/configuration.rb +14 -11
- data/lib/evrone/ci/worker/docker.rb +2 -2
- data/lib/evrone/ci/worker/local.rb +6 -7
- data/lib/evrone/ci/worker/middlewares/{docker_script.rb → run_script.rb} +14 -15
- data/lib/evrone/ci/worker/middlewares/start_connector.rb +36 -0
- data/lib/evrone/ci/worker/version.rb +1 -1
- data/spec/lib/worker/configuration_spec.rb +16 -15
- data/spec/lib/worker/docker_spec.rb +7 -8
- data/spec/lib/worker/local_spec.rb +7 -7
- data/spec/lib/worker/middlewares/run_script_spec.rb +63 -0
- data/spec/lib/worker/middlewares/start_connector_spec.rb +34 -0
- data/spec/spec_helper.rb +10 -0
- metadata +22 -28
- data/lib/evrone/ci/worker/middlewares/docker_start_container.rb +0 -83
- data/lib/evrone/ci/worker/middlewares/local_create_dirs.rb +0 -29
- data/lib/evrone/ci/worker/middlewares/local_script.rb +0 -53
- data/spec/lib/worker/middlewares/docker_script_spec.rb +0 -48
- data/spec/lib/worker/middlewares/docker_start_container_spec.rb +0 -21
- data/spec/lib/worker/middlewares/local_create_dirs_spec.rb +0 -32
- data/spec/lib/worker/middlewares/local_script_spec.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6cf0b0887a284839ad78e87338b5c6c01b6387f
|
4
|
+
data.tar.gz: 9d0bc82d9da7bfb5b03d226fa5387e477e858672
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4ba61e8fc3398c563d264071290d2e214f1d6c1c505b8e0300fab0d869f97232dd6a29ad53ceb49988ce8c881fda7f175bc3db183693d8e694e8bf4b10b8dad
|
7
|
+
data.tar.gz: 94eccc5cfebd5472a7c69c40fb7b1acb236e2e70282691f4eba171c8e1ff0bf306d2bce0665303864e3ec7477f525680ac372f2969a9254826b1f71e12cc0bed
|
data/Gemfile
CHANGED
@@ -4,3 +4,4 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
gem 'evrone-ci-common', path: File.expand_path("../../common", __FILE__)
|
6
6
|
gem 'evrone-ci-message', path: File.expand_path("../../message", __FILE__)
|
7
|
+
gem 'evrone-ci-container_connector', path: File.expand_path("../../container_connector", __FILE__)
|
data/Rakefile
CHANGED
data/evrone-ci-worker.gemspec
CHANGED
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'evrone-ci-common',
|
22
|
-
spec.add_runtime_dependency 'evrone-ci-message',
|
21
|
+
spec.add_runtime_dependency 'evrone-ci-common', "= #{Evrone::CI::Worker::VERSION}"
|
22
|
+
spec.add_runtime_dependency 'evrone-ci-message', "= #{Evrone::CI::Worker::VERSION}"
|
23
|
+
spec.add_runtime_dependency 'evrone-ci-container_connector', "= #{Evrone::CI::Worker::VERSION}"
|
23
24
|
spec.add_runtime_dependency 'evrone-common-amqp', '~> 0.2.5'
|
24
|
-
spec.add_runtime_dependency 'docker-api', '= 1.5.4'
|
25
25
|
spec.add_runtime_dependency 'hashr', '= 0.0.22'
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.3"
|
data/lib/evrone/ci/worker.rb
CHANGED
@@ -22,12 +22,8 @@ module Evrone
|
|
22
22
|
autoload :LogJob, File.expand_path("../worker/middlewares/log_job", __FILE__)
|
23
23
|
autoload :UpdateJobStatus, File.expand_path("../worker/middlewares/update_job_status", __FILE__)
|
24
24
|
autoload :Timeout, File.expand_path("../worker/middlewares/timeout", __FILE__)
|
25
|
-
|
26
|
-
autoload :
|
27
|
-
autoload :LocalScript, File.expand_path("../worker/middlewares/local_script", __FILE__)
|
28
|
-
|
29
|
-
autoload :DockerStartContainer, File.expand_path("../worker/middlewares/docker_start_container", __FILE__)
|
30
|
-
autoload :DockerScript, File.expand_path("../worker/middlewares/docker_script", __FILE__)
|
25
|
+
autoload :StartConnector, File.expand_path("../worker/middlewares/start_connector", __FILE__)
|
26
|
+
autoload :RunScript, File.expand_path("../worker/middlewares/run_script", __FILE__)
|
31
27
|
|
32
28
|
module Helper
|
33
29
|
autoload :Logger, File.expand_path("../worker/helper/logger", __FILE__)
|
@@ -19,24 +19,19 @@ module Evrone
|
|
19
19
|
timeout: 30 * 60,
|
20
20
|
logger: Common::TaggedLogging.new(Logger.new STDOUT),
|
21
21
|
|
22
|
-
tmp_dir_name: "tmp",
|
23
|
-
|
24
22
|
workers: 1,
|
25
23
|
path_prefix: nil,
|
26
24
|
|
27
25
|
docker: {
|
28
|
-
|
26
|
+
user: "ci",
|
27
|
+
password: "ci",
|
29
28
|
init: %w{ /usr/bin/runsvdir -P /etc/service },
|
30
29
|
image: "dmexe/ci",
|
30
|
+
remote_dir: "/home/ci",
|
31
|
+
},
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
port: nil, # used in tests
|
35
|
-
user: "ci",
|
36
|
-
password: "ci"
|
37
|
-
},
|
38
|
-
|
39
|
-
create_options: nil # used in tests
|
33
|
+
local: {
|
34
|
+
remote_dir: "/tmp/.local_connector"
|
40
35
|
}
|
41
36
|
|
42
37
|
def timeout
|
@@ -55,6 +50,14 @@ module Evrone
|
|
55
50
|
@@null_logger
|
56
51
|
end
|
57
52
|
|
53
|
+
def connector_options
|
54
|
+
self[self.run]
|
55
|
+
end
|
56
|
+
|
57
|
+
def connector_remote_dir
|
58
|
+
connector_options[:remote_dir]
|
59
|
+
end
|
60
|
+
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
@@ -9,23 +9,22 @@ module Evrone
|
|
9
9
|
|
10
10
|
include Common::Helper::Middlewares
|
11
11
|
|
12
|
-
attr_reader :job
|
12
|
+
attr_reader :job
|
13
13
|
|
14
14
|
middlewares do
|
15
15
|
use LogJob
|
16
16
|
use UpdateJobStatus
|
17
17
|
use Timeout
|
18
|
-
use
|
19
|
-
use
|
18
|
+
use StartConnector
|
19
|
+
use RunScript
|
20
20
|
end
|
21
21
|
|
22
|
-
def initialize(job,
|
23
|
-
@job
|
24
|
-
@path_prefix = Pathname.new(path_prefix).expand_path
|
22
|
+
def initialize(job, _)
|
23
|
+
@job = job
|
25
24
|
end
|
26
25
|
|
27
26
|
def perform
|
28
|
-
env = OpenStruct.new job: job
|
27
|
+
env = OpenStruct.new job: job
|
29
28
|
run_middlewares(env){ |_| 0 }
|
30
29
|
end
|
31
30
|
|
@@ -1,15 +1,17 @@
|
|
1
|
+
require 'evrone/ci/common'
|
2
|
+
|
1
3
|
module Evrone
|
2
4
|
module CI
|
3
5
|
module Worker
|
4
6
|
|
5
|
-
|
7
|
+
RunScript = Struct.new(:app) do
|
6
8
|
|
7
9
|
include Helper::Logger
|
8
10
|
include Helper::Config
|
9
11
|
include Common::Helper::UploadShCommand
|
10
12
|
|
11
13
|
def call(env)
|
12
|
-
if env.
|
14
|
+
if env.spawner
|
13
15
|
code = run_script(env)
|
14
16
|
run_after_script(env)
|
15
17
|
|
@@ -31,32 +33,30 @@ module Evrone
|
|
31
33
|
private
|
32
34
|
|
33
35
|
def run_script(env)
|
34
|
-
|
35
|
-
file = [home, ".ci_build.sh"].join("/")
|
36
|
+
file = [env.spawner.work_dir, ".ci_build.sh"].join("/")
|
36
37
|
|
37
|
-
script = [upload_sh_command(file, script_content(env
|
38
|
+
script = [upload_sh_command(file, script_content(env))]
|
38
39
|
script << "env - HOME=$HOME bash #{file}"
|
39
40
|
script = script.join(" && ")
|
40
41
|
|
41
|
-
env.
|
42
|
+
env.spawner.spawn script, read_timeout: read_timeout, &env.job.method(:add_to_output)
|
42
43
|
end
|
43
44
|
|
44
45
|
def run_after_script(env)
|
45
|
-
|
46
|
-
file = [home, ".ci_after_build.sh"].join("/")
|
46
|
+
file = [env.spawner.work_dir, ".ci_after_build.sh"].join("/")
|
47
47
|
|
48
48
|
script = [upload_sh_command(file, after_script_content(env))]
|
49
49
|
script << "env - HOME=$HOME bash #{file}"
|
50
50
|
script = script.join(" && ")
|
51
51
|
|
52
|
-
env.
|
52
|
+
env.spawner.spawn script, read_timeout: read_timeout, &env.job.method(:add_to_output)
|
53
53
|
end
|
54
54
|
|
55
|
-
def script_content(env
|
55
|
+
def script_content(env)
|
56
56
|
buf = ["set -e"]
|
57
|
-
buf << "echo before_script > #{
|
57
|
+
buf << "echo before_script > #{env.spawner.work_dir}/.ci_state"
|
58
58
|
buf << env.job.message.before_script
|
59
|
-
buf << "echo script > #{
|
59
|
+
buf << "echo script > #{env.spawner.work_dir}/.ci_state"
|
60
60
|
buf << env.job.message.script
|
61
61
|
buf.join("\n")
|
62
62
|
end
|
@@ -68,10 +68,9 @@ module Evrone
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def read_state(env)
|
71
|
-
home = config.docker.remote_dir
|
72
71
|
buf = ""
|
73
|
-
state_file = "#{
|
74
|
-
env.
|
72
|
+
state_file = "#{env.spawner.work_dir}/.ci_state"
|
73
|
+
env.spawner.spawn "cat #{state_file}" do |out|
|
75
74
|
buf << out
|
76
75
|
end
|
77
76
|
buf.strip
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'pathname'
|
3
|
+
require 'evrone/ci/container_connector'
|
4
|
+
|
5
|
+
module Evrone
|
6
|
+
module CI
|
7
|
+
module Worker
|
8
|
+
|
9
|
+
StartConnector = Struct.new(:app) do
|
10
|
+
|
11
|
+
include Helper::Config
|
12
|
+
include Helper::Logger
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
options = config.connector_options
|
16
|
+
options.merge! logger: logger
|
17
|
+
env.connector = Evrone::CI::ContainerConnector.lookup(config.run, options)
|
18
|
+
env.connector.start do |spawner|
|
19
|
+
env.job.add_to_output "using #{Socket.gethostname}##{spawner.id}\n"
|
20
|
+
logger.tagged("#{spawner.id}") do
|
21
|
+
begin
|
22
|
+
env.spawner = spawner
|
23
|
+
app.call env
|
24
|
+
ensure
|
25
|
+
env.spawner = spawner
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
@@ -4,26 +4,27 @@ describe Evrone::CI::Worker::Configuration do
|
|
4
4
|
let(:config) { Evrone::CI::Worker.config }
|
5
5
|
subject { config }
|
6
6
|
|
7
|
-
its(:run)
|
8
|
-
its(:docker)
|
9
|
-
its(:
|
10
|
-
its(:
|
11
|
-
its(:
|
7
|
+
its(:run) { should eq :docker }
|
8
|
+
its(:docker) { should be }
|
9
|
+
its(:timeout) { should eq 1800 }
|
10
|
+
its(:amqp_url) { should be_nil }
|
11
|
+
its(:connector_options) { should eq config.docker }
|
12
|
+
its(:connector_remote_dir) { should eq config.docker.remote_dir }
|
12
13
|
|
13
14
|
context "docker" do
|
14
15
|
subject { config.docker }
|
15
16
|
|
16
|
-
its(:
|
17
|
-
its(:
|
18
|
-
its(:init)
|
19
|
-
its(:image)
|
17
|
+
its(:user) { should be }
|
18
|
+
its(:password) { should be }
|
19
|
+
its(:init) { should be }
|
20
|
+
its(:image) { should be }
|
21
|
+
its(:remote_dir) { should be }
|
20
22
|
end
|
21
23
|
|
22
|
-
context "
|
23
|
-
subject { config.
|
24
|
+
context "local" do
|
25
|
+
subject { config.local }
|
24
26
|
|
25
|
-
its(:
|
26
|
-
its(:password) { should eq 'ci' }
|
27
|
+
its(:remote_dir){ should be }
|
27
28
|
end
|
28
29
|
|
29
30
|
context ".configure" do
|
@@ -33,7 +34,7 @@ describe Evrone::CI::Worker::Configuration do
|
|
33
34
|
c.docker.image = 'image'
|
34
35
|
end
|
35
36
|
}
|
36
|
-
its(:run) { should eq :local
|
37
|
-
its("docker.image") { should eq 'image'
|
37
|
+
its(:run) { should eq :local }
|
38
|
+
its("docker.image") { should eq 'image' }
|
38
39
|
end
|
39
40
|
end
|
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'pathname'
|
3
|
-
require 'fileutils'
|
4
2
|
|
5
|
-
describe Evrone::CI::Worker::Docker do
|
3
|
+
describe Evrone::CI::Worker::Docker, docker: true do
|
6
4
|
let(:options) { { } }
|
7
5
|
let(:job) { create :job, options }
|
8
|
-
let(:
|
9
|
-
let(:local) { described_class.new job, path }
|
6
|
+
let(:local) { described_class.new job, nil }
|
10
7
|
subject { local }
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
context "perform", run_docker: true do
|
9
|
+
context "perform" do
|
15
10
|
subject { local.perform }
|
16
11
|
it { should eq 0 }
|
17
12
|
|
13
|
+
before do
|
14
|
+
Evrone::CI::Worker.config.run = "docker"
|
15
|
+
end
|
16
|
+
|
18
17
|
context "when fail before_script" do
|
19
18
|
let(:options) { { before_script: "false" } }
|
20
19
|
it { should eq(-1) }
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'pathname'
|
3
|
-
require 'fileutils'
|
4
2
|
|
5
3
|
describe Evrone::CI::Worker::Local do
|
6
4
|
let(:options) { { } }
|
7
5
|
let(:job) { create :job, options }
|
8
|
-
let(:
|
9
|
-
let(:local) { described_class.new job, path }
|
6
|
+
let(:local) { described_class.new job, nil }
|
10
7
|
subject { local }
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
context "perform", local_run: true do
|
9
|
+
context "perform" do
|
15
10
|
subject { local.perform }
|
11
|
+
|
12
|
+
before do
|
13
|
+
Evrone::CI::Worker.config.run = "local"
|
14
|
+
end
|
15
|
+
|
16
16
|
it { should eq 0 }
|
17
17
|
|
18
18
|
context "when fail before_script" do
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Evrone::CI::Worker::RunScript do
|
4
|
+
let(:exit_code) { 0 }
|
5
|
+
let(:app) { ->(_) { exit_code } }
|
6
|
+
let(:script) { "echo script" }
|
7
|
+
let(:before_script) { "echo before_script" }
|
8
|
+
let(:after_script) { "echo after_script" }
|
9
|
+
let(:job) { create :job,
|
10
|
+
script: script,
|
11
|
+
before_script: before_script,
|
12
|
+
after_script: after_script }
|
13
|
+
let(:env) { OpenStruct.new job: job }
|
14
|
+
let(:mid) { described_class.new app }
|
15
|
+
let(:connector_mid) { Evrone::CI::Worker::StartConnector.new(mid) }
|
16
|
+
|
17
|
+
subject { connector_mid.call env }
|
18
|
+
|
19
|
+
shared_examples "run script" do
|
20
|
+
|
21
|
+
it "should be" do
|
22
|
+
expect(subject).to eq 0
|
23
|
+
job.release
|
24
|
+
expect(all_job_log_output).to match("script")
|
25
|
+
expect(all_job_log_output).to match("after_script")
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when script failed" do
|
29
|
+
let(:script) { "false" }
|
30
|
+
it "should be" do
|
31
|
+
expect(subject).to eq(1)
|
32
|
+
job.release
|
33
|
+
expect(all_job_log_output).to match("after_script")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when before_script failed" do
|
38
|
+
let(:before_script) { "false" }
|
39
|
+
it "should be" do
|
40
|
+
expect(subject).to eq(-1)
|
41
|
+
job.release
|
42
|
+
expect(all_job_log_output).to match("after_script")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "local connector" do
|
48
|
+
before do
|
49
|
+
Evrone::CI::Worker.config.run = "local"
|
50
|
+
end
|
51
|
+
|
52
|
+
it_should_behave_like "run script"
|
53
|
+
end
|
54
|
+
|
55
|
+
context "local connector", docker: true do
|
56
|
+
before do
|
57
|
+
Evrone::CI::Worker.config.run = "docker"
|
58
|
+
end
|
59
|
+
|
60
|
+
it_should_behave_like "run script"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Evrone::CI::Worker::StartConnector do
|
4
|
+
let(:exit_code) { 0 }
|
5
|
+
let(:app) { ->(_) { exit_code } }
|
6
|
+
let(:job) { create :job }
|
7
|
+
let(:env) { OpenStruct.new job: job }
|
8
|
+
let(:mid) { described_class.new app }
|
9
|
+
|
10
|
+
subject { mid.call env }
|
11
|
+
|
12
|
+
context "local connector" do
|
13
|
+
before do
|
14
|
+
Evrone::CI::Worker.config.run = "local"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should successfully start" do
|
18
|
+
expect(subject).to eq 0
|
19
|
+
expect(env.connector).to be
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "docker connector", docker: true do
|
24
|
+
before do
|
25
|
+
Evrone::CI::Worker.config.run = "docker"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should successfully start" do
|
29
|
+
expect(subject).to eq 0
|
30
|
+
expect(env.connector).to be
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -14,5 +14,15 @@ RSpec.configure do |config|
|
|
14
14
|
config.before(:each) do
|
15
15
|
Evrone::Common::AMQP::Testing.clear
|
16
16
|
Evrone::CI::Worker.reset_config!
|
17
|
+
|
18
|
+
Evrone::CI::Worker.configure do |c|
|
19
|
+
=begin
|
20
|
+
c.docker.ssh.port = 2223
|
21
|
+
c.docker.ssh.host = 'localhost'
|
22
|
+
c.docker.create_options = {
|
23
|
+
'PortSpecs' => ['2022:22']
|
24
|
+
}
|
25
|
+
=end
|
26
|
+
end
|
17
27
|
end
|
18
28
|
end
|
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.pre28
|
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-12-
|
11
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evrone-ci-common
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.0.
|
19
|
+
version: 0.2.0.pre28
|
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.pre28
|
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.pre28
|
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.pre28
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: evrone-
|
42
|
+
name: evrone-ci-container_connector
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.2.
|
47
|
+
version: 0.2.0.pre28
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.2.
|
54
|
+
version: 0.2.0.pre28
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: evrone-common-amqp
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.2.5
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.2.5
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: hashr
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,11 +169,9 @@ files:
|
|
169
169
|
- lib/evrone/ci/worker/initializers/amqp.rb
|
170
170
|
- lib/evrone/ci/worker/job.rb
|
171
171
|
- lib/evrone/ci/worker/local.rb
|
172
|
-
- lib/evrone/ci/worker/middlewares/docker_script.rb
|
173
|
-
- lib/evrone/ci/worker/middlewares/docker_start_container.rb
|
174
|
-
- lib/evrone/ci/worker/middlewares/local_create_dirs.rb
|
175
|
-
- lib/evrone/ci/worker/middlewares/local_script.rb
|
176
172
|
- lib/evrone/ci/worker/middlewares/log_job.rb
|
173
|
+
- lib/evrone/ci/worker/middlewares/run_script.rb
|
174
|
+
- lib/evrone/ci/worker/middlewares/start_connector.rb
|
177
175
|
- lib/evrone/ci/worker/middlewares/timeout.rb
|
178
176
|
- lib/evrone/ci/worker/middlewares/update_job_status.rb
|
179
177
|
- lib/evrone/ci/worker/version.rb
|
@@ -181,11 +179,9 @@ files:
|
|
181
179
|
- spec/lib/worker/docker_spec.rb
|
182
180
|
- spec/lib/worker/job_spec.rb
|
183
181
|
- spec/lib/worker/local_spec.rb
|
184
|
-
- spec/lib/worker/middlewares/docker_script_spec.rb
|
185
|
-
- spec/lib/worker/middlewares/docker_start_container_spec.rb
|
186
|
-
- spec/lib/worker/middlewares/local_create_dirs_spec.rb
|
187
|
-
- spec/lib/worker/middlewares/local_script_spec.rb
|
188
182
|
- spec/lib/worker/middlewares/log_job_spec.rb
|
183
|
+
- spec/lib/worker/middlewares/run_script_spec.rb
|
184
|
+
- spec/lib/worker/middlewares/start_connector_spec.rb
|
189
185
|
- spec/lib/worker/middlewares/timeout_spec.rb
|
190
186
|
- spec/lib/worker/middlewares/update_job_status_spec.rb
|
191
187
|
- spec/lib/worker_spec.rb
|
@@ -223,11 +219,9 @@ test_files:
|
|
223
219
|
- spec/lib/worker/docker_spec.rb
|
224
220
|
- spec/lib/worker/job_spec.rb
|
225
221
|
- spec/lib/worker/local_spec.rb
|
226
|
-
- spec/lib/worker/middlewares/docker_script_spec.rb
|
227
|
-
- spec/lib/worker/middlewares/docker_start_container_spec.rb
|
228
|
-
- spec/lib/worker/middlewares/local_create_dirs_spec.rb
|
229
|
-
- spec/lib/worker/middlewares/local_script_spec.rb
|
230
222
|
- spec/lib/worker/middlewares/log_job_spec.rb
|
223
|
+
- spec/lib/worker/middlewares/run_script_spec.rb
|
224
|
+
- spec/lib/worker/middlewares/start_connector_spec.rb
|
231
225
|
- spec/lib/worker/middlewares/timeout_spec.rb
|
232
226
|
- spec/lib/worker/middlewares/update_job_status_spec.rb
|
233
227
|
- spec/lib/worker_spec.rb
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'docker'
|
2
|
-
require 'evrone/common/spawn'
|
3
|
-
require 'socket'
|
4
|
-
require 'pathname'
|
5
|
-
|
6
|
-
module Evrone
|
7
|
-
module CI
|
8
|
-
module Worker
|
9
|
-
|
10
|
-
DockerStartContainer = Struct.new(:app) do
|
11
|
-
|
12
|
-
include Helper::Config
|
13
|
-
include Helper::Logger
|
14
|
-
include Evrone::Common::Spawn
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
spawn_container(env) do
|
18
|
-
open_ssh_session(env) do
|
19
|
-
app.call env
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def open_ssh_session(env)
|
27
|
-
host = env.container_addr
|
28
|
-
user = config.docker.ssh.user
|
29
|
-
pass = config.docker.ssh.password
|
30
|
-
|
31
|
-
ssh_options = {
|
32
|
-
password: pass,
|
33
|
-
port: config.docker.ssh.port || 22,
|
34
|
-
paranoid: false,
|
35
|
-
forward_agent: false
|
36
|
-
}
|
37
|
-
sleep 2
|
38
|
-
env.job.add_to_output "open ssh session to #{user}@#{host}:#{ssh_options[:port]}\n"
|
39
|
-
open_ssh(host, "ci", ssh_options) do |ssh|
|
40
|
-
begin
|
41
|
-
env.ssh = ssh
|
42
|
-
logger.tagged "ssh" do
|
43
|
-
yield
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def spawn_container(env)
|
50
|
-
env.container = ::Docker::Container.create create_options
|
51
|
-
env.container.start
|
52
|
-
|
53
|
-
env.job.add_to_output "using #{Socket.gethostname}/#{env.container.id}\n"
|
54
|
-
|
55
|
-
env.container_addr = env.container.json['NetworkSettings']['IPAddress']
|
56
|
-
env.docker_repo_dir = Pathname.new(config.docker.remote_dir).join(env.job.message.name)
|
57
|
-
|
58
|
-
logger.tagged "docker #{env.container.id}" do
|
59
|
-
begin
|
60
|
-
logger.info "start container"
|
61
|
-
sleep 3
|
62
|
-
yield
|
63
|
-
ensure
|
64
|
-
env.container.stop
|
65
|
-
logger.info "stop container"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def create_options
|
71
|
-
{
|
72
|
-
'Cmd' => config.docker.init,
|
73
|
-
'Image' => config.docker.image,
|
74
|
-
'Memory' => 1610612736, # 1.5g
|
75
|
-
}.merge(config.docker.create_options || {})
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'evrone/ci/common'
|
2
|
-
|
3
|
-
module Evrone
|
4
|
-
module CI
|
5
|
-
module Worker
|
6
|
-
|
7
|
-
LocalCreateDirs = Struct.new(:app) do
|
8
|
-
|
9
|
-
include Common::Helper::Shell
|
10
|
-
include Worker::Helper::Config
|
11
|
-
|
12
|
-
def call(env)
|
13
|
-
tmp_dir! env
|
14
|
-
|
15
|
-
app.call env
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def tmp_dir!(env)
|
21
|
-
env.tmp_dir = env.path_prefix.join(config.tmp_dir_name)
|
22
|
-
.join(env.job.message.name)
|
23
|
-
recreate env.tmp_dir
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'evrone/ci/common'
|
2
|
-
|
3
|
-
module Evrone
|
4
|
-
module CI
|
5
|
-
module Worker
|
6
|
-
|
7
|
-
LocalScript = Struct.new(:app) do
|
8
|
-
|
9
|
-
include Common::Helper::Shell
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
script = env.tmp_dir.join("build.sh")
|
13
|
-
write_file script, content(env), 0700
|
14
|
-
|
15
|
-
code = bash file: script, &env.job.method(:add_to_output)
|
16
|
-
|
17
|
-
if code == 0
|
18
|
-
app.call env
|
19
|
-
else
|
20
|
-
state = read_state(env)
|
21
|
-
case state
|
22
|
-
when "script"
|
23
|
-
code
|
24
|
-
else
|
25
|
-
code * -1
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
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
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Evrone::CI::Worker::DockerScript, run_docker: true do
|
4
|
-
let(:exit_code) { 0 }
|
5
|
-
let(:app) { ->(_) { exit_code } }
|
6
|
-
let(:script) { "echo script" }
|
7
|
-
let(:before_script) { "echo before_script" }
|
8
|
-
let(:after_script) { "echo after_script" }
|
9
|
-
let(:job) { create :job,
|
10
|
-
script: script,
|
11
|
-
before_script: before_script,
|
12
|
-
after_script: after_script }
|
13
|
-
let(:env) { OpenStruct.new job: job }
|
14
|
-
let(:mid) { described_class.new app }
|
15
|
-
let(:docker_mid) { Evrone::CI::Worker::DockerStartContainer.new(mid) }
|
16
|
-
|
17
|
-
subject { docker_mid.call env }
|
18
|
-
|
19
|
-
before do
|
20
|
-
stub(env).docker_repo_dir { Pathname.new '/tmp' }
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should be" do
|
24
|
-
expect(subject).to eq 0
|
25
|
-
job.release
|
26
|
-
expect(all_job_log_output).to match("script")
|
27
|
-
expect(all_job_log_output).to match("after_script")
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when script failed" do
|
31
|
-
let(:script) { "false" }
|
32
|
-
it "should be" do
|
33
|
-
expect(subject).to eq(1)
|
34
|
-
job.release
|
35
|
-
expect(all_job_log_output).to match("after_script")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "when before_script failed" do
|
40
|
-
let(:before_script) { "false" }
|
41
|
-
it "should be" do
|
42
|
-
expect(subject).to eq(-1)
|
43
|
-
job.release
|
44
|
-
expect(all_job_log_output).to match("after_script")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Evrone::CI::Worker::DockerStartContainer, run_docker: true do
|
4
|
-
let(:exit_code) { 0 }
|
5
|
-
let(:app) { ->(_) { exit_code } }
|
6
|
-
let(:job) { create :job }
|
7
|
-
let(:env) { OpenStruct.new job: job }
|
8
|
-
let(:mid) { described_class.new app }
|
9
|
-
|
10
|
-
subject { mid.call env }
|
11
|
-
|
12
|
-
it "should be" do
|
13
|
-
expect(subject).to eq 0
|
14
|
-
|
15
|
-
expect(env.ssh).to be
|
16
|
-
expect(env.container).to be
|
17
|
-
expect(env.docker_repo_dir.to_s).to eq "/home/ci/evrone/test-repo"
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pathname'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
describe Evrone::CI::Worker::LocalCreateDirs do
|
6
|
-
let(:app) { ->(_) { 0 } }
|
7
|
-
let(:job) { create :job }
|
8
|
-
let(:path_prefix) { Pathname.new '/tmp/.ci' }
|
9
|
-
let(:env) { OpenStruct.new job: job, path_prefix: path_prefix }
|
10
|
-
let(:mid) { described_class.new app }
|
11
|
-
|
12
|
-
subject { mid.call env }
|
13
|
-
|
14
|
-
after do
|
15
|
-
FileUtils.rm_rf path_prefix
|
16
|
-
end
|
17
|
-
|
18
|
-
it { should eq 0 }
|
19
|
-
|
20
|
-
context "create and assign directories" do
|
21
|
-
|
22
|
-
before do
|
23
|
-
subject
|
24
|
-
end
|
25
|
-
|
26
|
-
it "tmp_dir" do
|
27
|
-
expect(env.tmp_dir.to_s).to eq '/tmp/.ci/tmp/evrone/test-repo'
|
28
|
-
expect(File.directory? env.tmp_dir).to be
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pathname'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
describe Evrone::CI::Worker::LocalScript do
|
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 }
|
15
|
-
|
16
|
-
subject { mid.call env }
|
17
|
-
|
18
|
-
after do
|
19
|
-
FileUtils.rm_rf path_prefix
|
20
|
-
end
|
21
|
-
|
22
|
-
before do
|
23
|
-
FileUtils.mkdir_p work_dir
|
24
|
-
FileUtils.mkdir_p tmp_dir
|
25
|
-
end
|
26
|
-
|
27
|
-
it { should eq 0 }
|
28
|
-
|
29
|
-
it "should capture output" do
|
30
|
-
subject
|
31
|
-
job.release
|
32
|
-
expect(last_job_log_message.log).to be_include("before_script\nscript\n")
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when script failed" do
|
36
|
-
let(:script) { 'false' }
|
37
|
-
it { should satisfy { |n| [1,127].include?(n) } }
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when before_script failed" do
|
41
|
-
let(:before_script) { 'false' }
|
42
|
-
it { should satisfy { |n| [-1,-127].include?(n) } }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|