vx-worker 0.2.0.pre28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +7 -0
  5. data/LICENSE.txt +276 -0
  6. data/Rakefile +27 -0
  7. data/bin/vx-worker +6 -0
  8. data/docker/Dockerfile +15 -0
  9. data/docker/bootstrap.sh +106 -0
  10. data/docker/sv-enable +26 -0
  11. data/docker/sv-gen +50 -0
  12. data/lib/vx/worker/cli.rb +55 -0
  13. data/lib/vx/worker/configuration.rb +62 -0
  14. data/lib/vx/worker/consumers/job_logs_consumer.rb +13 -0
  15. data/lib/vx/worker/consumers/job_status_consumer.rb +13 -0
  16. data/lib/vx/worker/consumers/jobs_consumer.rb +28 -0
  17. data/lib/vx/worker/docker.rb +32 -0
  18. data/lib/vx/worker/ext/string.rb +10 -0
  19. data/lib/vx/worker/helper/config.rb +11 -0
  20. data/lib/vx/worker/helper/logger.rb +11 -0
  21. data/lib/vx/worker/initializers/amqp.rb +3 -0
  22. data/lib/vx/worker/job.rb +49 -0
  23. data/lib/vx/worker/local.rb +32 -0
  24. data/lib/vx/worker/middlewares/log_job.rb +19 -0
  25. data/lib/vx/worker/middlewares/run_script.rb +84 -0
  26. data/lib/vx/worker/middlewares/start_connector.rb +32 -0
  27. data/lib/vx/worker/middlewares/timeout.rb +22 -0
  28. data/lib/vx/worker/middlewares/update_job_status.rb +69 -0
  29. data/lib/vx/worker/version.rb +5 -0
  30. data/lib/vx/worker.rb +83 -0
  31. data/spec/lib/worker/configuration_spec.rb +40 -0
  32. data/spec/lib/worker/docker_spec.rb +28 -0
  33. data/spec/lib/worker/job_spec.rb +104 -0
  34. data/spec/lib/worker/local_spec.rb +29 -0
  35. data/spec/lib/worker/middlewares/log_job_spec.rb +15 -0
  36. data/spec/lib/worker/middlewares/run_script_spec.rb +63 -0
  37. data/spec/lib/worker/middlewares/start_connector_spec.rb +34 -0
  38. data/spec/lib/worker/middlewares/timeout_spec.rb +28 -0
  39. data/spec/lib/worker/middlewares/update_job_status_spec.rb +75 -0
  40. data/spec/lib/worker_spec.rb +39 -0
  41. data/spec/spec_helper.rb +27 -0
  42. data/spec/support/all_job_log_output.rb +3 -0
  43. data/spec/support/create.rb +19 -0
  44. data/spec/support/last_job_logs_message.rb +3 -0
  45. data/spec/support/shared_examples/update_job_status_message_spec.rb +6 -0
  46. data/vx-worker.gemspec +31 -0
  47. metadata +231 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e5ee04a730defffa2d31c9bc8c88712d9bf1cd3e
