This repository was archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfabfile.py
112 lines (90 loc) · 3.66 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
import os
from fabric.api import settings, run, env, cd, puts, abort
from fabric.contrib import files
from braid import git, cron, pip, archive, config
from braid.twisted import service
from braid.tasks import addTasks
from braid.utils import confirm
__all__ = ['config']
class Buildbot(service.Service):
def task_install(self):
"""
Install buildbot.
"""
self.bootstrap()
with settings(user=self.serviceUser):
pip.install('sqlalchemy==0.7.10')
self.update(_installDeps=True)
run('/bin/ln -nsf {}/start {}/start'.format(self.configDir, self.binDir))
run('/bin/mkdir -p ~/data')
run('/bin/mkdir -p ~/data/build_products')
run('/bin/ln -nsf ~/data/build_products {}/master/public_html/builds'.format(self.configDir))
# TODO: install dependencies
if env.get('installTestData'):
self.task_installTestData()
cron.install(self.serviceUser, '{}/crontab'.format(self.configDir))
def task_installTestData(self, force=None):
"""
Do test environment setup (with fake passwords, etc).
"""
if env.get('environment') == 'production':
abort("Don't use testInit in production.")
with settings(user=self.serviceUser), cd(os.path.join(self.configDir, 'master')):
if force or not files.exists('private.py'):
puts('Using sample private.py')
run('/bin/cp private.py.sample private.py')
if force or not files.exists('state.sqlite'):
run('~/.local/bin/buildbot upgrade-master')
def task_updatePrivateData(self):
"""
Update private config.
"""
with settings(user=self.serviceUser):
git.branch(
'[email protected]:/git/buildbot-secrets',
'~/private')
def update(self, _installDeps=False):
"""
Update
"""
with settings(user=self.serviceUser):
git.branch('https://github.com/twisted-infra/twisted-buildbot-configuration', self.configDir)
buildbotSource = os.path.join(self.configDir, 'buildbot-source')
git.branch('https://github.com/twisted-infra/buildbot', buildbotSource)
if _installDeps:
pip.install('{}'.format(os.path.join(buildbotSource, 'master')),
python='python')
else:
pip.install('--no-deps --upgrade {}'.format(os.path.join(buildbotSource, 'master')),
python='python')
if env.get('installPrivateData'):
self.task_updatePrivateData()
def task_update(self):
"""
Update config and restart.
"""
self.update()
self.task_restart()
def task_dump(self, localfile):
"""
Create a tarball containing all information not currently stored in
version control and download it to the given C{localfile}.
"""
with settings(user=self.serviceUser):
archive.dump({
'data': 'data',
}, localfile, exclude=[
'http.log*',
])
def task_restore(self, localfile):
"""
Restore all information not stored in version control from a tarball
on the invoking users machine.
"""
msg = 'The whole data directory will be replaced with the backup.'
if confirm(msg):
with settings(user=self.serviceUser):
archive.restore({
'data': 'data',
}, localfile)
addTasks(globals(), Buildbot('bb-master').getTasks())