forked from travis-ci/travis-ci.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
235 lines (187 loc) · 8.62 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Travis CI: About - Databases on Travis workers</title>
<link rel="stylesheet" type="text/css" href="/style.css" media="screen">
</head>
<body>
<div id="navigation">
<div class="wrapper">
<a href="http://travis-ci.org" id="logo">travis-ci<span>.org</span></a>
<ul>
<li><a href="/">Blog</a></li>
<li><a href="/docs/">Docs</a></li>
<li class="right"><a href="http://travis-ci.org">go to travis-ci.org →</a></li>
</ul>
</div>
</div>
<div id="header">
<div class="wrapper">
<h1 class="riddle"><a href="/" title="Travis">Travis CI</a></h1>
<p>An open-source, distributed build system for the open source community.</p>
</div><!-- /.wrapper -->
</div><!-- /#header -->
<div id="content">
<div class="wrapper">
<div class="pad">
<div id="main">
<h2>Databases on Travis workers</h2>
<p>Every Travis CI worker has preinstalled software that’s commonly used by the open source developer community. Some of the services available are:</p>
<ul>
<li>databases – MySQL, PostgreSQL, SQLite3, MongoDB</li>
<li>key-value stores – Redis, Riak, memcached</li>
<li>messaging systems – RabbitMQ</li>
<li>node.js, ImageMagick</li>
</ul>
<p>You can find the full list of installed software, as well as Ruby engines and versions, in the <a href="https://github.com/travis-ci/travis-worker/blob/master/config/worker.production.yml">worker
configuration file</a>. That file specifies which <a href="https://github.com/travis-ci/travis-cookbooks">recipes from the cookbook</a> are used while building the worker instance.</p>
<p>Some of these, e.g. node.js and memcached, are either available in the PATH or running on a default port, so no special information about them is required. Others, namely databases, may require authentication.</p>
<p>Here is how to configure your project to use databases in its tests. This assumes you have already visited <a href="/docs/user/build-configuration/">Build configuration</a> documentation.</p>
<h3 id="sqlite3">SQLite3</h3>
<p>Probably the easiest and simplest solution for your relation database needs. If you don’t specifically want to test how your code behaves with other databases, SQLite in memory might be the best and fastest option.</p>
<p>For ruby projects, ensure that you have the sqlite3 ruby bindings in your bundle:</p>
<pre><code># Gemfile
gem 'sqlite3'
</code></pre>
<p>If your project is a Rails app, all you need to set up is:</p>
<pre><code># config/database.yml in Rails
test:
adapter: sqlite3
database: ":memory:"
timeout: 500
</code></pre>
<p>However, if your project is a general library or plugin, you need to handle connecting to the database yourself in tests. For example, connecting with ActiveRecord:</p>
<pre><code>ActiveRecord::Base.establish_connection :adapter => 'sqlite3',
:database => ':memory:'
</code></pre>
<h3 id="mysql">MySQL</h3>
<p>MySQL on Travis requires no authentication. Specify an empty username and no password:</p>
<pre><code>mysql:
adapter: mysql2
database: myapp_test
username:
encoding: utf8
</code></pre>
<p>You do have to create the <code>myapp_test</code> database first. Run this as part of your build script:</p>
<pre><code># .travis.yml
before_script:
- "mysql -e 'create database myapp_test;' >/dev/null"
</code></pre>
<h3 id="postgresql">PostgreSQL</h3>
<p>PostgreSQL requires authentication with “postgres” user and no password:</p>
<pre><code>postgres:
adapter: postgresql
database: myapp_test
username: postgres
</code></pre>
<p>You have to create the database as part of your build process:</p>
<pre><code># .travis.yml
before_script:
- "psql -c 'create database myapp_test;' -U postgres >/dev/null"
</code></pre>
<h3 id="mongodb">MongoDB</h3>
<p>MongoDB requires no authentication or database creation up front:</p>
<pre><code>require 'mongo'
Mongo::Connection.new('localhost').db('myapp')
</code></pre>
<p>In cases you need to create users for your database, you can do something like this:</p>
<pre><code># .travis.yml
before_script:
- mongo myapp --eval 'db.addUser("travis", "test");'
# then, in ruby:
uri = "mongodb://travis:test@localhost:27017/myapp"
Mongo::Connection.from_uri(uri)
</code></pre>
<h3 id="multiple-database-systems">Multiple database systems</h3>
<p>If your project’s tests need to run multiple times using different databases, this can be configured on Travis CI in several ways. One approach you might take is put all database configurations in one yaml file:</p>
<pre><code># test/database.yml
sqlite:
adapter: sqlite3
database: ":memory:"
timeout: 500
mysql:
adapter: mysql2
database: myapp_test
username:
encoding: utf8
postgres:
adapter: postgresql
database: myapp_test
username: postgres
</code></pre>
<p>Then, in your test suite, read that data into a configurations hash:</p>
<pre><code>configs = YAML.load_file('test/database.yml')
ActiveRecord::Base.configurations = configs
db_name = ENV['DB'] || 'sqlite'
ActiveRecord::Base.establish_connection(db_name)
ActiveRecord::Base.default_timezone = :utc
</code></pre>
<p>Now you use the “DB” environment variable to specify the name of the database configuration you want to use. Locally, you would run this as:</p>
<pre><code>$ DB=postgres bundle exec rake
</code></pre>
<p>On Travis CI you want to test against all 3 databases all the time, and for that you can use the “env” option:</p>
<pre><code># .travis.yml
env:
- DB=sqlite
- DB=mysql
- DB=postgres
</code></pre>
<p>When doing this, please read and understand everything about the build matrix described in <a href="/docs/user/build-configuration/">Build configuration</a>.</p>
<p>Lastly, make sure that you’re creating mysql and postgres databases in your build script according to the notes earlier in this document.</p>
</div><!-- /#main -->
<div id="sidebar">
<h2>Contact</h2>
<ul>
<li><a href="http://github.com/travis-ci">Github</a></li>
<li><a href="http://twitter.com/travisci">Twitter</a></li>
<li><a href="irc://irc.freenode.net#travis">IRC</a></li>
<li><a href="http://groups.google.com/group/travis-ci">Mailinglist</a></li>
</ul>
<h2>User Docs</h2>
<ul>
<li><a href="/docs/user/getting-started/">Getting started</a></li>
<li><a href="/docs/user/build-configuration/">Build configuration</a></li>
<li><a href="/docs/user/database-setup/">Database setup</a></li>
<li><a href="/docs/user/status-images/">Status images</a></li>
<li><a href="/docs/user/resources/">Resources</a></li>
<li><a href="/docs/user/ci-environment/">CI environment</a></li>
</ul>
<h2>Languages</h2>
<ul>
<li><a href="/docs/user/languages/clojure/">Clojure</a></li>
<li><a href="/docs/user/languages/erlang/">Erlang</a></li>
<li><a href="/docs/user/languages/javascript-with-nodejs/">JavaScript (with Node.js)</a></li>
<li><a href="/docs/user/languages/ruby/">Ruby</a></li>
</ul>
<h2>Developer Docs</h2>
<ul>
<li><a href="/docs/dev/worker/">The worker</a></li>
<li><a href="/docs/dev/api/">The API</a></li>
</ul>
<h2>Under construction</h2>
<ul>
<li><p>Our site is still under construction. You can help us in: travis#irc.freenode.net</p></li>
</ul>
</div><!-- /#sidebar -->
</div><!-- /.pad -->
</div><!-- /.wrapper -->
</div><!-- /#content -->
<div id="footer">
<div class="wrapper">
<div class="box">
<p>This site is maintained by the <a href="http://github.com/travis-ci">Travis CI community</a>. Feel free to <a href="http://github.com/travis-ci/travis-ci.github.com">contribute</a>!</p>
</div>
<div class="box">
<p>This design was kindly provided by the talented Ben Webster of <a href="http://www.plus2.com.au">Plus2</a>.</p>
</div>
<div class="box last">
<ul>
<li><a href="http://github.com/travis-ci/travis-ci" title="">View the Source</a></li>
<li><a href="http://twitter.com/travisci" title="">Travis CI on Twitter</a></li>
</ul>
</div><!-- /.box -->
</div><!-- /.wrapper -->
</div><!-- /#footer -->
</body>
</html>