janky 0.9.0
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.
- data/CHANGES +3 -0
- data/COPYING +22 -0
- data/Gemfile +2 -0
- data/README.md +211 -0
- data/Rakefile +19 -0
- data/config.ru +3 -0
- data/janky.gemspec +102 -0
- data/lib/janky.rb +224 -0
- data/lib/janky/app.rb +81 -0
- data/lib/janky/branch.rb +112 -0
- data/lib/janky/build.rb +223 -0
- data/lib/janky/build_request.rb +49 -0
- data/lib/janky/builder.rb +108 -0
- data/lib/janky/builder/client.rb +82 -0
- data/lib/janky/builder/http.rb +43 -0
- data/lib/janky/builder/mock.rb +45 -0
- data/lib/janky/builder/payload.rb +63 -0
- data/lib/janky/builder/receiver.rb +20 -0
- data/lib/janky/builder/runner.rb +47 -0
- data/lib/janky/campfire.rb +127 -0
- data/lib/janky/campfire/mock.rb +0 -0
- data/lib/janky/commit.rb +14 -0
- data/lib/janky/database/migrate/1312115512_init.rb +48 -0
- data/lib/janky/database/migrate/1312117285_non_unique_repo_uri.rb +10 -0
- data/lib/janky/database/migrate/1312198807_repo_enabled.rb +11 -0
- data/lib/janky/database/migrate/1313867551_add_build_output_column.rb +9 -0
- data/lib/janky/database/migrate/1313871652_add_commit_url_column.rb +9 -0
- data/lib/janky/database/migrate/1317384618_add_repo_hook_url.rb +9 -0
- data/lib/janky/database/migrate/1317384619_add_build_room_id.rb +9 -0
- data/lib/janky/database/migrate/1317384629_drop_default_room_id.rb +9 -0
- data/lib/janky/database/migrate/1317384649_github_team_id.rb +9 -0
- data/lib/janky/database/schema.rb +68 -0
- data/lib/janky/database/seed.dump.gz +0 -0
- data/lib/janky/exception.rb +62 -0
- data/lib/janky/github.rb +67 -0
- data/lib/janky/github/api.rb +69 -0
- data/lib/janky/github/commit.rb +27 -0
- data/lib/janky/github/mock.rb +47 -0
- data/lib/janky/github/payload.rb +34 -0
- data/lib/janky/github/payload_parser.rb +57 -0
- data/lib/janky/github/receiver.rb +69 -0
- data/lib/janky/helpers.rb +17 -0
- data/lib/janky/hubot.rb +117 -0
- data/lib/janky/job_creator.rb +111 -0
- data/lib/janky/notifier.rb +84 -0
- data/lib/janky/notifier/campfire.rb +21 -0
- data/lib/janky/notifier/mock.rb +55 -0
- data/lib/janky/notifier/multi.rb +22 -0
- data/lib/janky/public/css/base.css +204 -0
- data/lib/janky/public/images/building-bot.gif +0 -0
- data/lib/janky/public/images/disclosure-arrow.png +0 -0
- data/lib/janky/public/images/logo.png +0 -0
- data/lib/janky/public/images/robawt-status.gif +0 -0
- data/lib/janky/public/javascripts/application.js +3 -0
- data/lib/janky/public/javascripts/jquery.js +16 -0
- data/lib/janky/public/javascripts/jquery.relatize.js +111 -0
- data/lib/janky/repository.rb +174 -0
- data/lib/janky/tasks.rb +36 -0
- data/lib/janky/templates/console.mustache +4 -0
- data/lib/janky/templates/index.mustache +11 -0
- data/lib/janky/templates/layout.mustache +22 -0
- data/lib/janky/version.rb +3 -0
- data/lib/janky/views/console.rb +33 -0
- data/lib/janky/views/index.rb +35 -0
- data/lib/janky/views/layout.rb +19 -0
- data/test/default.xml.erb +0 -0
- data/test/janky_test.rb +271 -0
- data/test/test_helper.rb +107 -0
- metadata +319 -0
data/CHANGES
ADDED
data/COPYING
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011 GitHub, Inc. <https://github.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
Janky
|
2
|
+
=====
|
3
|
+
|
4
|
+
This is Janky, a continuous integration server built on top of
|
5
|
+
[Jenkins][], controlled by [Hubot][], and designed for [GitHub][].
|
6
|
+
|
7
|
+
* **Built on top of Jenkins.** The power, vast amount of plugins and large
|
8
|
+
communauty of the popular CI server all wrapped up in a great experience.
|
9
|
+
|
10
|
+
* **Controlled by Hubot.** Day to day operations are exposed as simple
|
11
|
+
Hubot commands that the whole team can use.
|
12
|
+
|
13
|
+
* **Designed for GitHub.** Janky creates the appropriate [web hooks][w] for
|
14
|
+
you and the web app restricts access to members of your GitHub organization.
|
15
|
+
|
16
|
+
[GitHub]: https://github.com
|
17
|
+
[Hubot]: http://hubot.github.com
|
18
|
+
[Jenkins]: http://jenkins-ci.org
|
19
|
+
[w]: http://developer.github.com/v3/repos/hooks/
|
20
|
+
|
21
|
+
Hubot Usage
|
22
|
+
-----------
|
23
|
+
|
24
|
+
Start by setting up a new Jenkins job and GitHub web hook for a
|
25
|
+
repository:
|
26
|
+
|
27
|
+
hubot ci setup github/janky
|
28
|
+
|
29
|
+
The `setup` command can safely be run over and over again. It won't do
|
30
|
+
anything unless it needs to. It takes an optional name argument:
|
31
|
+
|
32
|
+
hubot ci setup github/janky janky-ruby1.9.2
|
33
|
+
|
34
|
+
All branches are built automatically on push. Disable auto build with:
|
35
|
+
|
36
|
+
hubot ci toggle janky
|
37
|
+
|
38
|
+
Run the command again to re-enable it. Force a build of the master
|
39
|
+
branch:
|
40
|
+
|
41
|
+
hubot ci build janky
|
42
|
+
|
43
|
+
Of a specific branch:
|
44
|
+
|
45
|
+
hubot ci build janky/libgit2
|
46
|
+
|
47
|
+
Different builds aren't relevant to the same Campfire room and so Janky
|
48
|
+
lets you choose where notifications are sent to. First get a list of
|
49
|
+
available rooms:
|
50
|
+
|
51
|
+
hubot ci rooms
|
52
|
+
|
53
|
+
Then pick one:
|
54
|
+
|
55
|
+
hubot ci set janky room The Serious Room
|
56
|
+
|
57
|
+
Get the status of a build:
|
58
|
+
|
59
|
+
hubot ci status janky
|
60
|
+
|
61
|
+
Specific branch:
|
62
|
+
|
63
|
+
hubot ci status janky/libgit2
|
64
|
+
|
65
|
+
All builds:
|
66
|
+
|
67
|
+
hubot ci status
|
68
|
+
|
69
|
+
Finally, get a quick reference of the available commands with:
|
70
|
+
|
71
|
+
hubot ci?
|
72
|
+
|
73
|
+
Installing
|
74
|
+
----------
|
75
|
+
|
76
|
+
### Jenkins
|
77
|
+
|
78
|
+
Janky requires access to a Jenkins server. Version **1.427** is
|
79
|
+
recommended. Refer to the Jenkins [documentation][doc] for installation
|
80
|
+
instructions and install the [Notification Plugin][np] version 1.4.
|
81
|
+
|
82
|
+
[doc]: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins
|
83
|
+
[np]: https://wiki.jenkins-ci.org/display/JENKINS/Notification+Plugin
|
84
|
+
|
85
|
+
### Deploying
|
86
|
+
|
87
|
+
Janky is designed to be deployed to [Heroku](https://heroku.com).
|
88
|
+
|
89
|
+
Grab all the necessary files from [this gist][gist]:
|
90
|
+
|
91
|
+
$ git clone gist://gist.github.com/123 janky
|
92
|
+
|
93
|
+
Then push up it to a new Heroku app:
|
94
|
+
|
95
|
+
$ cd janky
|
96
|
+
$ heroku create --stack cedar
|
97
|
+
$ git push heroku master
|
98
|
+
|
99
|
+
After configuration the app (see below), create the database:
|
100
|
+
|
101
|
+
$ heroku run rake db:migrate
|
102
|
+
|
103
|
+
[gist]: https://gist.github.com/gist/1234
|
104
|
+
|
105
|
+
### Configuring
|
106
|
+
|
107
|
+
Janky is configured using environment variables. Use the `heroku config`
|
108
|
+
command:
|
109
|
+
|
110
|
+
$ heroku config:add VARIABLE=value
|
111
|
+
|
112
|
+
Required settings:
|
113
|
+
|
114
|
+
* `JANKY_BASE_URL`: The application URL with a trailing slash. Example:
|
115
|
+
`http://mf-doom-42.heroku.com/`.
|
116
|
+
* `JANKY_BUILDER_DEFAULT`: The Jenkins server URL with a trailing slash.
|
117
|
+
Example: `http://jenkins.example.com/`.
|
118
|
+
* `JANKY_CONFIG_DIR`: Directory where build config templates are stored.
|
119
|
+
Typically set to `/app/config` on Heroku.
|
120
|
+
* `JANKY_HUBOT_USER`: Login used to protect the Hubot API.
|
121
|
+
* `JANKY_HUBOT_PASSWORD`: Password for the Hubot API.
|
122
|
+
* `JANKY_GITHUB_USER`: The login of the GitHub user used to access the
|
123
|
+
API. Requires Push and Pull privileges.
|
124
|
+
* `JANKY_GITHUB_PASSWORD`: The password for the GitHub user.
|
125
|
+
* `JANKY_GITHUB_HOOK_SECRET`: Secret used to sign hook requests from
|
126
|
+
GitHub.
|
127
|
+
* `JANKY_CAMPFIRE_ACCOUNT`: The name of your Campfire account.
|
128
|
+
* `JANKY_CAMPFIRE_TOKEN`: The authentication token of the user sending
|
129
|
+
build notifications.
|
130
|
+
* `JANKY_CAMPFIRE_DEFAULT_ROOM`: The name of the room where notifications
|
131
|
+
are sent by default. Example: "Builds".
|
132
|
+
|
133
|
+
To restrict access to members of a GitHub organization, [register a new
|
134
|
+
OAuth application on GitHub](https://github.com/account/applications)
|
135
|
+
with the callback set to `$JANKY_BASE_URL/auth/github/callback` then set
|
136
|
+
a few extra settings:
|
137
|
+
|
138
|
+
* `JANKY_SESSION_SECRET`: Random session cookie secret. Typically
|
139
|
+
generated by a tool like `pgwen`.
|
140
|
+
* `JANKY_AUTH_CLIENT_ID`: The client ID of the OAuth application.
|
141
|
+
* `JANKY_AUTH_CLIENT_SECRET`: The client secret of the OAuth application.
|
142
|
+
* `JANKY_AUTH_ORGANIZATION`: The organization name. Example: "github".
|
143
|
+
|
144
|
+
### Hubot
|
145
|
+
|
146
|
+
Install the [ci script](http://git.io/hubot-ci-master) in your Hubot
|
147
|
+
then set the `HUBOT_JANKY_URL` environment variable. Example:
|
148
|
+
`http://user:secret@janky.example.com/_hubot/`, with user and password
|
149
|
+
replaced by `JANKY_HUBOT_USER` and `JANKY_HUBOT_PASSWORD` repectively.
|
150
|
+
|
151
|
+
### Custom Build Configuration
|
152
|
+
|
153
|
+
The default build command should suffice for most Ruby applications:
|
154
|
+
|
155
|
+
$ bundle install --path vendor/gems --binstubs
|
156
|
+
$ bundle exec rake
|
157
|
+
|
158
|
+
For more control you can add a `script/cibuild` at the root of your
|
159
|
+
repository for Jenkins to execute instead.
|
160
|
+
|
161
|
+
For total control, whole Jenkins' `config.xml` files can be associated
|
162
|
+
with Janky builds. Given a build called `windows`, Janky will try
|
163
|
+
`config/jobs/windows.xml.erb` before falling back to the default
|
164
|
+
configuration, `config/jobs/default.xml.erb`. After updating or adding
|
165
|
+
a custom config, run `hubot ci setup` again to update the Jenkins
|
166
|
+
server.
|
167
|
+
|
168
|
+
Hacking
|
169
|
+
-------
|
170
|
+
|
171
|
+
Create the databases:
|
172
|
+
|
173
|
+
$ mysqladmin -uroot create janky_development
|
174
|
+
$ mysqladmin -uroot create janky_test
|
175
|
+
|
176
|
+
Create the tables:
|
177
|
+
|
178
|
+
$ RACK_ENV=development bin/rake db:migrate
|
179
|
+
$ RACK_ENV=test bin/rake db:migrate
|
180
|
+
|
181
|
+
Get your environment up and running:
|
182
|
+
|
183
|
+
$ script/boostrap
|
184
|
+
|
185
|
+
Seed some data into the development database:
|
186
|
+
|
187
|
+
$ bin/rake db:seed
|
188
|
+
|
189
|
+
Start the server:
|
190
|
+
|
191
|
+
$ script/server
|
192
|
+
|
193
|
+
Open the app:
|
194
|
+
|
195
|
+
$ open http://localhost:9393/
|
196
|
+
|
197
|
+
Run the test suite:
|
198
|
+
|
199
|
+
$ ruby test/janky_spec.rb
|
200
|
+
|
201
|
+
Contributing
|
202
|
+
------------
|
203
|
+
|
204
|
+
Fork the [Janky repository on GitHub](https://github.com/github/janky) and
|
205
|
+
send a Pull Request.
|
206
|
+
|
207
|
+
Copying
|
208
|
+
-------
|
209
|
+
|
210
|
+
Copyright © 2011, GitHub, Inc. See the `COPYING` file for license
|
211
|
+
rights and limitations (MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
|
2
|
+
ENV["RACK_ENV"] ||= "development"
|
3
|
+
|
4
|
+
require "janky"
|
5
|
+
Janky.setup(ENV)
|
6
|
+
require "janky/tasks"
|
7
|
+
|
8
|
+
task "db:seed" do
|
9
|
+
if ENV["RACK_ENV"] != "development"
|
10
|
+
fail "refusing to load seed data into non-development database"
|
11
|
+
end
|
12
|
+
|
13
|
+
dump = File.expand_path("../lib/janky/database/seed.dump.gz", __FILE__)
|
14
|
+
|
15
|
+
Replicate::Loader.new do |loader|
|
16
|
+
loader.log_to $stderr, false, false
|
17
|
+
loader.read Zlib::GzipReader.open(dump)
|
18
|
+
end
|
19
|
+
end
|
data/config.ru
ADDED
data/janky.gemspec
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.expand_path("../lib/janky/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new "janky", Janky::VERSION do |s|
|
4
|
+
s.description = "Janky is a Continuous Integration server"
|
5
|
+
s.summary = "Continuous Integration server built on top of Jenkins and " \
|
6
|
+
"designed for GitHub and Hubot"
|
7
|
+
s.authors = ["GitHub, Inc."]
|
8
|
+
s.homepage = "https://github.com/github/janky"
|
9
|
+
s.has_rdoc = false
|
10
|
+
|
11
|
+
# runtime
|
12
|
+
s.add_dependency "rake", "~>0.9.2"
|
13
|
+
s.add_dependency "sinatra", "~>1.3"
|
14
|
+
s.add_dependency "sinatra_auth_github", "~>0.1.5"
|
15
|
+
s.add_dependency "mustache", "~>0.11"
|
16
|
+
s.add_dependency "yajl-ruby", "~>0.8"
|
17
|
+
s.add_dependency "activerecord", "~>3.1.0"
|
18
|
+
s.add_dependency "broach", "~>0.2"
|
19
|
+
s.add_dependency "replicate", "~>1.4"
|
20
|
+
|
21
|
+
# development
|
22
|
+
s.add_development_dependency "shotgun", "~>0.9"
|
23
|
+
s.add_development_dependency "thin", "~>1.2"
|
24
|
+
s.add_development_dependency "mysql2", "~>0.3.0"
|
25
|
+
|
26
|
+
# test
|
27
|
+
s.add_development_dependency "database_cleaner", "~>0.6"
|
28
|
+
|
29
|
+
s.files = %w[
|
30
|
+
CHANGES
|
31
|
+
COPYING
|
32
|
+
Gemfile
|
33
|
+
README.md
|
34
|
+
Rakefile
|
35
|
+
config.ru
|
36
|
+
janky.gemspec
|
37
|
+
lib/janky.rb
|
38
|
+
lib/janky/app.rb
|
39
|
+
lib/janky/branch.rb
|
40
|
+
lib/janky/build.rb
|
41
|
+
lib/janky/build_request.rb
|
42
|
+
lib/janky/builder.rb
|
43
|
+
lib/janky/builder/client.rb
|
44
|
+
lib/janky/builder/http.rb
|
45
|
+
lib/janky/builder/mock.rb
|
46
|
+
lib/janky/builder/payload.rb
|
47
|
+
lib/janky/builder/receiver.rb
|
48
|
+
lib/janky/builder/runner.rb
|
49
|
+
lib/janky/campfire.rb
|
50
|
+
lib/janky/campfire/mock.rb
|
51
|
+
lib/janky/commit.rb
|
52
|
+
lib/janky/database/migrate/1312115512_init.rb
|
53
|
+
lib/janky/database/migrate/1312117285_non_unique_repo_uri.rb
|
54
|
+
lib/janky/database/migrate/1312198807_repo_enabled.rb
|
55
|
+
lib/janky/database/migrate/1313867551_add_build_output_column.rb
|
56
|
+
lib/janky/database/migrate/1313871652_add_commit_url_column.rb
|
57
|
+
lib/janky/database/migrate/1317384618_add_repo_hook_url.rb
|
58
|
+
lib/janky/database/migrate/1317384619_add_build_room_id.rb
|
59
|
+
lib/janky/database/migrate/1317384629_drop_default_room_id.rb
|
60
|
+
lib/janky/database/migrate/1317384649_github_team_id.rb
|
61
|
+
lib/janky/database/schema.rb
|
62
|
+
lib/janky/database/seed.dump.gz
|
63
|
+
lib/janky/exception.rb
|
64
|
+
lib/janky/github.rb
|
65
|
+
lib/janky/github/api.rb
|
66
|
+
lib/janky/github/commit.rb
|
67
|
+
lib/janky/github/mock.rb
|
68
|
+
lib/janky/github/payload.rb
|
69
|
+
lib/janky/github/payload_parser.rb
|
70
|
+
lib/janky/github/receiver.rb
|
71
|
+
lib/janky/helpers.rb
|
72
|
+
lib/janky/hubot.rb
|
73
|
+
lib/janky/job_creator.rb
|
74
|
+
lib/janky/notifier.rb
|
75
|
+
lib/janky/notifier/campfire.rb
|
76
|
+
lib/janky/notifier/mock.rb
|
77
|
+
lib/janky/notifier/multi.rb
|
78
|
+
lib/janky/public/css/base.css
|
79
|
+
lib/janky/public/images/building-bot.gif
|
80
|
+
lib/janky/public/images/disclosure-arrow.png
|
81
|
+
lib/janky/public/images/logo.png
|
82
|
+
lib/janky/public/images/robawt-status.gif
|
83
|
+
lib/janky/public/javascripts/application.js
|
84
|
+
lib/janky/public/javascripts/jquery.js
|
85
|
+
lib/janky/public/javascripts/jquery.relatize.js
|
86
|
+
lib/janky/repository.rb
|
87
|
+
lib/janky/tasks.rb
|
88
|
+
lib/janky/templates/console.mustache
|
89
|
+
lib/janky/templates/index.mustache
|
90
|
+
lib/janky/templates/layout.mustache
|
91
|
+
lib/janky/version.rb
|
92
|
+
lib/janky/views/console.rb
|
93
|
+
lib/janky/views/index.rb
|
94
|
+
lib/janky/views/layout.rb
|
95
|
+
]
|
96
|
+
|
97
|
+
s.test_files = %w[
|
98
|
+
test/default.xml.erb
|
99
|
+
test/janky_test.rb
|
100
|
+
test/test_helper.rb
|
101
|
+
]
|
102
|
+
end
|
data/lib/janky.rb
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "digest/md5"
|
3
|
+
|
4
|
+
require "active_record"
|
5
|
+
require "replicate"
|
6
|
+
require "sinatra/base"
|
7
|
+
require "mustache/sinatra"
|
8
|
+
require "yajl"
|
9
|
+
require "yajl/json_gem"
|
10
|
+
require "tilt"
|
11
|
+
require "broach"
|
12
|
+
require "sinatra/auth/github"
|
13
|
+
|
14
|
+
require "janky/repository"
|
15
|
+
require "janky/branch"
|
16
|
+
require "janky/commit"
|
17
|
+
require "janky/build"
|
18
|
+
require "janky/build_request"
|
19
|
+
require "janky/github"
|
20
|
+
require "janky/github/api"
|
21
|
+
require "janky/github/mock"
|
22
|
+
require "janky/github/payload"
|
23
|
+
require "janky/github/commit"
|
24
|
+
require "janky/github/payload_parser"
|
25
|
+
require "janky/github/receiver"
|
26
|
+
require "janky/job_creator"
|
27
|
+
require "janky/helpers"
|
28
|
+
require "janky/hubot"
|
29
|
+
require "janky/builder"
|
30
|
+
require "janky/builder/client"
|
31
|
+
require "janky/builder/runner"
|
32
|
+
require "janky/builder/http"
|
33
|
+
require "janky/builder/mock"
|
34
|
+
require "janky/builder/payload"
|
35
|
+
require "janky/builder/receiver"
|
36
|
+
require "janky/campfire"
|
37
|
+
require "janky/exception"
|
38
|
+
require "janky/notifier"
|
39
|
+
require "janky/notifier/mock"
|
40
|
+
require "janky/notifier/multi"
|
41
|
+
require "janky/notifier/campfire"
|
42
|
+
require "janky/app"
|
43
|
+
require "janky/views/layout"
|
44
|
+
require "janky/views/index"
|
45
|
+
require "janky/views/console"
|
46
|
+
|
47
|
+
# This is Janky, a continuous integration server. Checkout the 'app'
|
48
|
+
# method on this module for an overview of the different components
|
49
|
+
# involved.
|
50
|
+
module Janky
|
51
|
+
# The base exception class raised when errors are encountered.
|
52
|
+
class Error < StandardError; end
|
53
|
+
|
54
|
+
# Setup the application, including the database and Jenkins connections.
|
55
|
+
#
|
56
|
+
# settings - Hash of app settings. Typically ENV but any object responding
|
57
|
+
# to #[] is valid. See required_settings for required keys.
|
58
|
+
# The RACK_ENV setting is always required.
|
59
|
+
#
|
60
|
+
# Raises an Error when required settings are missing.
|
61
|
+
# Returns nothing.
|
62
|
+
def self.setup(settings)
|
63
|
+
env = settings["RACK_ENV"]
|
64
|
+
if env.nil? || env.empty?
|
65
|
+
raise Error, "RACK_ENV is required"
|
66
|
+
end
|
67
|
+
|
68
|
+
required_settings.each do |setting|
|
69
|
+
next if !settings[setting].nil? && !settings[setting].empty?
|
70
|
+
|
71
|
+
if env == "production"
|
72
|
+
raise Error, "#{setting} setting is required"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
if env != "production"
|
77
|
+
settings["DATABASE_URL"] ||= "mysql2://root@localhost/janky_#{env}"
|
78
|
+
settings["JANKY_BASE_URL"] ||= "http://localhost:9393"
|
79
|
+
settings["JANKY_BUILDER_DEFAULT"] ||= "http://localhost:8080/"
|
80
|
+
settings["JANKY_CONFIG_DIR"] ||= File.dirname(__FILE__)
|
81
|
+
end
|
82
|
+
|
83
|
+
database = URI(settings["DATABASE_URL"])
|
84
|
+
adapter = database.scheme == "postgres" ? "postgresql" : database.scheme
|
85
|
+
base_url = URI(settings["JANKY_BASE_URL"]).to_s
|
86
|
+
|
87
|
+
ActiveRecord::Base.establish_connection(
|
88
|
+
:adapter => adapter,
|
89
|
+
:host => database.host,
|
90
|
+
:database => database.path[1..-1],
|
91
|
+
:username => database.user,
|
92
|
+
:password => database.password,
|
93
|
+
:reconnect => true
|
94
|
+
)
|
95
|
+
|
96
|
+
self.jobs_config_dir = config_dir = Pathname(settings["JANKY_CONFIG_DIR"])
|
97
|
+
if !config_dir.directory?
|
98
|
+
raise Error, "#{config_dir} is not a directory"
|
99
|
+
end
|
100
|
+
|
101
|
+
# Setup the callback URL of this Janky host.
|
102
|
+
Janky::Builder.setup(base_url + "/_builder")
|
103
|
+
|
104
|
+
# Setup the default Jenkins build host
|
105
|
+
Janky::Builder[:default] = settings["JANKY_BUILDER_DEFAULT"]
|
106
|
+
|
107
|
+
Janky::GitHub.setup(
|
108
|
+
settings["JANKY_GITHUB_USER"],
|
109
|
+
settings["JANKY_GITHUB_PASSWORD"],
|
110
|
+
settings["JANKY_GITHUB_HOOK_SECRET"],
|
111
|
+
base_url + "/_github"
|
112
|
+
)
|
113
|
+
|
114
|
+
if settings.key?("JANKY_SESSION_SECRET")
|
115
|
+
Janky::App.register Sinatra::Auth::Github
|
116
|
+
Janky::App.set({
|
117
|
+
:sessions => true,
|
118
|
+
:session_secret => settings["JANKY_SESSION_SECRET"],
|
119
|
+
:github_team_id => settings["JANKY_AUTH_TEAM_ID"],
|
120
|
+
:github_organization => settings["JANKY_AUTH_ORGANIZATION"],
|
121
|
+
:github_options => {
|
122
|
+
:secret => settings["JANKY_AUTH_CLIENT_SECRET"],
|
123
|
+
:client_id => settings["JANKY_AUTH_CLIENT_ID"],
|
124
|
+
:scopes => "repo",
|
125
|
+
},
|
126
|
+
})
|
127
|
+
end
|
128
|
+
|
129
|
+
Janky::Hubot.set(
|
130
|
+
:base_url => settings["JANKY_BASE_URL"],
|
131
|
+
:username => settings["JANKY_HUBOT_USER"],
|
132
|
+
:password => settings["JANKY_HUBOT_PASSWORD"]
|
133
|
+
)
|
134
|
+
|
135
|
+
Janky::Campfire.setup(
|
136
|
+
settings["JANKY_CAMPFIRE_ACCOUNT"],
|
137
|
+
settings["JANKY_CAMPFIRE_TOKEN"],
|
138
|
+
settings["JANKY_CAMPFIRE_DEFAULT_ROOM"]
|
139
|
+
)
|
140
|
+
|
141
|
+
Janky::Exception.setup(Janky::Exception::Mock)
|
142
|
+
|
143
|
+
Notifier.setup(Notifier::Campfire)
|
144
|
+
end
|
145
|
+
|
146
|
+
# List of settings required in production.
|
147
|
+
#
|
148
|
+
# Returns an Array of Strings.
|
149
|
+
def self.required_settings
|
150
|
+
%w[RACK_ENV DATABASE_URL
|
151
|
+
JANKY_BASE_URL
|
152
|
+
JANKY_BUILDER_DEFAULT
|
153
|
+
JANKY_CONFIG_DIR
|
154
|
+
JANKY_GITHUB_USER JANKY_GITHUB_PASSWORD JANKY_GITHUB_HOOK_SECRET
|
155
|
+
JANKY_HUBOT_USER JANKY_HUBOT_PASSWORD
|
156
|
+
JANKY_CAMPFIRE_ACCOUNT JANKY_CAMPFIRE_TOKEN JANKY_CAMPFIRE_DEFAULT_ROOM]
|
157
|
+
end
|
158
|
+
|
159
|
+
# Directory where Jenkins job configuration templates are located.
|
160
|
+
#
|
161
|
+
# Returns the directory as a Pathname.
|
162
|
+
class << self
|
163
|
+
attr_accessor :jobs_config_dir
|
164
|
+
end
|
165
|
+
|
166
|
+
# Mock out all network-dependant components. Must be called after setup.
|
167
|
+
# Typically used in test environments.
|
168
|
+
#
|
169
|
+
# Returns nothing.
|
170
|
+
def self.enable_mock!
|
171
|
+
Janky::Builder.enable_mock!
|
172
|
+
Janky::GitHub.enable_mock!
|
173
|
+
Janky::Notifier.enable_mock!
|
174
|
+
Janky::Campfire.enable_mock!
|
175
|
+
Janky::App.disable :github_team_id
|
176
|
+
end
|
177
|
+
|
178
|
+
# Reset the state of the mocks.
|
179
|
+
#
|
180
|
+
# Returns nothing.
|
181
|
+
def self.reset!
|
182
|
+
Janky::Notifier.reset!
|
183
|
+
Janky::Builder.reset!
|
184
|
+
end
|
185
|
+
|
186
|
+
# The Janky Rack application, assembled from four apps. Exceptions
|
187
|
+
# raised during the request cycle are caught by the Exception
|
188
|
+
# middleware which typically report exceptions to an external
|
189
|
+
# service before re-raising the exception.
|
190
|
+
#
|
191
|
+
# Returns a memoized Rack application.
|
192
|
+
def self.app
|
193
|
+
@app ||= Rack::Builder.app {
|
194
|
+
# Exception reporting middleware.
|
195
|
+
use Janky::Exception::Middleware
|
196
|
+
|
197
|
+
# GitHub Post-Receive requests.
|
198
|
+
map "/_github" do
|
199
|
+
run Janky::GitHub.receiver
|
200
|
+
end
|
201
|
+
|
202
|
+
# Jenkins callback requests.
|
203
|
+
map "/_builder" do
|
204
|
+
run Janky::Builder.receiver
|
205
|
+
end
|
206
|
+
|
207
|
+
# Hubot API, protected by Basic Auth.
|
208
|
+
map "/_hubot" do
|
209
|
+
use Rack::Auth::Basic do |username, password|
|
210
|
+
username == Janky::Hubot.username &&
|
211
|
+
password == Janky::Hubot.password
|
212
|
+
end
|
213
|
+
|
214
|
+
run Janky::Hubot
|
215
|
+
end
|
216
|
+
|
217
|
+
# Web dashboard
|
218
|
+
map "/" do
|
219
|
+
use Janky::NoAuth
|
220
|
+
run Janky::App
|
221
|
+
end
|
222
|
+
}
|
223
|
+
end
|
224
|
+
end
|