evrone-ci-worker 0.2.0.pre0
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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +24 -0
- data/bin/evrone-ci-worker +22 -0
- data/docker/Dockerfile +61 -0
- data/docker/sv-enable +26 -0
- data/docker/sv-gen +50 -0
- data/evrone-ci-worker.gemspec +32 -0
- data/lib/evrone/ci/worker/configuration.rb +58 -0
- data/lib/evrone/ci/worker/consumers/job_logs_consumer.rb +15 -0
- data/lib/evrone/ci/worker/consumers/job_status_consumer.rb +16 -0
- data/lib/evrone/ci/worker/consumers/jobs_consumer.rb +27 -0
- data/lib/evrone/ci/worker/docker.rb +35 -0
- data/lib/evrone/ci/worker/ext/string.rb +10 -0
- data/lib/evrone/ci/worker/helper/config.rb +14 -0
- data/lib/evrone/ci/worker/helper/logger.rb +14 -0
- data/lib/evrone/ci/worker/initializers/amqp.rb +53 -0
- data/lib/evrone/ci/worker/job.rb +42 -0
- data/lib/evrone/ci/worker/local.rb +37 -0
- data/lib/evrone/ci/worker/middlewares/docker_before_script.rb +38 -0
- data/lib/evrone/ci/worker/middlewares/docker_fetch_repo.rb +76 -0
- data/lib/evrone/ci/worker/middlewares/docker_script.rb +39 -0
- data/lib/evrone/ci/worker/middlewares/docker_start_container.rb +81 -0
- data/lib/evrone/ci/worker/middlewares/local_before_script.rb +29 -0
- data/lib/evrone/ci/worker/middlewares/local_create_dirs.rb +46 -0
- data/lib/evrone/ci/worker/middlewares/local_fetch_repo.rb +47 -0
- data/lib/evrone/ci/worker/middlewares/local_script.rb +29 -0
- data/lib/evrone/ci/worker/middlewares/log_job.rb +25 -0
- data/lib/evrone/ci/worker/middlewares/update_job_status.rb +64 -0
- data/lib/evrone/ci/worker/runner/docker.rb +0 -0
- data/lib/evrone/ci/worker/runner/local.rb +52 -0
- data/lib/evrone/ci/worker/version.rb +7 -0
- data/lib/evrone/ci/worker.rb +84 -0
- data/spec/lib/worker/configuration_spec.rb +40 -0
- data/spec/lib/worker/docker_spec.rb +29 -0
- data/spec/lib/worker/job_spec.rb +54 -0
- data/spec/lib/worker/local_spec.rb +29 -0
- data/spec/lib/worker/middlewares/docker_before_script_spec.rb +30 -0
- data/spec/lib/worker/middlewares/docker_fetch_repo_spec.rb +26 -0
- data/spec/lib/worker/middlewares/docker_script_spec.rb +30 -0
- data/spec/lib/worker/middlewares/docker_start_container_spec.rb +21 -0
- data/spec/lib/worker/middlewares/local_before_script_spec.rb +35 -0
- data/spec/lib/worker/middlewares/local_create_dirs_spec.rb +42 -0
- data/spec/lib/worker/middlewares/local_fetch_repo_spec.rb +56 -0
- data/spec/lib/worker/middlewares/local_script_spec.rb +35 -0
- data/spec/lib/worker/middlewares/log_job_spec.rb +15 -0
- data/spec/lib/worker/middlewares/update_job_status_spec.rb +70 -0
- data/spec/lib/worker_spec.rb +39 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/create.rb +33 -0
- data/spec/support/shared_examples/update_job_status_message_spec.rb +7 -0
- metadata +257 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7b9bb1d659ac857b4f5fdb4bf715a9695360997
|
4
|
+
data.tar.gz: 07a0fd1df69fa7374d2ff7b80bddfbd6a685983f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30ee6822495f8aebe134334a77477e98e64041b821a89cf4922e7fdee91cb53eae27c2e380ef515f4c1823722f40dd740f18992eaaec7c8345d5bbd41ccee9b3
|
7
|
+
data.tar.gz: bf174a1ebc89b1b1a3e268553cb1c9e185376cc78697086ae361d5573cf5c9f356c27eac5108226ea548e2a0aad57a75ab911fb9869ac0ebe87bf9e8c1a9c74f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dmitry Galinsky
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Evrone::Ci::Job
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'evrone-ci-job'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install evrone-ci-job
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.require
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require "bundler/gem_tasks"
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task :default => ["test:create_repo", :spec]
|
10
|
+
|
11
|
+
namespace :test do
|
12
|
+
task :create_repo do
|
13
|
+
dir = "fixtures/repo"
|
14
|
+
unless File.directory? dir
|
15
|
+
cmd = "git clone https://github.com/evrone/ci-worker-test-repo.git fixtures/repo"
|
16
|
+
puts cmd
|
17
|
+
system cmd
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
task :travis do
|
23
|
+
exec "bundle exec rake SPEC_OPTS='--format documentation -t ~run_docker --order=rand'"
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path("../../lib/evrone/ci/worker", __FILE__)
|
4
|
+
|
5
|
+
trap('INT') {
|
6
|
+
Thread.new do
|
7
|
+
Evrone::Common::AMQP.shutdown
|
8
|
+
end.join
|
9
|
+
}
|
10
|
+
|
11
|
+
Evrone::CI::Worker.configure do |c|
|
12
|
+
c.docker.ssh.port = 2223
|
13
|
+
c.docker.ssh.host = 'localhost'
|
14
|
+
c.docker.create_options = {
|
15
|
+
'PortSpecs' => ['2022:22']
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
Evrone::Common::AMQP::Supervisor::Threaded.build(
|
20
|
+
Evrone::CI::Worker::JobsConsumer => 4,
|
21
|
+
).run
|
22
|
+
|
data/docker/Dockerfile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
FROM ubuntu:12.04
|
2
|
+
|
3
|
+
# disable questions
|
4
|
+
ENV DEBIAN_FRONTEND noninteractive
|
5
|
+
|
6
|
+
# disable service autostarting
|
7
|
+
ENV RUNLEVEL 1
|
8
|
+
|
9
|
+
# replace init
|
10
|
+
RUN dpkg-divert --local --rename --add /sbin/initctl
|
11
|
+
RUN ln -s /bin/true /sbin/initctl
|
12
|
+
|
13
|
+
RUN apt-get -qy update
|
14
|
+
RUN apt-get install -qy curl git-core build-essential
|
15
|
+
|
16
|
+
# add evrone repo
|
17
|
+
RUN mkdir -p /etc/apt/sources.list.d
|
18
|
+
RUN echo "deb http://download.opensuse.org/repositories/home:/dmexe/xUbuntu_12.04/ ./" > /etc/apt/sources.list.d/Evrone.list
|
19
|
+
RUN curl http://download.opensuse.org/repositories/home:/dmexe/xUbuntu_12.04/Release.key | apt-key add -
|
20
|
+
RUN apt-get -qy update
|
21
|
+
|
22
|
+
# install runit
|
23
|
+
RUN chmod 0000 /sbin/start
|
24
|
+
RUN apt-get -qy install runit
|
25
|
+
RUN chmod 0755 /sbin/start
|
26
|
+
ADD ./sv-gen /usr/local/bin/sv-gen
|
27
|
+
ADD ./sv-enable /usr/local/bin/sv-enable
|
28
|
+
|
29
|
+
# set user password
|
30
|
+
RUN useradd -m ci
|
31
|
+
RUN echo "ci:ci" | chpasswd
|
32
|
+
RUN apt-get -qy install sudo
|
33
|
+
RUN echo "ci ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
34
|
+
|
35
|
+
# fixes locales
|
36
|
+
RUN locale-gen en_US.UTF-8
|
37
|
+
RUN dpkg-reconfigure -fnoninteractive locales
|
38
|
+
RUN update-locale LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8" LANGUAGE="en_US"
|
39
|
+
|
40
|
+
# install ssh
|
41
|
+
RUN apt-get install -qy openssh-server
|
42
|
+
RUN mkdir -p /var/run/sshd
|
43
|
+
RUN sv-gen ssh "/usr/sbin/sshd -D -e"
|
44
|
+
|
45
|
+
# install postgresql
|
46
|
+
RUN apt-get install -qy postgresql
|
47
|
+
RUN echo "host all all all trust" > /etc/postgresql/9.1/main/pg_hba.conf
|
48
|
+
RUN 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
|
49
|
+
|
50
|
+
# add ruby
|
51
|
+
RUN apt-get install -qy rbenv rbenv-2.0.0-p195 rbenv-1.9.3-p448
|
52
|
+
RUN env RBENV_VERSION=2.0.0-p195 rbenv exec gem install bundler --no-ri --no-rdoc
|
53
|
+
RUN env RBENV_VERSION=1.9.3-p448 rbenv exec gem install bundler --no-ri --no-rdoc
|
54
|
+
RUN rbenv rehash
|
55
|
+
|
56
|
+
RUN apt-get -qy clean autoremove
|
57
|
+
|
58
|
+
RUN sv-enable postgresql
|
59
|
+
RUN sv-enable ssh
|
60
|
+
|
61
|
+
ENTRYPOINT ["/usr/bin/runsvdir", "-P", "/etc/service"]
|
data/docker/sv-enable
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
NAME=${1}
|
6
|
+
USAGE="Usage: sv-enable <service>"
|
7
|
+
SRC=/etc/sv/${NAME}
|
8
|
+
DST=/etc/service/${NAME}
|
9
|
+
|
10
|
+
if [ "x${1}" = "x" ] ; then
|
11
|
+
echo $USAGE
|
12
|
+
exit 1
|
13
|
+
fi
|
14
|
+
|
15
|
+
if [ ! -d ${SRC} ] ; then
|
16
|
+
echo "Service ${NAME} does not exists"
|
17
|
+
exit 1
|
18
|
+
fi
|
19
|
+
|
20
|
+
mkdir -p /etc/service
|
21
|
+
|
22
|
+
if [ ! -L $DST ] ; then
|
23
|
+
echo " ---> enable ${NAME}"
|
24
|
+
rm -rf ${DST}
|
25
|
+
ln -s ${SRC} ${DST}
|
26
|
+
fi
|
data/docker/sv-gen
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
NAME=${1}
|
6
|
+
CMD=${2}
|
7
|
+
USER=${3:-root}
|
8
|
+
DIR=${4:-/}
|
9
|
+
RUN_FILE="/etc/sv/${NAME}/run"
|
10
|
+
LOG_FILE="/etc/sv/${NAME}/log/run"
|
11
|
+
|
12
|
+
USAGE="Usage: sv-gen <name> <command> [user] [directory]"
|
13
|
+
|
14
|
+
if [ "x${1}" = "x" ] ; then
|
15
|
+
echo $USAGE
|
16
|
+
exit 1
|
17
|
+
fi
|
18
|
+
|
19
|
+
if [ "x${2}" = "x" ] ; then
|
20
|
+
echo $USAGE
|
21
|
+
exit 1
|
22
|
+
fi
|
23
|
+
|
24
|
+
echo " ---> create /etc/sv/${NAME}"
|
25
|
+
mkdir -p /etc/sv/${NAME}
|
26
|
+
|
27
|
+
echo " ---> create ${RUN_FILE}"
|
28
|
+
cat > $RUN_FILE << EOF
|
29
|
+
#!/bin/sh
|
30
|
+
set -e
|
31
|
+
exec 2>&1
|
32
|
+
cd ${DIR}
|
33
|
+
CMD="${CMD}"
|
34
|
+
exec chpst -u ${USER} \$CMD 2>&1
|
35
|
+
EOF
|
36
|
+
chmod +x ${RUN_FILE}
|
37
|
+
|
38
|
+
echo " ---> create /etc/sv/${NAME}/log"
|
39
|
+
mkdir -p /etc/sv/${NAME}/log
|
40
|
+
|
41
|
+
echo " ---> create ${LOG_FILE}"
|
42
|
+
cat > $LOG_FILE << EOF
|
43
|
+
#!/bin/sh
|
44
|
+
set -e
|
45
|
+
LOG=/var/log/${NAME}
|
46
|
+
|
47
|
+
test -d "\$LOG" || mkdir -p m2750 "\$LOG"
|
48
|
+
exec svlogd "\$LOG"
|
49
|
+
EOF
|
50
|
+
chmod +x ${LOG_FILE}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require File.expand_path('../lib/evrone/ci/worker/version.rb', __FILE__)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "evrone-ci-worker"
|
8
|
+
spec.version = Evrone::CI::Worker::VERSION
|
9
|
+
spec.authors = ["Dmitry Galinsky"]
|
10
|
+
spec.email = ["dima.exe@gmail.com"]
|
11
|
+
spec.description = %q{ ci worker }
|
12
|
+
spec.summary = %q{ ci worker }
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
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-common-amqp', '~> 0.1.1'
|
24
|
+
spec.add_runtime_dependency 'docker-api', '= 1.5.4'
|
25
|
+
spec.add_runtime_dependency 'hashr', '= 0.0.22'
|
26
|
+
spec.add_runtime_dependency 'net-scp', '= 1.1.2'
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "rspec"
|
31
|
+
spec.add_development_dependency "rr"
|
32
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'hashr'
|
2
|
+
require 'logger'
|
3
|
+
require 'evrone/ci/common/tagged_logging'
|
4
|
+
|
5
|
+
module Evrone
|
6
|
+
module CI
|
7
|
+
module Worker
|
8
|
+
class Configuration < ::Hashr
|
9
|
+
|
10
|
+
extend Hashr::EnvDefaults
|
11
|
+
|
12
|
+
@@null_logger = Logger.new("/dev/null")
|
13
|
+
|
14
|
+
self.env_namespace = 'ci_worker'
|
15
|
+
self.raise_missing_keys = true
|
16
|
+
|
17
|
+
define amqp_url: nil,
|
18
|
+
run: "docker",
|
19
|
+
timeout: 30 * 60,
|
20
|
+
logger: Common::TaggedLogging.new(Logger.new STDOUT),
|
21
|
+
|
22
|
+
work_dir_name: "work",
|
23
|
+
repo_dir_name: "repo",
|
24
|
+
tmp_dir_name: "tmp",
|
25
|
+
|
26
|
+
sleep_after_job: 5,
|
27
|
+
|
28
|
+
docker: {
|
29
|
+
remote_dir: "/home/ci",
|
30
|
+
init: %w{ /usr/local/bin/runsvdir -P /etc/service },
|
31
|
+
image: "ci",
|
32
|
+
|
33
|
+
ssh: {
|
34
|
+
host: nil, # used in tests
|
35
|
+
port: nil, # used in tests
|
36
|
+
user: "ci",
|
37
|
+
password: "ci"
|
38
|
+
},
|
39
|
+
|
40
|
+
create_options: nil # used in tests
|
41
|
+
}
|
42
|
+
|
43
|
+
def timeout
|
44
|
+
self[:timeout].to_i
|
45
|
+
end
|
46
|
+
|
47
|
+
def run
|
48
|
+
self[:run].to_sym
|
49
|
+
end
|
50
|
+
|
51
|
+
def null_logger
|
52
|
+
@@null_logger
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'evrone/common/amqp'
|
2
|
+
|
3
|
+
module Evrone
|
4
|
+
module CI
|
5
|
+
module Worker
|
6
|
+
class JobsConsumer
|
7
|
+
|
8
|
+
include Evrone::Common::AMQP::Consumer
|
9
|
+
|
10
|
+
exchange 'ci.jobs'
|
11
|
+
queue 'ci.worker.jobs.generic'
|
12
|
+
ack true
|
13
|
+
|
14
|
+
model Message::PerformJob
|
15
|
+
|
16
|
+
def perform(message)
|
17
|
+
job = Job.new message
|
18
|
+
number = Thread.current[:consumer_id] || 0
|
19
|
+
path_prefix = "/tmp/.test/job.#{number}"
|
20
|
+
Worker.perform(job, path_prefix)
|
21
|
+
ack!
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'evrone/ci/common'
|
2
|
+
|
3
|
+
module Evrone
|
4
|
+
module CI
|
5
|
+
module Worker
|
6
|
+
|
7
|
+
class Docker
|
8
|
+
|
9
|
+
include Common::Helper::Middlewares
|
10
|
+
|
11
|
+
attr_reader :job
|
12
|
+
|
13
|
+
middlewares do
|
14
|
+
use LogJob
|
15
|
+
use UpdateJobStatus
|
16
|
+
use DockerStartContainer
|
17
|
+
use DockerFetchRepo
|
18
|
+
use DockerBeforeScript
|
19
|
+
use DockerScript
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(job, _)
|
23
|
+
@job = job
|
24
|
+
end
|
25
|
+
|
26
|
+
def perform
|
27
|
+
env = OpenStruct.new job: job
|
28
|
+
run_middlewares(env){ |_| 0 }
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'evrone/common/amqp'
|
2
|
+
|
3
|
+
module Evrone::CI::Worker::AMQP
|
4
|
+
|
5
|
+
Base = Struct.new("Subscribing", :app) do
|
6
|
+
include Evrone::CI::Worker::Helper::Logger
|
7
|
+
|
8
|
+
def consumer_name
|
9
|
+
Thread.current[:consumer_name]
|
10
|
+
end
|
11
|
+
|
12
|
+
def consumer_id
|
13
|
+
Thread.current[:consumer_id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def consumer_tag
|
17
|
+
consumer_id ? "#{consumer_name.split('::').last} #{consumer_id}" : consumer_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Subscribing < Base
|
22
|
+
def call(env)
|
23
|
+
logger.tagged(consumer_tag) do
|
24
|
+
logger.warn "subsribing #{env[:exchange].name}"
|
25
|
+
rs = app.call env
|
26
|
+
logger.warn "shutdown"
|
27
|
+
rs
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Recieving < Base
|
33
|
+
def call(env)
|
34
|
+
logger.warn "payload recieved #{env[:payload].inspect[0...60]}..."
|
35
|
+
rs = app.call env
|
36
|
+
logger.warn "commit message"
|
37
|
+
rs
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Evrone::Common::AMQP.configure do |c|
|
43
|
+
c.subscribing do
|
44
|
+
use Evrone::CI::Worker::AMQP::Subscribing
|
45
|
+
end
|
46
|
+
|
47
|
+
c.recieving do
|
48
|
+
use Evrone::CI::Worker::AMQP::Recieving
|
49
|
+
end
|
50
|
+
|
51
|
+
c.content_type = 'application/x-protobuf'
|
52
|
+
c.logger = nil
|
53
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'evrone/ci/message'
|
2
|
+
require 'evrone/ci/common'
|
3
|
+
|
4
|
+
module Evrone
|
5
|
+
module CI
|
6
|
+
module Worker
|
7
|
+
class Job
|
8
|
+
|
9
|
+
include Helper::Logger
|
10
|
+
|
11
|
+
attr_reader :output, :message
|
12
|
+
|
13
|
+
def initialize(perform_job_message)
|
14
|
+
@output = ""
|
15
|
+
@message = perform_job_message
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_to_output(str)
|
19
|
+
output << str
|
20
|
+
logger.debug str.strip if logger.level == 0
|
21
|
+
JobLogsConsumer.publish create_job_log_message(str)
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_command_to_output(cmd)
|
25
|
+
add_to_output "$ #{cmd}\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_job_log_message(data)
|
29
|
+
tm = Time.now
|
30
|
+
Message::JobLog.new(
|
31
|
+
build_id: message.id,
|
32
|
+
job_id: message.job_id,
|
33
|
+
tm: tm.to_i,
|
34
|
+
tm_usec: tm.usec,
|
35
|
+
log: data
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'evrone/ci/common'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Evrone
|
5
|
+
module CI
|
6
|
+
module Worker
|
7
|
+
|
8
|
+
class Local
|
9
|
+
|
10
|
+
include Common::Helper::Middlewares
|
11
|
+
|
12
|
+
attr_reader :job, :path_prefix
|
13
|
+
|
14
|
+
middlewares do
|
15
|
+
use LogJob
|
16
|
+
use UpdateJobStatus
|
17
|
+
use LocalCreateDirs
|
18
|
+
use LocalFetchRepo
|
19
|
+
use LocalBeforeScript
|
20
|
+
use LocalScript
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(job, path_prefix)
|
24
|
+
@job = job
|
25
|
+
@path_prefix = Pathname.new(path_prefix).expand_path
|
26
|
+
end
|
27
|
+
|
28
|
+
def perform
|
29
|
+
env = OpenStruct.new job: job, path_prefix: path_prefix
|
30
|
+
run_middlewares(env){ |_| 0 }
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
|