-
Notifications
You must be signed in to change notification settings - Fork 3
/
fabfile.py
721 lines (603 loc) · 26.9 KB
/
fabfile.py
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
import signal
import StringIO
import sys
import time
from fabric.api import *
import fabric.contrib.files
env.use_ssh_config = True
RVM = '~/.rvm/scripts/rvm'
PHANTOMJS = '~/phantomjs-1.9.7-linux-x86_64/bin'
def _setup():
sudo('apt-get update')
sudo('apt-get install --yes git')
_setup_rvm()
def _setup_rvm():
if not fabric.contrib.files.exists(RVM):
sudo('apt-get install --yes curl')
run('gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3')
run('wget -q -O - https://get.rvm.io | bash -s -- --ignore-dotfiles')
def _setup_ssl():
if not fabric.contrib.files.exists('server.crt'):
run('openssl genrsa -des3 -passout pass:x -out server.pass.key 2048')
run('openssl rsa -passin pass:x -in server.pass.key -out server.key')
run('rm server.pass.key')
run('openssl req -new -key server.key -out server.csr')
run('openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt')
def _setup_phantomjs():
if not fabric.contrib.files.exists('phantomjs-1.9.7-linux-x86_64'):
run("wget 'https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2'")
run('tar xf phantomjs-1.9.7-linux-x86_64.tar.bz2')
def _install_postgresql():
sudo('apt-get install --yes postgresql-9.3 postgresql-server-dev-9.3 postgresql-client-9.3 postgresql-contrib-9.3 postgresql-plpython-9.3 libpq-dev')
fabric.contrib.files.sed('/etc/postgresql/9.3/main/pg_hba.conf', '^local\s*all\s*all\s*peer\s*$', 'local all all md5', use_sudo=True)
sudo('/etc/init.d/postgresql restart')
def _postgres_user_exists(username):
return '1' in sudo('psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname=\'%s\'"' % username, user='postgres')
def _postgres_db_exists(dbname):
return ' {} '.format(dbname) in sudo('psql -l --pset="pager=off"', user='postgres')
def _postgres_user_exists(username):
return '1' in sudo('psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname=\'%s\'"' % username, user='postgres')
def _postgres_db_exists(dbname):
return dbname in sudo('psql -l --pset="pager=off"', user='postgres')
def _install_nodejs():
# the nodejs package in trusty is too old for grunt-cli,
# so manually installing it here
if run('which node', warn_only=True):
return
sudo('apt-get install --yes make g++')
run('wget http://nodejs.org/dist/v0.12.2/node-v0.12.2.tar.gz')
run('tar xf node-v0.12.2.tar.gz')
with cd('node-v0.12.2'):
run('./configure')
run('make')
sudo('make install')
run('rm -rf node-v0.12.2*')
def accounts_setup(https=''):
"""Set up openstax/accounts"""
_setup()
_setup_ssl()
_install_postgresql()
if not fabric.contrib.files.exists('accounts'):
if https:
run('git clone https://github.com/openstax/accounts')
else:
run('git clone [email protected]:openstax/accounts')
if not _postgres_user_exists('ox_accounts'):
sudo('psql -d postgres -c "CREATE USER ox_accounts WITH SUPERUSER PASSWORD \'ox_accounts\';"', user='postgres')
if not _postgres_db_exists('ox_accounts_dev'):
sudo('createdb -O ox_accounts ox_accounts_dev', user='postgres')
with cd('accounts'):
with prefix('source {}'.format(RVM)):
run('rvm install $(cat .ruby-version)')
run('rvm gemset create accounts')
run('rvm gemset use accounts')
# FIXME not sure why bundle isn't installed
run('which bundle || gem install bundle')
run('bundle install --without production')
run('gem install unicorn-rails')
run('rake db:setup', warn_only=True)
_configure_accounts_nginx()
print """
To use the facebook and twitter login:
1. Create an app on facebook and twitter
2. Paste the "App ID" and "App Secret" from the facebook app settings page into accounts/config/secret_settings.yml:
facebook_app_id: '1234567890'
facebook_app_secret: '1234567890abcdef'
Paste the "Consumer Key" and "Consumer Secret" from the twitter app settings page into accounts/config/secret_settings.yml:
twitter_consumer_key: 'xxxxx'
twitter_consumer_secret: 'yyyyy'
3. Set the callback url on the facebook and twitter app settings page to https://{server}:3000/auth/facebook and https://{server}:3000/auth/twitter respectively. (or the IP address of {server})
""".format(server=env.host)
def accounts_create_admin_user(username='admin', password='password'):
"""Create an admin user in accounts (default admin/password)
"""
print('Creating admin user with username {} and password {}'.format(
username, password))
with cd('accounts'):
put(StringIO.StringIO("""\
user = FactoryGirl.create :user, :admin, :terms_agreed, username: '{}'
identity = FactoryGirl.create :identity, user: user, password: '{}'
FactoryGirl.create :authentication, provider: 'identity', uid: identity.id.to_s, user: user
""".format(username, password)), 'admin_user.rb')
with prefix('source {}'.format(RVM)):
run('bundle exec rails console <admin_user.rb')
def _accounts_run():
# Should use accounts_run_unicorn
with cd('accounts'):
with prefix('source {}'.format(RVM)):
run('rake db:migrate')
# ctrl-c doesn't kill the rails server so the old server is still running
run('kill -9 `cat tmp/pids/server.pid`', warn_only=True)
run('rails server')
def _accounts_run_ssl():
# should use accounts_run_unicorn
with cd('accounts'):
with prefix('source {}'.format(RVM)):
run('thin start -p 3000 --ssl --ssl-verify --ssl-key-file ~/server.key --ssl-cert-file ~/server.crt')
def _configure_accounts_nginx():
sudo('apt-get install --yes nginx')
if not fabric.contrib.files.exists('/etc/nginx/sites-available/accounts',
use_sudo=True):
put(StringIO.StringIO("""\
upstream unicorn {
server unix:/tmp/unicorn.accounts.sock fail_timeout=0;
}
server {
listen 3000 default deferred;
keepalive_timeout 5;
ssl on;
ssl_ciphers RC4:HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_certificate %(home_dir)s/server.crt;
ssl_certificate_key %(home_dir)s/server.key;
add_header Strict-Transport-Security "max-age=631138519";
root %(home_dir)s/accounts/public;
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
}
""" % {'home_dir': run('pwd')}),
'/etc/nginx/sites-available/accounts',
use_sudo=True)
sudo('ln -sf /etc/nginx/sites-available/accounts '
'/etc/nginx/sites-enabled/accounts')
sudo('/etc/init.d/nginx restart')
def accounts_run_unicorn(fg=''):
"""Run openstax/accounts using unicorn_rails"""
with cd('accounts'):
if not fabric.contrib.files.exists('config/unicorn.rb'):
put(StringIO.StringIO("""\
working_directory "{pwd}"
pid "{pwd}/unicorn.pid"
stderr_path "{pwd}/log/unicorn.log"
stdout_path "{pwd}/log/unicorn.log"
listen "/tmp/unicorn.accounts.sock"
worker_processes 1
timeout 30
""".format(pwd=run('pwd'))), 'config/unicorn.rb')
with prefix('source {}'.format(RVM)):
run('bundle install')
run('pkill -f unicorn_rails || 0', warn_only=True)
run('rm -f /tmp/unicorn.accounts.sock')
if fg:
run('unicorn_rails -c config/unicorn.rb')
else:
run('unicorn_rails -D -c config/unicorn.rb')
def accounts_test(test_case=None, traceback=''):
"""Run openstax/accounts tests"""
_setup_phantomjs()
with cd('accounts'):
with prefix('source {}'.format(RVM)):
if test_case:
run('PATH=$PATH:{} rspec {} {}'.format(PHANTOMJS, traceback and '-b', test_case))
else:
if _postgres_db_exists('ox_accounts_test'):
sudo('dropdb ox_accounts_test', user='postgres')
sudo('createdb -O ox_accounts ox_accounts_test', user='postgres')
run('bundle install')
run('RAILS_ENV=test rake db:setup')
run('rake db:migrate')
run('PATH=$PATH:{} rake --trace'.format(PHANTOMJS))
def accounts_routes():
"""Run "rake routes" on openstax/accounts"""
with cd('accounts'):
with prefix('source {}'.format(RVM)):
run('rake routes')
def accounts_log():
"""Show openstax/accounts development.log"""
with cd('accounts'):
run('tail -f log/development.log')
def example_setup():
"""Set up openstax/connect-rails (outdated)"""
_setup()
sudo('apt-get install --yes nodejs')
if not fabric.contrib.files.exists('connect-rails'):
run('git clone https://github.com/openstax/connect-rails')
with cd('connect-rails'):
with prefix('source {}'.format(RVM)):
run('rvm install ruby-1.9.3-p392')
run('rvm gemset create connect-rails')
run('rvm gemset use connect-rails')
run('bundle install --without production')
pwd = run('pwd')
filename = 'connect-rails/lib/openstax/connect/engine.rb'
if not fabric.contrib.files.contains(filename, ':client_options'):
fabric.contrib.files.sed(
filename,
'OpenStax::Connect.configuration.openstax_application_secret',
'OpenStax::Connect.configuration.openstax_application_secret, '
'{:client_options => {:ssl => {:ca_file => "%s/server.crt"}}}'
% pwd)
with cd('connect-rails/example'):
with prefix('source {}'.format(RVM)):
run('rake db:setup', warn_only=True)
run('rake openstax_connect:install:migrations')
print """
To set up openstax/connect-rails with openstax/accounts:
1. Go to http://{server}:2999/oauth/applications
2. Create a "New application" with callback url: "http://{server}:4000/connect/auth/openstax/callback"
3. Click the "Trusted?" checkbox and submit
4. Copy the application ID and secret into connect-rails/example/config/secret_settings.yml, for example:
openstax_application_id: '54cc59280662417f2b30c6869baa9c6cb3360c81c4f9d829155d2485d5bcfeed'
openstax_application_secret: '7ce94d06d7bc8aec4ff81c3f65883300e1e2fa10051e60e58de6d79de91d8608'
5. Set config.openstax_services_url in connect-rails/example/config/initializers/openstax_connect.rb to "https://{server}:3000/" (or the IP address of {server})
6. Start the example application.
7. Go to http://{server}:4000 and click log in
See https://github.com/openstax/connect-rails for full documentation.
""".format(server=env.host)
def example_run():
"""Run openstax/connect-rails (outdated)"""
with cd('connect-rails/example'):
with prefix('source {}'.format(RVM)):
run('rake db:migrate')
# ctrl-c doesn't kill the rails server so the old server is still
# running
run('kill -9 `cat tmp/pids/server.pid`', warn_only=True)
run('rails server')
def accounts_pyramid_setup(https=''):
"""Set up Connexions/openstax-accounts (python)"""
if not fabric.contrib.files.exists('openstax-accounts'):
if https:
run('git clone https://github.com/Connexions/openstax-accounts.git')
else:
run('git clone [email protected]:Connexions/openstax-accounts.git')
def accounts_pyramid_run():
"""Run Connexions/openstax-accounts (python)"""
with cd('openstax-accounts'):
run('./bin/python setup.py install')
run('./bin/pserve development.ini')
def accounts_pyramid_test(test_case=None, display=None, test_all=None):
"""Run Connexions/openstax-accounts (python) tests"""
if not display:
sudo('apt-get install --yes xvfb')
run('pkill -f xvfb', warn_only=True)
if test_case:
test_case = '-s {}'.format(test_case)
else:
test_case = ''
if not fabric.contrib.files.exists('openstax-accounts'):
run('git clone https://github.com/Connexions/openstax-accounts.git')
if not fabric.contrib.files.exists('openstax-accounts/chromedriver'):
with cd('openstax-accounts'):
if not fabric.contrib.files.exists('chromedriver'):
run("wget 'http://chromedriver.storage.googleapis.com/2.14/chromedriver_linux64.zip'")
sudo('apt-get install --yes unzip')
run('unzip chromedriver_linux64.zip')
run('rm chromedriver_linux64.zip')
sudo('apt-get install --yes chromium-browser')
sudo('apt-get install --yes python-virtualenv')
with cd('openstax-accounts'):
if not fabric.contrib.files.exists('bin/python'):
run('virtualenv .')
env = ['PATH=$PATH:.']
if display:
env.append('DISPLAY={}'.format(display))
run('./bin/python setup.py install')
if test_case:
run('{} {} ./bin/python setup.py test {}'.format(' '.join(env),
not display and 'xvfb-run' or '', test_case))
elif test_all:
run('{} {} ./bin/python setup.py test -s '
'openstax_accounts.tests.FunctionalTests'
.format(' '.join(env), not display and 'xvfb-run' or ''))
env.append('TESTING_INI=test_stub.ini')
run('{} {} ./bin/python setup.py test -s '
'openstax_accounts.tests.StubTests'
.format(' '.join(env), not display and 'xvfb-run' or ''))
else:
env.append('LOCAL_INI=.travis_testing.ini')
run('{} {} ./bin/python setup.py test'
.format(' '.join(env), not display and 'xvfb-run' or ''))
def tutor_deployment_setup():
if not fabric.contrib.files.exists('tutor-deployment'):
run('git clone -b feature/exercises [email protected]:openstax/tutor-deployment.git')
sudo('pip install virtualenvwrapper')
with cd('tutor-deployment'):
with prefix('WORKON_HOME=$HOME/.environments'):
with prefix('source /usr/local/bin/virtualenvwrapper_lazy.sh'):
run('mkvirtualenv -p `which python2` tutordep')
with prefix('workon tutordep'):
run('pip install -r requirements.txt')
def accounts_deploy(env='qa'):
with cd('tutor-deployment'):
with prefix('WORKON_HOME=$HOME/.environments'):
with prefix('source /usr/local/bin/virtualenvwrapper_lazy.sh'):
with prefix('workon tutordep'):
run('ansible-playbook -i environments/{env}/accounts-{env}1 '
'accounts_only.yml '
'--vault-password-file $HOME/.ssh/vault-accounts-{env}1 '
'--private-key $HOME/.ssh/tutor-{env}-kp.pem'.format(env=env))
def openstax_api_setup(https=''):
if not fabric.contrib.files.exists('openstax_api'):
if https:
run('git clone https://github.com/openstax/openstax_api.git')
else:
run('git clone [email protected]:openstax/openstax_api.git')
with cd('openstax_api'):
with prefix('source {}'.format(RVM)):
run('rvm install $(cat .ruby-version)')
run('rvm gemset create openstax_api')
run('rvm gemset use openstax_api')
def openstax_api_test():
with cd('openstax_api'):
with prefix('source {}'.format(RVM)):
run('rvm gemset use openstax_api')
run('bundle')
run('rake db:migrate')
run('rake')
def biglearn_algs_setup():
"""Set up openstax/biglearn-algs"""
sudo('apt-get install python-numpy python-scipy')
sudo('pip install virtualenvwrapper')
if not fabric.contrib.files.exists('biglearn-algs'):
run('git clone [email protected]:openstax/biglearn-algs.git')
with cd('biglearn-algs'
), prefix('export WORKON_HOME=$HOME/.environments'
), prefix('source /usr/local/bin/virtualenvwrapper.sh'):
# --system-side-packages includes dist packages (like scipy and
# numpy) in virtualenv
run('mkvirtualenv -p `which python2` --system-site-packages blapidev')
with prefix('workon blapidev'):
run('pip install -e .')
def biglearn_algs_test():
"""Run openstax/biglearn-algs tests"""
with cd('biglearn-algs'):
with prefix('export WORKON_HOME=$HOME/.environments'):
with prefix('source /usr/local/bin/virtualenvwrapper.sh'):
with prefix('workon blapidev'):
run('python setup.py test')
def biglearn_common_setup():
"""Set up openstax/biglearn-common"""
sudo('pip install virtualenvwrapper')
if not fabric.contrib.files.exists('biglearn-common'):
run('git clone [email protected]:openstax/biglearn-common.git')
with cd('biglearn-common'
), prefix('export WORKON_HOME=$HOME/.environments'
), prefix('source /usr/local/bin/virtualenvwrapper.sh'):
run('mkvirtualenv -p `which python2` --system-site-packages blapidev')
with prefix('workon blapidev'):
run('pip install -e .')
def biglearn_platform_setup():
"""Set up openstax/biglearn-platform"""
biglearn_common_setup()
biglearn_algs_setup()
sudo('pip install virtualenvwrapper')
if not fabric.contrib.files.exists('biglearn-platform'):
run('git clone [email protected]:openstax/biglearn-platform.git')
with cd('biglearn-platform/app'
), prefix('export WORKON_HOME=$HOME/.environments'
), prefix('source /usr/local/bin/virtualenvwrapper.sh'):
run('mkvirtualenv -p `which python2` --system-site-packages blapidev')
with prefix('workon blapidev'):
run('pip install -e .')
def tutor_server_setup(https=''):
"""Set up openstax/tutor-server"""
_setup()
_install_postgresql()
sudo('apt-get install --yes qt5-default libqt5webkit5-dev')
if not fabric.contrib.files.exists('tutor-server'):
if https:
run('git clone https://github.com/openstax/tutor-server.git')
else:
run('git clone [email protected]:openstax/tutor-server.git')
if not _postgres_user_exists('ox_tutor'):
sudo('psql -d postgres -c "CREATE USER ox_tutor WITH SUPERUSER PASSWORD \'ox_tutor_secret_password\';"', user='postgres')
if not _postgres_db_exists('ox_tutor_dev'):
sudo('createdb -O ox_tutor ox_tutor_dev', user='postgres')
with cd('tutor-server'):
with prefix('source {}'.format(RVM)):
run('rvm install $(cat .ruby-version)')
run('rvm gemset create $(cat .ruby-gemset)')
run('rvm gemset use $(cat .ruby-gemset)')
run('bundle install --without production')
run('rake db:migrate')
run('rake db:seed')
def tutor_server_run():
"""Run rails server on openstax/tutor-server"""
def sigint_handler(signal, frame):
if fabric.contrib.files.exists('tmp/pids/server.pid'):
run('kill `cat tmp/pids/server.pid`', warn_only=True)
run('rm -f tmp/pids/server.pid')
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
with cd('tutor-server'):
with prefix('source {}'.format(RVM)):
run('rake db:migrate')
run('rails server -b 0.0.0.0')
def tutor_server_test(test_case=None):
"""Run openstax/tutor-server tests"""
if _postgres_db_exists('ox_tutor_test'):
sudo('dropdb ox_tutor_test', user='postgres')
sudo('createdb -O ox_tutor ox_tutor_test', user='postgres')
with cd('tutor-server'):
with prefix('source {}'.format(RVM)):
if test_case:
run('rspec -b {}'.format(test_case))
else:
run('bundle install --without production')
run('rake db:drop && rake db:create && rake db:migrate')
run('rake')
def tutor_js_setup(https=''):
"""Set up openstax/tutor-js"""
_setup()
_install_nodejs()
sudo('npm install -g gulp bower')
if not fabric.contrib.files.exists('tutor-js'):
if https:
run('git clone https://github.com/openstax/tutor-js.git')
else:
run('git clone [email protected]:openstax/tutor-js.git')
with cd('tutor-js'):
run('npm install')
run('bower install')
def tutor_js_run():
"""Run openstax/tutor-js"""
with cd('tutor-js'):
run('PORT=8001 gulp serve')
def tutor_js_test():
"""Run openstax/tutor-js tests"""
with cd('tutor-js'):
sudo('npm install -g gulp bower')
run('bower install')
run('npm install')
run('npm test')
def osc_setup():
"""Set up lml/osc"""
_setup()
sudo('apt-get install libxml2-dev libxslt-dev')
if not fabric.contrib.files.exists('osc'):
run('git clone [email protected]:lml/osc.git')
with cd('osc'):
run('rm -f .rvmrc')
with prefix('source {}'.format(RVM)):
run('rvm install $(cat .ruby-version)')
run('rvm gemset create $(cat .ruby-gemset)')
run('rvm gemset use $(cat .ruby-gemset)')
# Install bundler in case it is not installed
run('which bundle || gem install bundler')
run('bundle install --without production')
run('rake db:setup')
def osc_run():
"""Run lml/osc server"""
with cd('osc'):
with prefix('source {}'.format(RVM)):
# ctrl-c doesn't kill the rails server so the old server is still
# running
run('kill -9 `cat tmp/pids/server.pid`', warn_only=True)
run('rails server -p 3002')
def osc_test(test_case=None):
"""Run lml/osc tests"""
with cd('osc'):
with prefix('source {}'.format(RVM)):
if test_case:
run('rspec -b {}'.format(test_case))
else:
run('bundle install')
run('rake db:migrate')
run('rake')
def exercises_setup(https=''):
"""Set up openstax/exercises"""
_setup()
sudo('apt-get install --yes libicu-dev')
if not fabric.contrib.files.exists('exercises'):
if https:
run('git clone https://github.com/openstax/exercises.git')
else:
run('git clone [email protected]:openstax/exercises.git')
if not _postgres_user_exists('ox_exercises'):
sudo('psql -d postgres -c "CREATE USER ox_exercises WITH CREATEDB PASSWORD \'ox_exercises\'"', user='postgres')
if not _postgres_db_exists('ox_exercises_dev'):
sudo('createdb -O ox_exercises ox_exercises_dev', user='postgres')
with cd('exercises'):
with prefix('source {}'.format(RVM)):
run('rvm install $(cat .ruby-version)')
run('rvm gemset create $(cat .ruby-gemset)')
run('rvm gemset use $(cat .ruby-gemset)')
run('bundle install --without production')
run('rake db:migrate')
run('rake db:seed')
def exercises_run():
"""Run openstax/exercises"""
with cd('exercises'):
with prefix('source {}'.format(RVM)):
# ctrl-c doesn't kill the rails server so the old server is still
# running
run('kill -9 `cat tmp/pids/server.pid`', warn_only=True)
run('rails server')
def exercises_test(test_case=None):
"""Run openstax/exercises tests"""
if _postgres_db_exists('ox_exercises_test'):
sudo('dropdb ox_exercises_test', user='postgres')
sudo('createdb -O ox_exercises ox_exercises_test', user='postgres')
with cd('exercises'):
with prefix('source {}'.format(RVM)):
if test_case:
run('rspec -b {}'.format(test_case))
else:
run('bundle install --without production')
run('rake db:migrate')
run('rake')
def exchange_setup(https=''):
"""Set up openstax/exchange"""
_setup()
if not fabric.contrib.files.exists('exchange'):
if https:
run('git clone https://github.com/openstax/exchange.git')
else:
run('git clone [email protected]:openstax/exchange.git')
if not _postgres_user_exists('ox_exchange'):
sudo('psql -d postgres -c "CREATE USER ox_exchange WITH CREATEDB PASSWORD \'ox_exchange\'"', user='postgres')
if not _postgres_db_exists('ox_exchange_dev'):
sudo('createdb -O ox_exchange ox_exchange_dev', user='postgres')
with cd('exchange'):
with prefix('source {}'.format(RVM)):
run('rvm install $(cat .ruby-version)')
run('rvm gemset create $(cat .ruby-gemset)')
run('rvm gemset use $(cat .ruby-gemset)')
run('bundle install --without production')
run('rake db:migrate')
run('rake db:seed')
def exchange_run():
"""Run openstax/exchange"""
with cd('exchange'):
with prefix('source {}'.format(RVM)):
# ctrl-c doesn't kill the rails server so the old server is still
# running
run('kill -9 `cat tmp/pids/server.pid`', warn_only=True)
run('rails server')
def exchange_test(test_case=None):
"""Run openstax/exchange tests"""
if _postgres_db_exists('ox_exchange_test'):
sudo('dropdb ox_exchange_test', user='postgres')
sudo('createdb -O ox_exchange ox_exchange_test', user='postgres')
with cd('exchange'):
with prefix('source {}'.format(RVM)):
if test_case:
run('rspec -b {}'.format(test_case))
else:
run('bundle install --without production')
run('rake db:migrate')
run('rake')
def openstax_utilities_setup(https=''):
"""Set up openstax/openstax_utilities"""
_setup()
if not fabric.contrib.files.exists('openstax_utilities'):
if https:
run('git clone https://github.com/openstax/openstax_utilities.git')
else:
run('git clone [email protected]:openstax/openstax_utilities.git')
with cd('openstax_utilities'):
with prefix('source {}'.format(RVM)):
run('rvm install $(cat .ruby-version)')
run('bundle install --without production')
run('rake db:setup')
def openstax_utilities_test():
"""Run openstax/openstax_utilities tests"""
with cd('openstax_utilities'):
with prefix('source {}'.format(RVM)):
run('rake')
def accounts_rails_setup(https=''):
"""Set up openstax/accounts-rails"""
_setup()
if not fabric.contrib.files.exists('accounts-rails'):
if https:
run('git clone https://github.com/openstax/accounts-rails.git')
else:
run('git clone [email protected]:openstax/accounts-rails.git')
with cd('accounts-rails'):
with prefix('source {}'.format(RVM)):
run('rvm install 2.2.1')
with prefix('rvm use 2.2.1'):
run('bundle install --without production')
run('rake db:setup')
def accounts_rails_test():
"""Run openstax/accounts-rails tests"""
with cd('accounts-rails'):
with prefix('source {}'.format(RVM)):
with prefix('rvm use 2.2.1'):
run('rake')