forked from pebble/cloudpebble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
177 lines (134 loc) · 4.85 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
# WARNING: This file is extremely specific to how Katharine happens to have her
# local machines set up.
# In particular, to run without modification, you will need:
# - An EC2 keypair in ~/Downloads/katharine-keypair.pem
# - A keypair for the ycmd servers in ~/.ssh/id_rsa
# - The tintin source tree in ~/projects/tintin
# - With an appropriate python virtualenv in .env/
# - A clone of qemu-tintin-images in ~/projects/qemu-tintin-images
# - Access to the cloudpebble heroku app
from fabric.api import *
from fabric.tasks import execute
import os
PROJECTS_PATH = env.get('pebble_projects_path', '~/projects')
def get_project_path(name):
return os.path.join(PROJECTS_PATH, name)
env.roledefs = {
'qemu': ['[email protected]', '[email protected]'],
'ycmd': ['[email protected]', '[email protected]',
'[email protected]', '[email protected]',],
}
# This needs to stay commented out for anyone except Katharine to use the script
# env.key_filename = ['~/.ssh/id_rsa', '~/Downloads/katharine-keypair.pem']
@task
@roles('qemu')
@parallel
def update_qemu_service():
with cd("cloudpebble-qemu-controller"):
run("git pull")
run("git submodule update --init --recursive")
with prefix(". .env/bin/activate"):
run("pip install -r requirements.txt")
sudo("restart cloudpebble-qemu")
@task
@roles('qemu')
@parallel
def update_qemu_sdk():
with cd('qemu'):
run("git pull")
# This is currently the last qemu commit which works with CloudPebble
run("git checkout 01b08e22cfc7c1e08d5087d669a5a2f4703d5a20")
run("make -j8")
with cd("qemu-tintin-images"):
run("git pull")
with cd("pypkjs"):
run("git pull")
run("git submodule update --init --recursive")
with prefix(". .env/bin/activate"):
run("pip install -r requirements.txt")
@task
@roles('qemu')
@parallel
def restart_qemu_service():
sudo("restart cloudpebble-qemu")
@task
@roles('ycmd')
@parallel
def update_ycmd_sdk(sdk_version):
with cd("/home/ycm"), settings(sudo_user="ycm", shell="/bin/bash -c"):
sudo("wget -nv -O sdk.tar.gz https://s3.amazonaws.com/assets.getpebble.com/sdk3/release/sdk-core-%s.tar.bz2" % sdk_version)
sudo("tar -xf sdk.tar.gz")
sudo("rm -rf sdk3")
sudo("mv sdk-core sdk3")
@task
@roles('ycmd')
@parallel
def update_ycmd_service():
with cd("/home/ycm/proxy"), settings(sudo_user="ycm", shell="/bin/bash -c"):
sudo("git pull")
run("pip install --upgrade -r requirements.txt")
run("restart ycmd-proxy")
@task
@roles('ycmd')
@parallel
def restart_ycmd_service():
run("restart ycmd-proxy")
@task
def deploy_heroku():
local("git push heroku master")
@task
def restart_heroku():
local("heroku restart -a cloudpebble")
@task
def update_all_services():
execute(update_qemu_service)
execute(update_ycmd_service)
execute(deploy_heroku)
@task
def restart_everything():
execute(restart_qemu_service)
execute(restart_ycmd_service)
execute(restart_heroku)
def build_qemu_image(board, platform):
with lcd(get_project_path("tintin")):
with prefix(". .env/bin/activate"):
local("python ./waf configure --board={} --qemu --release --sdkshell build qemu_image_spi qemu_image_micro".format(board))
local("cp build/qemu_* {}".format(os.path.join(get_project_path('qemu-tintin-images'), platform, "3.0")))
@task
@runs_once
def update_qemu_images(sdk_version):
# Merge conflicts are no fun.
with lcd(get_project_path("qemu-tintin-images")):
local("git pull")
with lcd(get_project_path("tintin")):
local("git checkout v%s" % sdk_version)
# build_qemu_image("bb2", "aplite")
build_qemu_image("snowy_bb2", "basalt")
build_qemu_image("spalding_bb2", "chalk")
build_qemu_image("silk_bb", "diorite")
build_qemu_image("robert_bb", "emery")
with lcd(get_project_path("qemu-tintin-images")):
local("git commit -a -m 'Update to v%s'" % sdk_version)
local("git push")
@task
@runs_once
def update_cloudpebble_sdk(sdk_version):
local("sed -i.bak 's/sdk-core-3.[a-z0-9-]*\.tar\.bz2/sdk-core-%s.tar.bz2/' bin/post_compile bootstrap.sh" % sdk_version)
local("git add bin/post_compile bootstrap.sh")
local("git commit -m 'Update to v%s'" % sdk_version)
local("git push")
execute(deploy_heroku)
@task
def update_sdk(sdk_version):
execute(update_qemu_images, sdk_version)
execute(update_qemu_sdk)
execute(update_ycmd_sdk, sdk_version)
execute(update_cloudpebble_sdk, sdk_version)
@task
def update_all(sdk_version):
execute(update_qemu_images, sdk_version)
execute(update_qemu_sdk)
execute(update_qemu_service)
execute(update_ycmd_sdk, sdk_version)
execute(update_ycmd_service)
execute(update_cloudpebble_sdk, sdk_version)