evrone-ci-worker 0.2.0.pre4 → 0.2.0.pre5
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.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/bin/evrone-ci-worker +0 -1
- data/docker/bootstrap.sh +40 -11
- data/evrone-ci-worker.gemspec +0 -1
- data/lib/evrone/ci/worker/configuration.rb +3 -8
- data/lib/evrone/ci/worker/docker.rb +0 -2
- data/lib/evrone/ci/worker/job.rb +11 -6
- data/lib/evrone/ci/worker/local.rb +0 -1
- data/lib/evrone/ci/worker/middlewares/docker_script.rb +34 -10
- data/lib/evrone/ci/worker/middlewares/docker_start_container.rb +4 -3
- data/lib/evrone/ci/worker/middlewares/local_create_dirs.rb +0 -17
- data/lib/evrone/ci/worker/middlewares/local_script.rb +1 -1
- data/lib/evrone/ci/worker/middlewares/update_job_status.rb +1 -1
- data/lib/evrone/ci/worker/version.rb +1 -1
- data/lib/evrone/ci/worker.rb +4 -4
- data/spec/lib/worker/configuration_spec.rb +1 -2
- data/spec/lib/worker/job_spec.rb +21 -11
- data/spec/lib/worker/middlewares/docker_script_spec.rb +12 -2
- data/spec/lib/worker/middlewares/local_create_dirs_spec.rb +0 -10
- data/spec/lib/worker/middlewares/local_script_spec.rb +2 -1
- data/spec/support/all_job_log_output.rb +3 -0
- data/spec/support/create.rb +1 -15
- data/spec/support/last_job_logs_message.rb +3 -0
- metadata +10 -31
- data/lib/evrone/ci/worker/middlewares/docker_fetch_repo.rb +0 -73
- data/lib/evrone/ci/worker/middlewares/docker_webdav_cache.rb +0 -95
- data/lib/evrone/ci/worker/middlewares/local_fetch_repo.rb +0 -47
- data/lib/evrone/ci/worker/runner/docker.rb +0 -0
- data/lib/evrone/ci/worker/runner/local.rb +0 -52
- data/spec/lib/worker/middlewares/docker_fetch_repo_spec.rb +0 -26
- data/spec/lib/worker/middlewares/docker_webdav_cache_spec.rb +0 -49
- data/spec/lib/worker/middlewares/local_fetch_repo_spec.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73edf7643aed536ce533c1bf4933c5395952d512
|
4
|
+
data.tar.gz: b7ba035941f4101819506ab44f0dcf9e655d4e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c9d3c82ba6750443f38bb71ca029f24128fb04f823af0105bff44093e952fc311be39e347b38992d0b5fcef49fdc9c790bf3c017c76b2527f648aef785eb8ee
|
7
|
+
data.tar.gz: bfeb80657ba8e550dbe0eceb132815eff2080f98442ece836a710a2dc9f5a122f736f8ac06a97f0f52e08fc962c2666ac279ffe1d15b4ef16ca65c5a53f5c049
|
data/Rakefile
CHANGED
data/bin/evrone-ci-worker
CHANGED
data/docker/bootstrap.sh
CHANGED
@@ -6,12 +6,20 @@ set -e
|
|
6
6
|
echo "deb http://us.archive.ubuntu.com/ubuntu/ precise universe" >> /etc/apt/sources.list
|
7
7
|
echo "deb http://us.archive.ubuntu.com/ubuntu/ precise multiverse" >> /etc/apt/sources.list
|
8
8
|
|
9
|
+
# fixes locales
|
10
|
+
locale-gen en_US.UTF-8
|
11
|
+
dpkg-reconfigure -fnoninteractive locales
|
12
|
+
update-locale LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8" LANGUAGE="en_US"
|
13
|
+
export LANGUAGE=en_US
|
14
|
+
export LANG=en_US.UTF-8
|
15
|
+
export LC_ALL=en_US.UTF-8
|
16
|
+
|
9
17
|
# replace init
|
10
18
|
dpkg-divert --local --rename --add /sbin/initctl
|
11
19
|
ln -s /bin/true /sbin/initctl
|
12
20
|
|
13
21
|
apt-get -qy update
|
14
|
-
apt-get install -qy curl git-core build-essential
|
22
|
+
apt-get install -qy curl git-core build-essential vim-tiny
|
15
23
|
|
16
24
|
# add evrone repo
|
17
25
|
mkdir -p /etc/apt/sources.list.d
|
@@ -21,7 +29,7 @@ apt-get -qy update
|
|
21
29
|
|
22
30
|
# add packages
|
23
31
|
apt-get install -qy libmysqlclient-dev libpq-dev imagemagick libmagickwand-dev \
|
24
|
-
libcurl4-openssl-dev nodejs
|
32
|
+
libcurl4-openssl-dev nodejs libxml2-dev libxslt-dev \
|
25
33
|
openjdk-7-jre-headless libsqlite3-dev libgeos-dev ruby
|
26
34
|
|
27
35
|
# install runit
|
@@ -35,24 +43,43 @@ echo "ci:ci" | chpasswd
|
|
35
43
|
apt-get -qy install sudo
|
36
44
|
echo "ci ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
37
45
|
|
38
|
-
# fixes locales
|
39
|
-
locale-gen en_US.UTF-8
|
40
|
-
dpkg-reconfigure -fnoninteractive locales
|
41
|
-
update-locale LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8" LANGUAGE="en_US"
|
42
|
-
|
43
46
|
# install ssh
|
44
47
|
apt-get install -qy openssh-server
|
45
48
|
mkdir -p /var/run/sshd
|
46
49
|
sv-gen ssh "/usr/sbin/sshd -D -e"
|
47
50
|
|
48
51
|
# install postgresql
|
49
|
-
apt-get install -qy postgresql
|
50
|
-
echo "
|
52
|
+
apt-get install -qy postgresql-9.1 postgresql-contrib-9.1
|
53
|
+
echo "local all all trust" > /etc/postgresql/9.1/main/pg_hba.conf
|
54
|
+
echo "host all all all trust" >> /etc/postgresql/9.1/main/pg_hba.conf
|
51
55
|
sv-gen postgresql "/usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf" postgres
|
52
56
|
|
53
57
|
# install mysql
|
54
|
-
apt-get install -qy mysql-server
|
55
|
-
sv-gen
|
58
|
+
apt-get install -qy mysql-server-5.5
|
59
|
+
sv-gen mysql "/usr/sbin/mysqld" mysql
|
60
|
+
|
61
|
+
# install redis-server
|
62
|
+
apt-get install -qy redis-server
|
63
|
+
sed -i 's|daemonize yes|daemonize no|g' /etc/redis/redis.conf
|
64
|
+
sv-gen redis-server "/usr/bin/redis-server /etc/redis/redis.conf" redis
|
65
|
+
|
66
|
+
# install rabbitmq-server
|
67
|
+
apt-get install -qy rabbitmq-server
|
68
|
+
sv-gen rabbitmq-server "/usr/sbin/rabbitmq-server" root
|
69
|
+
|
70
|
+
# install elasticsearch
|
71
|
+
ES_PKG=elasticsearch-0.90.5.deb
|
72
|
+
curl https://download.elasticsearch.org/elasticsearch/elasticsearch/$ES_PKG -o /tmp/$ES_PKG
|
73
|
+
dpkg -i /tmp/$ES_PKG
|
74
|
+
rm -f /tmp/$ES_PKG
|
75
|
+
sv-gen elasticsearch "/usr/share/elasticsearch/bin/elasticsearch -f -Des.path.data=/var/lib/elasticsearch" elasticsearch
|
76
|
+
|
77
|
+
# install phantomjs
|
78
|
+
PH_PKG=phantomjs-1.9.2-linux-x86_64.tar.bz2
|
79
|
+
curl https://phantomjs.googlecode.com/files/$PH_PKG -o /tmp/$PH_PKG
|
80
|
+
tar -jxf /tmp/$PH_PKG -C /usr/local
|
81
|
+
rm -f /tmp/$PH_PKG
|
82
|
+
ln -sf /usr/local/$(basename $PH_PKG .tar.bz2)/bin/phantomjs /usr/local/bin
|
56
83
|
|
57
84
|
# add ruby
|
58
85
|
apt-get install -qy rbenv rbenv-2.0.0-p195 rbenv-1.9.3-p448
|
@@ -64,3 +91,5 @@ apt-get -qy clean autoremove
|
|
64
91
|
|
65
92
|
sv-enable postgresql
|
66
93
|
sv-enable ssh
|
94
|
+
sv-enable mysql
|
95
|
+
sv-enable redis-server
|
data/evrone-ci-worker.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'evrone-common-amqp', '~> 0.1.1'
|
24
24
|
spec.add_runtime_dependency 'docker-api', '= 1.5.4'
|
25
25
|
spec.add_runtime_dependency 'hashr', '= 0.0.22'
|
26
|
-
spec.add_runtime_dependency 'net-scp', '= 1.1.2'
|
27
26
|
|
28
27
|
spec.add_development_dependency "bundler", "~> 1.3"
|
29
28
|
spec.add_development_dependency "rake"
|
@@ -19,15 +19,10 @@ module Evrone
|
|
19
19
|
timeout: 30 * 60,
|
20
20
|
logger: Common::TaggedLogging.new(Logger.new STDOUT),
|
21
21
|
|
22
|
-
|
23
|
-
repo_dir_name: "repo",
|
24
|
-
tmp_dir_name: "tmp",
|
22
|
+
tmp_dir_name: "tmp",
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
workers: 1,
|
29
|
-
path_prefix: nil,
|
30
|
-
webdav_cache_url:nil,
|
24
|
+
workers: 1,
|
25
|
+
path_prefix: nil,
|
31
26
|
|
32
27
|
docker: {
|
33
28
|
remote_dir: "/home/ci",
|
data/lib/evrone/ci/worker/job.rb
CHANGED
@@ -12,14 +12,13 @@ module Evrone
|
|
12
12
|
|
13
13
|
def initialize(perform_job_message)
|
14
14
|
@output_counter = 0
|
15
|
-
@output = ""
|
16
15
|
@message = perform_job_message
|
16
|
+
@output = Common::OutputBuffer.new(&method(:publish_job_log_message))
|
17
17
|
end
|
18
18
|
|
19
19
|
def add_to_output(str)
|
20
20
|
output << str
|
21
21
|
logger.debug str.strip if logger.level == 0
|
22
|
-
JobLogsConsumer.publish create_job_log_message(str)
|
23
22
|
end
|
24
23
|
|
25
24
|
def add_command_to_output(cmd)
|
@@ -30,14 +29,20 @@ module Evrone
|
|
30
29
|
add_to_output log.split(/\n/).map{|i| " ===> #{i}\n" }.join
|
31
30
|
end
|
32
31
|
|
33
|
-
def
|
32
|
+
def release
|
33
|
+
output.close
|
34
|
+
end
|
35
|
+
|
36
|
+
def publish_job_log_message(str)
|
34
37
|
@output_counter += 1
|
35
|
-
Message::JobLog.new(
|
38
|
+
log = Message::JobLog.new(
|
36
39
|
build_id: message.id,
|
37
40
|
job_id: message.job_id,
|
38
|
-
tm:
|
39
|
-
log:
|
41
|
+
tm: output_counter,
|
42
|
+
log: str
|
40
43
|
)
|
44
|
+
JobLogsConsumer.publish log
|
45
|
+
log
|
41
46
|
end
|
42
47
|
|
43
48
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'net/scp'
|
2
|
-
|
3
1
|
module Evrone
|
4
2
|
module CI
|
5
3
|
module Worker
|
@@ -7,10 +5,14 @@ module Evrone
|
|
7
5
|
DockerScript = Struct.new(:app) do
|
8
6
|
|
9
7
|
include Helper::Logger
|
8
|
+
include Helper::Config
|
9
|
+
include Common::Helper::UploadShCommand
|
10
10
|
|
11
11
|
def call(env)
|
12
12
|
if env.ssh && env.docker_repo_dir
|
13
13
|
code = run_script(env)
|
14
|
+
run_after_script(env)
|
15
|
+
|
14
16
|
if code == 0
|
15
17
|
app.call env
|
16
18
|
else
|
@@ -29,24 +31,46 @@ module Evrone
|
|
29
31
|
private
|
30
32
|
|
31
33
|
def run_script(env)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
home = config.docker.remote_dir
|
35
|
+
file = [home, ".ci_build.sh"].join("/")
|
36
|
+
|
37
|
+
script = [upload_sh_command(file, script_content(env, home))]
|
38
|
+
script << "env - HOME=$HOME bash #{file}"
|
39
|
+
script = script.join(" && ")
|
40
|
+
|
41
|
+
env.ssh.spawn script, chdir: home, &env.job.method(:add_to_output)
|
42
|
+
end
|
43
|
+
|
44
|
+
def run_after_script(env)
|
45
|
+
home = config.docker.remote_dir
|
46
|
+
file = [home, ".ci_after_build.sh"].join("/")
|
47
|
+
|
48
|
+
script = [upload_sh_command(file, after_script_content(env))]
|
49
|
+
script << "env - HOME=$HOME bash #{file}"
|
50
|
+
script = script.join(" && ")
|
51
|
+
|
52
|
+
env.ssh.spawn script, chdir: home, &env.job.method(:add_to_output)
|
36
53
|
end
|
37
54
|
|
38
|
-
def
|
55
|
+
def script_content(env, home)
|
39
56
|
buf = ["set -e"]
|
40
|
-
buf << "echo before_script > #{
|
57
|
+
buf << "echo before_script > #{home}/.ci_state"
|
41
58
|
buf << env.job.message.before_script
|
42
|
-
buf << "echo script > #{
|
59
|
+
buf << "echo script > #{home}/.ci_state"
|
43
60
|
buf << env.job.message.script
|
44
61
|
buf.join("\n")
|
45
62
|
end
|
46
63
|
|
64
|
+
def after_script_content(env)
|
65
|
+
buf = ["set -e"]
|
66
|
+
buf << env.job.message.after_script
|
67
|
+
buf.join("\n")
|
68
|
+
end
|
69
|
+
|
47
70
|
def read_state(env)
|
71
|
+
home = config.docker.remote_dir
|
48
72
|
buf = ""
|
49
|
-
state_file =
|
73
|
+
state_file = "#{home}/.ci_state"
|
50
74
|
env.ssh.spawn "cat #{state_file}" do |out|
|
51
75
|
buf << out
|
52
76
|
end
|
@@ -52,9 +52,10 @@ module Evrone
|
|
52
52
|
|
53
53
|
env.job.add_to_output "using #{Socket.gethostname}/#{env.container.id}\n"
|
54
54
|
|
55
|
-
env.container_addr
|
56
|
-
env.container_addr
|
57
|
-
env.
|
55
|
+
env.container_addr = config.docker.ssh.host
|
56
|
+
env.container_addr ||= env.container.json['NetworkSettings']['IPAddress']
|
57
|
+
env.container_gateway ||= env.container.json['NetworkSettings']['Gateway']
|
58
|
+
env.docker_repo_dir = Pathname.new(config.docker.remote_dir).join(env.job.message.name)
|
58
59
|
|
59
60
|
logger.tagged "DOCKER #{env.container.id}" do
|
60
61
|
begin
|
@@ -11,8 +11,6 @@ module Evrone
|
|
11
11
|
|
12
12
|
def call(env)
|
13
13
|
tmp_dir! env
|
14
|
-
work_dir! env
|
15
|
-
repo_dir! env
|
16
14
|
|
17
15
|
app.call env
|
18
16
|
end
|
@@ -24,21 +22,6 @@ module Evrone
|
|
24
22
|
.join(env.job.message.name)
|
25
23
|
recreate env.tmp_dir
|
26
24
|
end
|
27
|
-
|
28
|
-
def work_dir!(env)
|
29
|
-
env.work_dir = env.path_prefix.join(config.work_dir_name)
|
30
|
-
.join(env.job.message.name)
|
31
|
-
|
32
|
-
recreate env.work_dir
|
33
|
-
end
|
34
|
-
|
35
|
-
def repo_dir!(env)
|
36
|
-
env.repo_dir = env.path_prefix.join(config.repo_dir_name)
|
37
|
-
.join(env.job.message.name)
|
38
|
-
|
39
|
-
mkdir env.repo_dir
|
40
|
-
end
|
41
|
-
|
42
25
|
end
|
43
26
|
|
44
27
|
end
|
@@ -12,7 +12,7 @@ module Evrone
|
|
12
12
|
script = env.tmp_dir.join("build.sh")
|
13
13
|
write_file script, content(env), 0700
|
14
14
|
|
15
|
-
code = bash file: script,
|
15
|
+
code = bash file: script, &env.job.method(:add_to_output)
|
16
16
|
|
17
17
|
if code == 0
|
18
18
|
app.call env
|
@@ -20,7 +20,7 @@ module Evrone
|
|
20
20
|
begin
|
21
21
|
rs = app.call env
|
22
22
|
rescue Exception => e
|
23
|
-
env.job.add_to_output("
|
23
|
+
env.job.add_to_output("\n\nERROR: #{e.inspect}\n")
|
24
24
|
logger.error("ERROR: #{e.inspect}\n BACKTRACE:\n#{e.backtrace.map{|i| " #{i}" }.join("\n")}")
|
25
25
|
end
|
26
26
|
|
data/lib/evrone/ci/worker.rb
CHANGED
@@ -20,18 +20,16 @@ module Evrone
|
|
20
20
|
autoload :Local, File.expand_path("../worker/local", __FILE__)
|
21
21
|
autoload :Docker, File.expand_path("../worker/docker", __FILE__)
|
22
22
|
autoload :CLI, File.expand_path("../worker/cli", __FILE__)
|
23
|
+
autoload :OutputBuffer, File.expand_path("../worker/output_buffer", __FILE__)
|
23
24
|
|
24
25
|
autoload :LogJob, File.expand_path("../worker/middlewares/log_job", __FILE__)
|
25
26
|
autoload :UpdateJobStatus, File.expand_path("../worker/middlewares/update_job_status", __FILE__)
|
26
27
|
|
27
28
|
autoload :LocalCreateDirs, File.expand_path("../worker/middlewares/local_create_dirs", __FILE__)
|
28
|
-
autoload :LocalFetchRepo, File.expand_path("../worker/middlewares/local_fetch_repo", __FILE__)
|
29
29
|
autoload :LocalScript, File.expand_path("../worker/middlewares/local_script", __FILE__)
|
30
30
|
|
31
31
|
autoload :DockerStartContainer, File.expand_path("../worker/middlewares/docker_start_container", __FILE__)
|
32
|
-
autoload :DockerFetchRepo, File.expand_path("../worker/middlewares/docker_fetch_repo", __FILE__)
|
33
32
|
autoload :DockerScript, File.expand_path("../worker/middlewares/docker_script", __FILE__)
|
34
|
-
autoload :DockerWebdavCache, File.expand_path("../worker/middlewares/docker_webdav_cache", __FILE__)
|
35
33
|
|
36
34
|
module Helper
|
37
35
|
autoload :Logger, File.expand_path("../worker/helper/logger", __FILE__)
|
@@ -69,7 +67,9 @@ module Evrone
|
|
69
67
|
end
|
70
68
|
|
71
69
|
def perform(job, path_prefix)
|
72
|
-
run_class.new(job, path_prefix).perform
|
70
|
+
rs = run_class.new(job, path_prefix).perform
|
71
|
+
job.release
|
72
|
+
rs
|
73
73
|
end
|
74
74
|
|
75
75
|
def run_class
|
@@ -6,8 +6,7 @@ describe Evrone::CI::Worker::Configuration do
|
|
6
6
|
|
7
7
|
its(:run) { should eq :docker }
|
8
8
|
its(:docker) { should be }
|
9
|
-
its(:
|
10
|
-
its(:repo_dir_name) { should eq 'repo' }
|
9
|
+
its(:tmp_dir_name) { should eq 'tmp' }
|
11
10
|
its(:timeout) { should eq 1800 }
|
12
11
|
its(:amqp_url) { should be_nil }
|
13
12
|
|
data/spec/lib/worker/job_spec.rb
CHANGED
@@ -8,13 +8,13 @@ describe Evrone::CI::Worker::Job do
|
|
8
8
|
|
9
9
|
context "just created" do
|
10
10
|
its(:message) { should eq message }
|
11
|
-
its(:output) { should
|
11
|
+
its(:output) { should be_an_instance_of(Evrone::CI::Common::OutputBuffer) }
|
12
12
|
its(:output_counter) { should eq 0 }
|
13
13
|
end
|
14
14
|
|
15
|
-
context "
|
15
|
+
context "publish_job_log_message" do
|
16
16
|
let(:data) { 'log' }
|
17
|
-
subject { job.
|
17
|
+
subject { job.publish_job_log_message data }
|
18
18
|
|
19
19
|
it { should be_an_instance_of(Evrone::CI::Message::JobLog) }
|
20
20
|
its(:job_id) { should eq job.message.job_id }
|
@@ -32,13 +32,17 @@ describe Evrone::CI::Worker::Job do
|
|
32
32
|
context "add_to_output" do
|
33
33
|
let(:data) { 'data' }
|
34
34
|
let(:messages) { Evrone::CI::Worker::JobLogsConsumer.messages }
|
35
|
-
subject
|
35
|
+
subject do
|
36
|
+
job.add_to_output(data)
|
37
|
+
job.output.flush
|
38
|
+
job
|
39
|
+
end
|
36
40
|
|
37
|
-
its(:output) { should eq data }
|
38
41
|
it "should delivery message" do
|
39
42
|
expect {
|
40
43
|
subject
|
41
44
|
}.to change(messages, :size).by(1)
|
45
|
+
expect(messages.first.log).to eq data
|
42
46
|
end
|
43
47
|
|
44
48
|
it "should increment output_counter" do
|
@@ -52,14 +56,17 @@ describe Evrone::CI::Worker::Job do
|
|
52
56
|
context "add_command_to_output" do
|
53
57
|
let(:data) { 'data' }
|
54
58
|
let(:messages) { Evrone::CI::Worker::JobLogsConsumer.messages }
|
55
|
-
subject
|
56
|
-
|
57
|
-
|
59
|
+
subject do
|
60
|
+
job.add_command_to_output(data)
|
61
|
+
job.output.flush
|
62
|
+
job
|
63
|
+
end
|
58
64
|
|
59
65
|
it "should delivery message" do
|
60
66
|
expect {
|
61
67
|
subject
|
62
68
|
}.to change(messages, :size).by(1)
|
69
|
+
expect(messages.first.log).to eq "$ #{data}\n"
|
63
70
|
end
|
64
71
|
|
65
72
|
it "should increment output_counter" do
|
@@ -73,14 +80,17 @@ describe Evrone::CI::Worker::Job do
|
|
73
80
|
context "add_trace_to_output" do
|
74
81
|
let(:data) { 'data' }
|
75
82
|
let(:messages) { Evrone::CI::Worker::JobLogsConsumer.messages }
|
76
|
-
subject
|
77
|
-
|
78
|
-
|
83
|
+
subject do
|
84
|
+
job.add_trace_to_output(data)
|
85
|
+
job.output.flush
|
86
|
+
job
|
87
|
+
end
|
79
88
|
|
80
89
|
it "should delivery message" do
|
81
90
|
expect {
|
82
91
|
subject
|
83
92
|
}.to change(messages, :size).by(1)
|
93
|
+
expect(messages.first.log).to eq " ===> #{data}\n"
|
84
94
|
end
|
85
95
|
|
86
96
|
it "should increment output_counter" do
|
@@ -5,7 +5,11 @@ describe Evrone::CI::Worker::DockerScript, run_docker: true do
|
|
5
5
|
let(:app) { ->(_) { exit_code } }
|
6
6
|
let(:script) { "echo script" }
|
7
7
|
let(:before_script) { "echo before_script" }
|
8
|
-
let(:
|
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 }
|
9
13
|
let(:env) { OpenStruct.new job: job }
|
10
14
|
let(:mid) { described_class.new app }
|
11
15
|
let(:docker_mid) { Evrone::CI::Worker::DockerStartContainer.new(mid) }
|
@@ -18,13 +22,17 @@ describe Evrone::CI::Worker::DockerScript, run_docker: true do
|
|
18
22
|
|
19
23
|
it "should be" do
|
20
24
|
expect(subject).to eq 0
|
21
|
-
|
25
|
+
job.release
|
26
|
+
expect(all_job_log_output).to match("script")
|
27
|
+
expect(all_job_log_output).to match("after_script")
|
22
28
|
end
|
23
29
|
|
24
30
|
context "when script failed" do
|
25
31
|
let(:script) { "false" }
|
26
32
|
it "should be" do
|
27
33
|
expect(subject).to eq(1)
|
34
|
+
job.release
|
35
|
+
expect(all_job_log_output).to match("after_script")
|
28
36
|
end
|
29
37
|
end
|
30
38
|
|
@@ -32,6 +40,8 @@ describe Evrone::CI::Worker::DockerScript, run_docker: true do
|
|
32
40
|
let(:before_script) { "false" }
|
33
41
|
it "should be" do
|
34
42
|
expect(subject).to eq(-1)
|
43
|
+
job.release
|
44
|
+
expect(all_job_log_output).to match("after_script")
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
@@ -23,20 +23,10 @@ describe Evrone::CI::Worker::LocalCreateDirs do
|
|
23
23
|
subject
|
24
24
|
end
|
25
25
|
|
26
|
-
it "work_dir" do
|
27
|
-
expect(env.work_dir.to_s).to eq '/tmp/.ci/work/evrone/test-repo'
|
28
|
-
expect(File.directory? env.work_dir).to be
|
29
|
-
end
|
30
|
-
|
31
26
|
it "tmp_dir" do
|
32
27
|
expect(env.tmp_dir.to_s).to eq '/tmp/.ci/tmp/evrone/test-repo'
|
33
28
|
expect(File.directory? env.tmp_dir).to be
|
34
29
|
end
|
35
30
|
|
36
|
-
it "repo_dir" do
|
37
|
-
expect(env.repo_dir.to_s).to eq '/tmp/.ci/repo/evrone/test-repo'
|
38
|
-
expect(File.directory? env.repo_dir).to be
|
39
|
-
end
|
40
|
-
|
41
31
|
end
|
42
32
|
end
|
@@ -28,7 +28,8 @@ describe Evrone::CI::Worker::LocalScript do
|
|
28
28
|
|
29
29
|
it "should capture output" do
|
30
30
|
subject
|
31
|
-
|
31
|
+
job.release
|
32
|
+
expect(last_job_log_message.log).to be_include("before_script\nscript\n")
|
32
33
|
end
|
33
34
|
|
34
35
|
context "when script failed" do
|
data/spec/support/create.rb
CHANGED
@@ -6,12 +6,8 @@ def create(who, *args)
|
|
6
6
|
|
7
7
|
case who
|
8
8
|
|
9
|
-
when :local_repo
|
10
|
-
Evrone::CI::Worker.root.join("fixtures/repo").to_s
|
11
|
-
|
12
9
|
when :message
|
13
|
-
name
|
14
|
-
|
10
|
+
name = args.shift
|
15
11
|
klass = Evrone::CI::Message.const_get name
|
16
12
|
klass.test_message options
|
17
13
|
|
@@ -19,15 +15,5 @@ def create(who, *args)
|
|
19
15
|
message = options[:message] || create(:message, 'PerformJob', options)
|
20
16
|
Evrone::CI::Worker::Job.new message
|
21
17
|
|
22
|
-
when :working_dirs
|
23
|
-
|
24
|
-
Evrone::CI::Worker::WorkingDirs.create args.shift, args.shift || '/tmp/.test'
|
25
|
-
|
26
|
-
when :git
|
27
|
-
build = args.shift
|
28
|
-
path = args.shift
|
29
|
-
Evrone::CI::SCM::Git.new build.src, build.sha, path, deploy_key: build.deploy_key, &build.method(:add_to_output)
|
30
|
-
|
31
18
|
end
|
32
|
-
|
33
19
|
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.pre5
|
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-10-
|
11
|
+
date: 2013-10-07 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.pre5
|
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.pre5
|
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.pre5
|
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.pre5
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: evrone-common-amqp
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.0.22
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: net-scp
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 1.1.2
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 1.1.2
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: bundler
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -183,34 +169,28 @@ files:
|
|
183
169
|
- lib/evrone/ci/worker/initializers/amqp.rb
|
184
170
|
- lib/evrone/ci/worker/job.rb
|
185
171
|
- lib/evrone/ci/worker/local.rb
|
186
|
-
- lib/evrone/ci/worker/middlewares/docker_fetch_repo.rb
|
187
172
|
- lib/evrone/ci/worker/middlewares/docker_script.rb
|
188
173
|
- lib/evrone/ci/worker/middlewares/docker_start_container.rb
|
189
|
-
- lib/evrone/ci/worker/middlewares/docker_webdav_cache.rb
|
190
174
|
- lib/evrone/ci/worker/middlewares/local_create_dirs.rb
|
191
|
-
- lib/evrone/ci/worker/middlewares/local_fetch_repo.rb
|
192
175
|
- lib/evrone/ci/worker/middlewares/local_script.rb
|
193
176
|
- lib/evrone/ci/worker/middlewares/log_job.rb
|
194
177
|
- lib/evrone/ci/worker/middlewares/update_job_status.rb
|
195
|
-
- lib/evrone/ci/worker/runner/docker.rb
|
196
|
-
- lib/evrone/ci/worker/runner/local.rb
|
197
178
|
- lib/evrone/ci/worker/version.rb
|
198
179
|
- spec/lib/worker/configuration_spec.rb
|
199
180
|
- spec/lib/worker/docker_spec.rb
|
200
181
|
- spec/lib/worker/job_spec.rb
|
201
182
|
- spec/lib/worker/local_spec.rb
|
202
|
-
- spec/lib/worker/middlewares/docker_fetch_repo_spec.rb
|
203
183
|
- spec/lib/worker/middlewares/docker_script_spec.rb
|
204
184
|
- spec/lib/worker/middlewares/docker_start_container_spec.rb
|
205
|
-
- spec/lib/worker/middlewares/docker_webdav_cache_spec.rb
|
206
185
|
- spec/lib/worker/middlewares/local_create_dirs_spec.rb
|
207
|
-
- spec/lib/worker/middlewares/local_fetch_repo_spec.rb
|
208
186
|
- spec/lib/worker/middlewares/local_script_spec.rb
|
209
187
|
- spec/lib/worker/middlewares/log_job_spec.rb
|
210
188
|
- spec/lib/worker/middlewares/update_job_status_spec.rb
|
211
189
|
- spec/lib/worker_spec.rb
|
212
190
|
- spec/spec_helper.rb
|
191
|
+
- spec/support/all_job_log_output.rb
|
213
192
|
- spec/support/create.rb
|
193
|
+
- spec/support/last_job_logs_message.rb
|
214
194
|
- spec/support/shared_examples/update_job_status_message_spec.rb
|
215
195
|
homepage: ''
|
216
196
|
licenses:
|
@@ -241,16 +221,15 @@ test_files:
|
|
241
221
|
- spec/lib/worker/docker_spec.rb
|
242
222
|
- spec/lib/worker/job_spec.rb
|
243
223
|
- spec/lib/worker/local_spec.rb
|
244
|
-
- spec/lib/worker/middlewares/docker_fetch_repo_spec.rb
|
245
224
|
- spec/lib/worker/middlewares/docker_script_spec.rb
|
246
225
|
- spec/lib/worker/middlewares/docker_start_container_spec.rb
|
247
|
-
- spec/lib/worker/middlewares/docker_webdav_cache_spec.rb
|
248
226
|
- spec/lib/worker/middlewares/local_create_dirs_spec.rb
|
249
|
-
- spec/lib/worker/middlewares/local_fetch_repo_spec.rb
|
250
227
|
- spec/lib/worker/middlewares/local_script_spec.rb
|
251
228
|
- spec/lib/worker/middlewares/log_job_spec.rb
|
252
229
|
- spec/lib/worker/middlewares/update_job_status_spec.rb
|
253
230
|
- spec/lib/worker_spec.rb
|
254
231
|
- spec/spec_helper.rb
|
232
|
+
- spec/support/all_job_log_output.rb
|
255
233
|
- spec/support/create.rb
|
234
|
+
- spec/support/last_job_logs_message.rb
|
256
235
|
- spec/support/shared_examples/update_job_status_message_spec.rb
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'docker'
|
2
|
-
require 'evrone/common/spawn'
|
3
|
-
require 'net/scp'
|
4
|
-
|
5
|
-
module Evrone
|
6
|
-
module CI
|
7
|
-
module Worker
|
8
|
-
|
9
|
-
DockerFetchRepo = Struct.new(:app) do
|
10
|
-
|
11
|
-
include Helper::Logger
|
12
|
-
include Helper::Config
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
if env.ssh && env.docker_repo_dir
|
16
|
-
code = -1
|
17
|
-
|
18
|
-
code = prepare_ssh_files(env)
|
19
|
-
code = spawn_script(env) if code == 0
|
20
|
-
|
21
|
-
if code == 0
|
22
|
-
app.call env
|
23
|
-
else
|
24
|
-
code * -1
|
25
|
-
end
|
26
|
-
else
|
27
|
-
app.call env
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def prepare_ssh_files(env)
|
34
|
-
dir = config.docker.remote_dir
|
35
|
-
scp = ::Net::SCP.new(env.ssh.connection)
|
36
|
-
|
37
|
-
code = env.ssh.spawn "mkdir -p #{dir}/.ssh && chmod 0700 #{dir}/.ssh", &env.job.method(:add_to_output)
|
38
|
-
|
39
|
-
if code == 0
|
40
|
-
config = "Host *\n"
|
41
|
-
config << " StrictHostKeyChecking no\n"
|
42
|
-
config << " UserKnownHostsFile /dev/null\n"
|
43
|
-
|
44
|
-
scp.upload! StringIO.new(config), "#{dir}/.ssh/config"
|
45
|
-
scp.upload! StringIO.new(env.job.message.deploy_key.to_s), "#{dir}/.ssh/id_rsa"
|
46
|
-
|
47
|
-
code = env.ssh.spawn "chmod 0600 #{dir}/.ssh/id_rsa", &env.job.method(:add_to_output)
|
48
|
-
end
|
49
|
-
code
|
50
|
-
end
|
51
|
-
|
52
|
-
def spawn_script(env)
|
53
|
-
scm = create_scm(env)
|
54
|
-
|
55
|
-
script = "sh -c '#{scm.make_fetch_command}'"
|
56
|
-
env.ssh.spawn script, &env.job.method(:add_to_output)
|
57
|
-
end
|
58
|
-
|
59
|
-
def create_scm(env)
|
60
|
-
SCM::Git.new(
|
61
|
-
env.job.message.src,
|
62
|
-
env.job.message.sha,
|
63
|
-
env.docker_repo_dir,
|
64
|
-
&env.job.method(:add_to_output)
|
65
|
-
)
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'net/scp'
|
2
|
-
|
3
|
-
module Evrone
|
4
|
-
module CI
|
5
|
-
module Worker
|
6
|
-
|
7
|
-
DockerWebdavCache = Struct.new(:app) do
|
8
|
-
|
9
|
-
include Helper::Config
|
10
|
-
include Helper::Logger
|
11
|
-
|
12
|
-
CASHER_URL = "https://raw.github.com/travis-ci/casher/master/bin/casher"
|
13
|
-
CASHER_BIN = "$HOME/.casher/bin/casher"
|
14
|
-
|
15
|
-
def call(env)
|
16
|
-
if env.ssh && config.webdav_cache_url
|
17
|
-
assign_url(env) &&
|
18
|
-
prepare(env) &&
|
19
|
-
fetch(env) &&
|
20
|
-
add(env)
|
21
|
-
end
|
22
|
-
|
23
|
-
rs = app.call env
|
24
|
-
|
25
|
-
if env.ssh && env.webdav_cache_url
|
26
|
-
push(env)
|
27
|
-
end
|
28
|
-
|
29
|
-
rs
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def assign_url(env)
|
35
|
-
release = nil
|
36
|
-
|
37
|
-
env.ssh.spawn "lsb_release -s -c" do |out|
|
38
|
-
release ||= out.gsub(/[^a-z0-9]/, '')
|
39
|
-
end
|
40
|
-
release = 'unknown' unless release
|
41
|
-
|
42
|
-
name = env.job.message.name.dup
|
43
|
-
name << "-#{release}"
|
44
|
-
name << "-#{env.job.message.matrix_keys.join("_")}.tgz"
|
45
|
-
name = name.gsub(/[^a-z0-9_\-.]/, '')
|
46
|
-
|
47
|
-
env.webdav_cache_url = "#{config.webdav_cache_url.dup}/#{name}"
|
48
|
-
true
|
49
|
-
end
|
50
|
-
|
51
|
-
def push(env)
|
52
|
-
cmd = %{
|
53
|
-
#{CASHER_BIN} push #{env.webdav_cache_url}
|
54
|
-
}.compact
|
55
|
-
|
56
|
-
logger.debug "push cache to #{env.webdav_cache_url.inspect}"
|
57
|
-
env.ssh.spawn cmd, &env.job.method(:add_trace_to_output)
|
58
|
-
true
|
59
|
-
end
|
60
|
-
|
61
|
-
def add(env)
|
62
|
-
cmd = %{
|
63
|
-
#{CASHER_BIN} add $HOME/cached
|
64
|
-
}.compact
|
65
|
-
env.ssh.spawn cmd, &env.job.method(:add_trace_to_output)
|
66
|
-
true
|
67
|
-
end
|
68
|
-
|
69
|
-
def fetch(env)
|
70
|
-
logger.debug "fetch cache from #{env.webdav_cache_url.inspect}"
|
71
|
-
cmd = %{
|
72
|
-
#{CASHER_BIN} fetch #{env.webdav_cache_url}
|
73
|
-
}.compact
|
74
|
-
env.ssh.spawn cmd, &env.job.method(:add_trace_to_output)
|
75
|
-
true
|
76
|
-
end
|
77
|
-
|
78
|
-
def prepare(env)
|
79
|
-
cmd = %{
|
80
|
-
export CASHER_DIR=$HOME/.casher &&
|
81
|
-
mkdir -p $CASHER_DIR/bin &&
|
82
|
-
curl #{CASHER_URL} -s -o #{CASHER_BIN} &&
|
83
|
-
chmod +x #{CASHER_BIN} &&
|
84
|
-
echo casher successfuly downloaded
|
85
|
-
}.compact
|
86
|
-
code = env.ssh.spawn cmd, &env.job.method(:add_trace_to_output)
|
87
|
-
code == 0
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'evrone/ci/common'
|
2
|
-
|
3
|
-
module Evrone
|
4
|
-
module CI
|
5
|
-
module Worker
|
6
|
-
|
7
|
-
LocalFetchRepo = Struct.new(:app) do
|
8
|
-
|
9
|
-
include Common::Helper::Shell
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
scm = create_scm(env)
|
13
|
-
|
14
|
-
if env.repo_dir
|
15
|
-
if scm.fetch == 0 && export(scm, env) == 0
|
16
|
-
app.call env
|
17
|
-
else
|
18
|
-
-1
|
19
|
-
end
|
20
|
-
else
|
21
|
-
app.call env
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def export(scm, env)
|
28
|
-
cmd = scm.class.make_export_command env.repo_dir, env.work_dir
|
29
|
-
env.job.add_command_to_output cmd
|
30
|
-
bash cmd, &env.job.method(:add_to_output)
|
31
|
-
end
|
32
|
-
|
33
|
-
def create_scm(env)
|
34
|
-
SCM::Git.new(
|
35
|
-
env.job.message.src,
|
36
|
-
env.job.message.sha,
|
37
|
-
env.repo_dir,
|
38
|
-
deploy_key: env.job.message.deploy_key,
|
39
|
-
&env.job.method(:add_to_output)
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
File without changes
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Evrone
|
2
|
-
module CI
|
3
|
-
module Worker
|
4
|
-
class Runner
|
5
|
-
class Local
|
6
|
-
|
7
|
-
include Worker::Helper::Logger
|
8
|
-
include Worker::Helper::Config
|
9
|
-
include Common::Helper::Shell
|
10
|
-
|
11
|
-
attr_reader :build, :path, :build_script
|
12
|
-
|
13
|
-
def initialize(build, path)
|
14
|
-
@build = build
|
15
|
-
@path = path
|
16
|
-
@build_script = path.tmp_dir.join(".build.sh").expand_path
|
17
|
-
end
|
18
|
-
|
19
|
-
def perform
|
20
|
-
make_build_script
|
21
|
-
run_build_script
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def run_build_script
|
27
|
-
bash file: build_script, chdir: path.work_dir, &method(:add_output)
|
28
|
-
end
|
29
|
-
|
30
|
-
def make_build_script
|
31
|
-
content = build.travis.to_queue.to_shell_script script_replaces do |env|
|
32
|
-
prepare_env env
|
33
|
-
end
|
34
|
-
write_file build_script, content, 0755
|
35
|
-
add_output_command build_script
|
36
|
-
end
|
37
|
-
|
38
|
-
def script_replaces
|
39
|
-
{ "SHARED_PATH" => path.shared_dir }
|
40
|
-
end
|
41
|
-
|
42
|
-
def prepare_env(env)
|
43
|
-
env['init'].unshift "echo 'copy repo from #{path.repo_dir} to #{path.work_dir}'"
|
44
|
-
env['init'].unshift build.csm.make_export_command path.repo_dir, path.work_dir
|
45
|
-
env
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Evrone::CI::Worker::DockerFetchRepo, run_docker: true do
|
4
|
-
let(:exit_code) { 0 }
|
5
|
-
let(:app) { ->(_) { exit_code } }
|
6
|
-
let(:options) { {} }
|
7
|
-
let(:job) { create :job, options }
|
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
|
-
it "should be" do
|
15
|
-
expect(subject).to eq 0
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when fail to fetch repo" do
|
19
|
-
let(:options) { { src: "/not-exists-repo.git" } }
|
20
|
-
it "should be" do
|
21
|
-
expect(subject).to eq(-128)
|
22
|
-
expect(job.output).to be_include("does not exist")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Evrone::CI::Worker::DockerWebdavCache, run_docker: true, webdav: true do
|
4
|
-
let(:exit_code) { 0 }
|
5
|
-
let(:app) {
|
6
|
-
->(env) {
|
7
|
-
file = "$HOME/cached/foo.txt"
|
8
|
-
cmd = %{
|
9
|
-
if [ -f #{file} ] ; then
|
10
|
-
echo "!exists" ;
|
11
|
-
cat #{file} ;
|
12
|
-
else
|
13
|
-
echo "!touch" ;
|
14
|
-
echo 1 > #{file} ;
|
15
|
-
fi
|
16
|
-
}.compact
|
17
|
-
env.ssh.spawn cmd, &job.method(:add_to_output)
|
18
|
-
}
|
19
|
-
}
|
20
|
-
let(:job) { create :job }
|
21
|
-
let(:env) { OpenStruct.new job: job }
|
22
|
-
let(:mid) { described_class.new app }
|
23
|
-
let(:docker_mid) { Evrone::CI::Worker::DockerStartContainer.new(mid) }
|
24
|
-
|
25
|
-
subject { docker_mid.call env }
|
26
|
-
|
27
|
-
before do
|
28
|
-
Evrone::CI::Worker.config.webdav_cache_url = 'http://192.168.44.1:8080/'
|
29
|
-
end
|
30
|
-
|
31
|
-
context "first run" do
|
32
|
-
it "should be" do
|
33
|
-
expect(subject).to eq 0
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "next run" do
|
38
|
-
before do
|
39
|
-
expect(docker_mid.call env).to eq 0
|
40
|
-
job.output.clear
|
41
|
-
end
|
42
|
-
it "should be" do
|
43
|
-
expect(subject).to eq 0
|
44
|
-
expect(job.output).to match(/\!exists/)
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pathname'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
describe Evrone::CI::Worker::LocalFetchRepo do
|
6
|
-
let(:exit_code) { 0 }
|
7
|
-
let(:app) { ->(_) { exit_code } }
|
8
|
-
let(:job) { create :job }
|
9
|
-
let(:path_prefix) { Pathname.new("/tmp/.ci") }
|
10
|
-
let(:repo_dir) { path_prefix.join("repo") }
|
11
|
-
let(:work_dir) { path_prefix.join("work") }
|
12
|
-
let(:env) { OpenStruct.new job: job, repo_dir: repo_dir, work_dir: work_dir }
|
13
|
-
let(:mid) { described_class.new app }
|
14
|
-
|
15
|
-
subject { mid.call env }
|
16
|
-
|
17
|
-
after do
|
18
|
-
FileUtils.rm_rf path_prefix
|
19
|
-
end
|
20
|
-
|
21
|
-
it { should eq 0 }
|
22
|
-
|
23
|
-
it "should create repo inside repo_dir" do
|
24
|
-
subject
|
25
|
-
expect(File.directory? "/tmp/.ci/repo/.git" ).to be
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should create copy of repo inside work_dir" do
|
29
|
-
subject
|
30
|
-
expect(File.readable? "/tmp/.ci/work/Gemfile").to be
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when fetch failed" do
|
34
|
-
before do
|
35
|
-
any_instance_of(Evrone::CI::SCM::Git) do |git|
|
36
|
-
mock(git).fetch { 1 }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it { should eq(-1) }
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when export failed" do
|
44
|
-
before do
|
45
|
-
any_instance_of(Evrone::CI::SCM::Git) do |git|
|
46
|
-
mock(git).fetch { 0 }
|
47
|
-
end
|
48
|
-
any_instance_of(described_class) do |m|
|
49
|
-
mock(m).export(anything, anything) { 1 }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it { should eq(-1) }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|