4
+ data.tar.gz: f654402fc597e89de03bc136fb3a73ad899c86ce
5
+ SHA512:
6
+ metadata.gz: 1dafcf6ddfe6efaee6ac3b6e282383846c7b699bcbd626f99f2125012161b51336313a7478b78f7ba2149ffe727876c47fe55c38259dcf2c36ea31f176310b75
7
+ data.tar.gz: 981214665be8424aba5f11bfd182ca40ea62ccb3daae29f837dae6cf00298b4d68f2e08117e06eaa6e51c1079263c6e9fff186fc54441226c23397a16a4bd416
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ fixtures/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ -f d
2
+ --color
3
+ --order=rand
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vx-worker.gemspec
4
+ gemspec
5
+ gem 'vx-common', path: File.expand_path("../../common", __FILE__)
6
+ gem 'vx-message', path: File.expand_path("../../message", __FILE__)
7
+ gem 'vx-container_connector', path: File.expand_path("../../container_connector", __FILE__)
data/LICENSE.txt ADDED
@@ -0,0 +1,276 @@
1
+ Copyright (c) 2013 Dmitry Galinsky
2
+
3
+ The GNU General Public License, Version 2, June 1991 (GPLv2)
4
+ ============================================================
5
+
6
+ > Copyright (C) 1989, 1991 Free Software Foundation, Inc.
7
+ > 59 Temple Place, Suite 330
8
+ > Boston, MA 02111-1307 USA
9
+
10
+ Everyone is permitted to copy and distribute verbatim copies of this license
11
+ document, but changing it is not allowed.
12
+
13
+
14
+ Preamble
15
+ --------
16
+
17
+ The licenses for most software are designed to take away your freedom to share
18
+ and change it. By contrast, the GNU General Public License is intended to
19
+ guarantee your freedom to share and change free software--to make sure the
20
+ software is free for all its users. This General Public License applies to most
21
+ of the Free Software Foundation's software and to any other program whose
22
+ authors commit to using it. (Some other Free Software Foundation software is
23
+ covered by the GNU Library General Public License instead.) You can apply it to
24
+ your programs, too.
25
+
26
+ When we speak of free software, we are referring to freedom, not price. Our
27
+ General Public Licenses are designed to make sure that you have the freedom to
28
+ distribute copies of free software (and charge for this service if you wish),
29
+ that you receive source code or can get it if you want it, that you can change
30
+ the software or use pieces of it in new free programs; and that you know you can
31
+ do these things.
32
+
33
+ To protect your rights, we need to make restrictions that forbid anyone to deny
34
+ you these rights or to ask you to surrender the rights. These restrictions
35
+ translate to certain responsibilities for you if you distribute copies of the
36
+ software, or if you modify it.
37
+
38
+ For example, if you distribute copies of such a program, whether gratis or for a
39
+ fee, you must give the recipients all the rights that you have. You must make
40
+ sure that they, too, receive or can get the source code. And you must show them
41
+ these terms so they know their rights.
42
+
43
+ We protect your rights with two steps: (1) copyright the software, and (2) offer
44
+ you this license which gives you legal permission to copy, distribute and/or
45
+ modify the software.
46
+
47
+ Also, for each author's protection and ours, we want to make certain that
48
+ everyone understands that there is no warranty for this free software. If the
49
+ software is modified by someone else and passed on, we want its recipients to
50
+ know that what they have is not the original, so that any problems introduced by
51
+ others will not reflect on the original authors' reputations.
52
+
53
+ Finally, any free program is threatened constantly by software patents. We wish
54
+ to avoid the danger that redistributors of a free program will individually
55
+ obtain patent licenses, in effect making the program proprietary. To prevent
56
+ this, we have made it clear that any patent must be licensed for everyone's free
57
+ use or not licensed at all.
58
+
59
+ The precise terms and conditions for copying, distribution and modification
60
+ follow.
61
+
62
+
63
+ Terms And Conditions For Copying, Distribution And Modification
64
+ ---------------------------------------------------------------
65
+ 0. This License applies to any program or other work which contains a notice
66
+ placed by the copyright holder saying it may be distributed under the terms
67
+ of this General Public License. The "Program", below, refers to any such
68
+ program or work, and a "work based on the Program" means either the Program
69
+ or any derivative work under copyright law: that is to say, a work
70
+ containing the Program or a portion of it, either verbatim or with
71
+ modifications and/or translated into another language. (Hereinafter,
72
+ translation is included without limitation in the term "modification".)
73
+ Each licensee is addressed as "you".
74
+
75
+ Activities other than copying, distribution and modification are not
76
+ covered by this License; they are outside its scope. The act of running the
77
+ Program is not restricted, and the output from the Program is covered only
78
+ if its contents constitute a work based on the Program (independent of
79
+ having been made by running the Program). Whether that is true depends on
80
+ what the Program does.
81
+
82
+ 1. You may copy and distribute verbatim copies of the Program's source code as
83
+ you receive it, in any medium, provided that you conspicuously and
84
+ appropriately publish on each copy an appropriate copyright notice and
85
+ disclaimer of warranty; keep intact all the notices that refer to this
86
+ License and to the absence of any warranty; and give any other recipients
87
+ of the Program a copy of this License along with the Program.
88
+
89
+ You may charge a fee for the physical act of transferring a copy, and you
90
+ may at your option offer warranty protection in exchange for a fee.
91
+
92
+ 2. You may modify your copy or copies of the Program or any portion of it,
93
+ thus forming a work based on the Program, and copy and distribute such
94
+ modifications or work under the terms of Section 1 above, provided that you
95
+ also meet all of these conditions:
96
+
97
+ a) You must cause the modified files to carry prominent notices stating
98
+ that you changed the files and the date of any change.
99
+
100
+ b) You must cause any work that you distribute or publish, that in whole
101
+ or in part contains or is derived from the Program or any part thereof,
102
+ to be licensed as a whole at no charge to all third parties under the
103
+ terms of this License.
104
+
105
+ c) If the modified program normally reads commands interactively when run,
106
+ you must cause it, when started running for such interactive use in the
107
+ most ordinary way, to print or display an announcement including an
108
+ appropriate copyright notice and a notice that there is no warranty (or
109
+ else, saying that you provide a warranty) and that users may
110
+ redistribute the program under these conditions, and telling the user
111
+ how to view a copy of this License. (Exception: if the Program itself
112
+ is interactive but does not normally print such an announcement, your
113
+ work based on the Program is not required to print an announcement.)
114
+
115
+ These requirements apply to the modified work as a whole. If identifiable
116
+ sections of that work are not derived from the Program, and can be
117
+ reasonably considered independent and separate works in themselves, then
118
+ this License, and its terms, do not apply to those sections when you
119
+ distribute them as separate works. But when you distribute the same
120
+ sections as part of a whole which is a work based on the Program, the
121
+ distribution of the whole must be on the terms of this License, whose
122
+ permissions for other licensees extend to the entire whole, and thus to
123
+ each and every part regardless of who wrote it.
124
+
125
+ Thus, it is not the intent of this section to claim rights or contest your
126
+ rights to work written entirely by you; rather, the intent is to exercise
127
+ the right to control the distribution of derivative or collective works
128
+ based on the Program.
129
+
130
+ In addition, mere aggregation of another work not based on the Program with
131
+ the Program (or with a work based on the Program) on a volume of a storage
132
+ or distribution medium does not bring the other work under the scope of
133
+ this License.
134
+
135
+ 3. You may copy and distribute the Program (or a work based on it, under
136
+ Section 2) in object code or executable form under the terms of Sections 1
137
+ and 2 above provided that you also do one of the following:
138
+
139
+ a) Accompany it with the complete corresponding machine-readable source
140
+ code, which must be distributed under the terms of Sections 1 and 2
141
+ above on a medium customarily used for software interchange; or,
142
+
143
+ b) Accompany it with a written offer, valid for at least three years, to
144
+ give any third party, for a charge no more than your cost of physically
145
+ performing source distribution, a complete machine-readable copy of the
146
+ corresponding source code, to be distributed under the terms of
147
+ Sections 1 and 2 above on a medium customarily used for software
148
+ interchange; or,
149
+
150
+ c) Accompany it with the information you received as to the offer to
151
+ distribute corresponding source code. (This alternative is allowed only
152
+ for noncommercial distribution and only if you received the program in
153
+ object code or executable form with such an offer, in accord with
154
+ Subsection b above.)
155
+
156
+ The source code for a work means the preferred form of the work for making
157
+ modifications to it. For an executable work, complete source code means all
158
+ the source code for all modules it contains, plus any associated interface
159
+ definition files, plus the scripts used to control compilation and
160
+ installation of the executable. However, as a special exception, the source
161
+ code distributed need not include anything that is normally distributed (in
162
+ either source or binary form) with the major components (compiler, kernel,
163
+ and so on) of the operating system on which the executable runs, unless
164
+ that component itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering access to
167
+ copy from a designated place, then offering equivalent access to copy the
168
+ source code from the same place counts as distribution of the source code,
169
+ even though third parties are not compelled to copy the source along with
170
+ the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program except as
173
+ expressly provided under this License. Any attempt otherwise to copy,
174
+ modify, sublicense or distribute the Program is void, and will
175
+ automatically terminate your rights under this License. However, parties
176
+ who have received copies, or rights, from you under this License will not
177
+ have their licenses terminated so long as such parties remain in full
178
+ compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not signed it.
181
+ However, nothing else grants you permission to modify or distribute the
182
+ Program or its derivative works. These actions are prohibited by law if you
183
+ do not accept this License. Therefore, by modifying or distributing the
184
+ Program (or any work based on the Program), you indicate your acceptance of
185
+ this License to do so, and all its terms and conditions for copying,
186
+ distributing or modifying the Program or works based on it.
187
+
188
+ 6. Each time you redistribute the Program (or any work based on the Program),
189
+ the recipient automatically receives a license from the original licensor
190
+ to copy, distribute or modify the Program subject to these terms and
191
+ conditions. You may not impose any further restrictions on the recipients'
192
+ exercise of the rights granted herein. You are not responsible for
193
+ enforcing compliance by third parties to this License.
194
+
195
+ 7. If, as a consequence of a court judgment or allegation of patent
196
+ infringement or for any other reason (not limited to patent issues),
197
+ conditions are imposed on you (whether by court order, agreement or
198
+ otherwise) that contradict the conditions of this License, they do not
199
+ excuse you from the conditions of this License. If you cannot distribute so
200
+ as to satisfy simultaneously your obligations under this License and any
201
+ other pertinent obligations, then as a consequence you may not distribute
202
+ the Program at all. For example, if a patent license would not permit
203
+ royalty-free redistribution of the Program by all those who receive copies
204
+ directly or indirectly through you, then the only way you could satisfy
205
+ both it and this License would be to refrain entirely from distribution of
206
+ the Program.
207
+
208
+ If any portion of this section is held invalid or unenforceable under any
209
+ particular circumstance, the balance of the section is intended to apply
210
+ and the section as a whole is intended to apply in other circumstances.
211
+
212
+ It is not the purpose of this section to induce you to infringe any patents
213
+ or other property right claims or to contest validity of any such claims;
214
+ this section has the sole purpose of protecting the integrity of the free
215
+ software distribution system, which is implemented by public license
216
+ practices. Many people have made generous contributions to the wide range
217
+ of software distributed through that system in reliance on consistent
218
+ application of that system; it is up to the author/donor to decide if he or
219
+ she is willing to distribute software through any other system and a
220
+ licensee cannot impose that choice.
221
+
222
+ This section is intended to make thoroughly clear what is believed to be a
223
+ consequence of the rest of this License.
224
+
225
+ 8. If the distribution and/or use of the Program is restricted in certain
226
+ countries either by patents or by copyrighted interfaces, the original
227
+ copyright holder who places the Program under this License may add an
228
+ explicit geographical distribution limitation excluding those countries, so
229
+ that distribution is permitted only in or among countries not thus excluded.
230
+ In such case, this License incorporates the limitation as if written in
231
+ the body of this License.
232
+
233
+ 9. The Free Software Foundation may publish revised and/or new versions of the
234
+ General Public License from time to time. Such new versions will be similar
235
+ in spirit to the present version, but may differ in detail to address new
236
+ problems or concerns.
237
+
238
+ Each version is given a distinguishing version number. If the Program
239
+ specifies a version number of this License which applies to it and "any
240
+ later version", you have the option of following the terms and conditions
241
+ either of that version or of any later version published by the Free
242
+ Software Foundation. If the Program does not specify a version number of
243
+ this License, you may choose any version ever published by the Free
244
+ Software Foundation.
245
+
246
+ 10. If you wish to incorporate parts of the Program into other free programs
247
+ whose distribution conditions are different, write to the author to ask for
248
+ permission. For software which is copyrighted by the Free Software
249
+ Foundation, write to the Free Software Foundation; we sometimes make
250
+ exceptions for this. Our decision will be guided by the two goals of
251
+ preserving the free status of all derivatives of our free software and of
252
+ promoting the sharing and reuse of software generally.
253
+
254
+
255
+ No Warranty
256
+ -----------
257
+
258
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
259
+ THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
260
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
261
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
262
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
263
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO
264
+ THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM
265
+ PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
266
+ CORRECTION.
267
+
268
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
269
+ ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
270
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
271
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
272
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
273
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
274
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
275
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
276
+ SUCH DAMAGES.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
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
+ desc "download test repo and run spec"
10
+ task :default => ["test:create_repo", :spec]
11
+
12
+ namespace :test do
13
+ desc "download test repo"
14
+ task :create_repo do
15
+ dir = "fixtures/repo"
16
+ unless File.directory? dir
17
+ cmd = "git clone https://github.com/evrone/ci-worker-test-repo.git fixtures/repo"
18
+ puts cmd
19
+ system cmd
20
+ end
21
+ end
22
+ end
23
+
24
+ desc "run travis build"
25
+ task :travis do
26
+ exec "bundle exec rake SPEC_OPTS='--format documentation -t ~docker --order=rand'"
27
+ end
data/bin/vx-worker ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path("../../lib/vx/worker", __FILE__)
4
+
5
+ cli = Vx::Worker::CLI.new
6
+ cli.run
data/docker/Dockerfile ADDED
@@ -0,0 +1,15 @@
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
+ # add runit helpers
10
+ ADD ./sv-gen /usr/local/bin/sv-gen
11
+ ADD ./sv-enable /usr/local/bin/sv-enable
12
+
13
+ # run bootstrap
14
+ ADD ./bootstrap.sh /tmp/bootstrap.sh
15
+ RUN /tmp/bootstrap.sh && rm /tmp/bootstrap.sh
@@ -0,0 +1,106 @@
1
+ #!/bin/bash
2
+ set -x
3
+ set -e
4
+
5
+ # add ubuntu repos
6
+ echo "deb http://us.archive.ubuntu.com/ubuntu/ precise universe" >> /etc/apt/sources.list
7
+ echo "deb http://us.archive.ubuntu.com/ubuntu/ precise multiverse" >> /etc/apt/sources.list
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
+
17
+ # replace init
18
+ dpkg-divert --local --rename --add /sbin/initctl
19
+ ln -s /bin/true /sbin/initctl
20
+
21
+ apt-get -qy update
22
+ apt-get install -qy curl git-core build-essential vim-tiny
23
+
24
+ # add evrone repo
25
+ mkdir -p /etc/apt/sources.list.d
26
+ echo "deb http://download.opensuse.org/repositories/home:/dmexe/xUbuntu_12.04/ ./" > /etc/apt/sources.list.d/Evrone.list
27
+ curl http://download.opensuse.org/repositories/home:/dmexe/xUbuntu_12.04/Release.key | apt-key add -
28
+ apt-get -qy update
29
+
30
+ # add packages
31
+ apt-get install -qy libmysqlclient-dev libpq-dev imagemagick libmagickwand-dev \
32
+ libcurl4-openssl-dev nodejs libxml2-dev libxslt-dev \
33
+ openjdk-7-jre-headless libsqlite3-dev libgeos-dev ruby
34
+
35
+ # install runit
36
+ chmod 0000 /sbin/start
37
+ apt-get -qy install runit
38
+ chmod 0755 /sbin/start
39
+
40
+ # set user password
41
+ useradd -m ci
42
+ echo "ci:ci" | chpasswd
43
+ apt-get -qy install sudo
44
+ echo "ci ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
45
+
46
+ # install ssh
47
+ apt-get install -qy openssh-server
48
+ mkdir -p /var/run/sshd
49
+ sv-gen ssh "/usr/sbin/sshd -D -e"
50
+
51
+ # install syslog
52
+ apt-get install -qy rsyslog
53
+ sv-gen rsyslogd "/usr/sbin/rsyslogd -c5 -n" root
54
+
55
+ # install postgresql
56
+ apt-get install -qy postgresql-9.1 postgresql-contrib-9.1
57
+ echo "local all all trust" > /etc/postgresql/9.1/main/pg_hba.conf
58
+ echo "host all all all trust" >> /etc/postgresql/9.1/main/pg_hba.conf
59
+ 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
60
+
61
+ # install mysql
62
+ apt-get install -qy mysql-server-5.5
63
+ sv-gen mysql "/usr/sbin/mysqld" mysql
64
+
65
+ # install redis-server
66
+ apt-get install -qy redis-server
67
+ sed -i 's|daemonize yes|daemonize no|g' /etc/redis/redis.conf
68
+ sv-gen redis-server "/usr/bin/redis-server /etc/redis/redis.conf" redis
69
+
70
+ # install rabbitmq-server
71
+ apt-get install -qy rabbitmq-server
72
+ sv-gen rabbitmq-server "/usr/sbin/rabbitmq-server" root
73
+
74
+ # install elasticsearch
75
+ ES_PKG=elasticsearch-0.90.5.deb
76
+ curl https://download.elasticsearch.org/elasticsearch/elasticsearch/$ES_PKG -o /tmp/$ES_PKG
77
+ dpkg -i /tmp/$ES_PKG
78
+ rm -f /tmp/$ES_PKG
79
+ sv-gen elasticsearch "/usr/share/elasticsearch/bin/elasticsearch -f -Des.path.data=/var/lib/elasticsearch" elasticsearch
80
+
81
+ # install phantomjs
82
+ PH_PKG=phantomjs-1.9.2-linux-x86_64.tar.bz2
83
+ curl https://phantomjs.googlecode.com/files/$PH_PKG -o /tmp/$PH_PKG
84
+ tar -jxf /tmp/$PH_PKG -C /usr/local
85
+ rm -f /tmp/$PH_PKG
86
+ ln -sf /usr/local/$(basename $PH_PKG .tar.bz2)/bin/phantomjs /usr/local/bin
87
+
88
+ # add ruby
89
+ apt-get install -qy rbenv rbenv-2.0.0-p195 rbenv-1.9.3-p448 rbenv-2.0.0-p247 rbenv-1.9.3-p392
90
+ apt-get install -qy ruby1.8 ruby1.8-dev rubygems # 1.8.7
91
+ env RBENV_VERSION=2.0.0-p247 rbenv exec gem install bundler --no-ri --no-rdoc
92
+ env RBENV_VERSION=2.0.0-p195 rbenv exec gem install bundler --no-ri --no-rdoc
93
+ env RBENV_VERSION=1.9.3-p448 rbenv exec gem install bundler --no-ri --no-rdoc
94
+ env RBENV_VERSION=1.9.3-p392 rbenv exec gem install bundler --no-ri --no-rdoc
95
+ env RBENV_VERSION=system rbenv exec gem install bundler --no-ri --no-rdoc
96
+ rbenv rehash
97
+ for i in `rbenv versions | grep -v '*'` ; do RBENV_VERSION=$i rbenv exec gem update --system ; done
98
+ echo 'gem: --no-ri --no-rdoc' > /etc/gemrc
99
+
100
+ apt-get -qy clean autoremove
101
+
102
+ sv-enable postgresql
103
+ sv-enable ssh
104
+ sv-enable mysql
105
+ sv-enable redis-server
106
+ sv-enable rsyslogd
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 sudo -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,55 @@
1
+ require 'optparse'
2
+ require 'vx/common/amqp_setup'
3
+ require 'vx/common'
4
+
5
+ module Vx
6
+ module Worker
7
+ class CLI
8
+
9
+ include Helper::Config
10
+ include Helper::Logger
11
+ include Common::EnvFile
12
+
13
+ def initialize
14
+ @options = {}
15
+ parse!
16
+ Worker.initialize!
17
+ end
18
+
19
+ def run
20
+ trap('INT') {
21
+ Thread.new do
22
+ Vx::Common::AMQP.shutdown
23
+ end.join
24
+ }
25
+
26
+ Vx::Common::AMQP::Supervisor::Threaded.build(
27
+ Vx::Worker::JobsConsumer => config.workers,
28
+ ).run
29
+ end
30
+
31
+ private
32
+
33
+ def parse!
34
+ OptionParser.new do |opts|
35
+ opts.banner = "Usage: vx-worker [options]"
36
+ opts.on("-w", "--workers NUM", "Number of workers, default 1") do |v|
37
+ @options[:workers] = v.to_i
38
+ end
39
+ opts.on("-p", "--path PATH", "Working directory, default current directory") do |v|
40
+ @options[:path_prefix] = v.to_s
41
+ end
42
+ opts.on("-c", "--config FILE", "Path to configuration file, default /etc/vexor/ci") do |v|
43
+ @options[:config] = v
44
+ end
45
+ end.parse!
46
+
47
+ read_env_file @options.delete(:config)
48
+
49
+ @options.each_pair do |k,v|
50
+ config.public_send("#{k}=", v)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,62 @@
1
+ require 'hashr'
2
+ require 'logger'
3
+ require 'vx/common/tagged_logging'
4
+
5
+ module Vx
6
+ module Worker
7
+ class Configuration < ::Hashr
8
+
9
+ extend Hashr::EnvDefaults
10
+
11
+ @@null_logger = Logger.new("/dev/null")
12
+
13
+ self.env_namespace = 'ci_worker'
14
+ self.raise_missing_keys = true
15
+
16
+ define amqp_url: nil,
17
+ run: "docker",
18
+ timeout: 30 * 60,
19
+ logger: Common::TaggedLogging.new(Logger.new STDOUT),
20
+
21
+ workers: 1,
22
+ path_prefix: nil,
23
+
24
+ docker: {
25
+ user: "ci",
26
+ password: "ci",
27
+ init: %w{ /usr/bin/runsvdir -P /etc/service },
28
+ image: "dmexe/ci",
29
+ remote_dir: "/home/ci",
30
+ },
31
+
32
+ local: {
33
+ remote_dir: "/tmp/.local_connector"
34
+ }
35
+
36
+ def timeout
37
+ self[:timeout].to_i
38
+ end
39
+
40
+ def run
41
+ self[:run].to_sym
42
+ end
43
+
44
+ def path_prefix
45
+ self[:path_prefix] || Dir.pwd
46
+ end
47
+
48
+ def null_logger
49
+ @@null_logger
50
+ end
51
+
52
+ def connector_options
53
+ self[self.run]
54
+ end
55
+
56
+ def connector_remote_dir
57
+ connector_options[:remote_dir]
58
+ end
59
+
60
+ end
61
+ end
62
+ end