forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
312 lines (259 loc) · 8.21 KB
/
Rakefile
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
# Run 'rake' or 'rake -P' to get a list of valid Rake commands.
require_relative './deployment'
require 'os'
require 'cdo/hip_chat'
require 'cdo/rake_utils'
namespace :lint do
task :ruby do
RakeUtils.bundle_exec 'rubocop'
end
task :haml do
RakeUtils.bundle_exec 'haml-lint dashboard pegasus'
end
task :javascript do
Dir.chdir(apps_dir) do
# lint all js/jsx files in dashboardd/app/assets/javascript
RakeUtils.system 'grunt jshint:files --glob "../dashboard/app/**/*.js*(x)"'
# also do our standard apps lint
RakeUtils.system 'grunt jshint'
end
Dir.chdir(shared_js_dir) do
RakeUtils.system 'npm run lint'
end
end
task all: [:ruby, :haml, :javascript]
end
task lint: ['lint:all']
##################################################################################################
##
##
## build
##
##
##################################################################################################
namespace :build do
task :configure do
if CDO.chef_managed
HipChat.log 'Applying <b>chef</b> profile...'
RakeUtils.sudo 'chef-client'
end
unless CDO.chef_managed
Dir.chdir(aws_dir) do
HipChat.log 'Installing <b>aws</b> bundle...'
RakeUtils.bundle_install
end
end
end
task :blockly_core do
Dir.chdir(blockly_core_dir) do
RakeUtils.npm_install
HipChat.log 'Building <b>blockly-core</b> debug...'
RakeUtils.system './deploy.sh', 'debug'
HipChat.log 'Building <b>blockly-core</b>...'
RakeUtils.system './deploy.sh'
end
end
task :core_and_apps_dev do
Dir.chdir(blockly_core_dir) do
RakeUtils.system './deploy.sh', 'debug'
end
Dir.chdir(apps_dir) do
RakeUtils.system 'MOOC_DEV=1 grunt build'
end
end
task :apps do
Dir.chdir(apps_dir) do
HipChat.log 'Installing <b>apps</b> dependencies...'
RakeUtils.npm_install
if rack_env?(:staging)
HipChat.log 'Updating <b>apps</b> i18n strings...'
RakeUtils.system './sync-apps.sh'
end
HipChat.log 'Building <b>apps</b>...'
env_vars = ''
env_vars += 'MOOC_LOCALIZE=1 ' if CDO.localize_apps
env_vars += 'MOOC_DIGEST=1 ' unless rack_env?(:development)
RakeUtils.system "#{env_vars} grunt"
end
end
task :shared do
Dir.chdir(shared_js_dir) do
HipChat.log 'Installing <b>shared js</b> dependencies...'
RakeUtils.npm_install
HipChat.log 'Building <b>shared js</b>...'
RakeUtils.system 'npm run gulp'
end
end
task :stop_varnish do
Dir.chdir(aws_dir) do
unless rack_env?(:development) || (RakeUtils.system_('ps aux | grep -v grep | grep varnishd -q') != 0)
HipChat.log 'Stopping <b>varnish</b>...'
RakeUtils.stop_service 'varnish'
end
end
end
task :dashboard do
Dir.chdir(dashboard_dir) do
HipChat.log 'Stopping <b>dashboard</b>...'
RakeUtils.stop_service CDO.dashboard_unicorn_name unless rack_env?(:development)
HipChat.log 'Installing <b>dashboard</b> bundle...'
RakeUtils.bundle_install
if CDO.daemon
HipChat.log 'Migrating <b>dashboard</b> database...'
RakeUtils.rake 'db:migrate'
HipChat.log 'Seeding <b>dashboard</b>...'
RakeUtils.rake 'seed:all'
end
unless rack_env?(:development)
HipChat.log 'Precompiling <b>dashboard</b> assets...'
RakeUtils.rake 'assets:precompile'
end
HipChat.log 'Starting <b>dashboard</b>.'
RakeUtils.start_service CDO.dashboard_unicorn_name unless rack_env?(:development)
if rack_env?(:production)
RakeUtils.rake "honeybadger:deploy TO=#{rack_env} REVISION=`git rev-parse HEAD`"
end
end
end
task :pegasus do
Dir.chdir(pegasus_dir) do
HipChat.log 'Stopping <b>pegasus</b>...'
RakeUtils.stop_service CDO.pegasus_unicorn_name unless rack_env?(:development)
HipChat.log 'Installing <b>pegasus</b> bundle...'
RakeUtils.bundle_install
if CDO.daemon
HipChat.log 'Migrating <b>pegasus</b> database...'
begin
RakeUtils.rake 'db:migrate'
rescue => e
HipChat.log "/quote #{e.message}\n#{CDO.backtrace e}", message_format: 'text'
raise e
end
HipChat.log 'Seeding <b>pegasus</b>...'
begin
RakeUtils.rake 'seed:migrate'
rescue => e
HipChat.log "/quote #{e.message}\n#{CDO.backtrace e}", message_format: 'text'
raise e
end
end
if CDO.daemon && !rack_env?(:development)
HipChat.log 'Analyzing <b>pegasus</b> hour-of-code activity...'
RakeUtils.system deploy_dir('bin', 'analyze_hoc_activity')
end
HipChat.log 'Starting <b>pegasus</b>.'
RakeUtils.start_service CDO.pegasus_unicorn_name unless rack_env?(:development)
end
end
task :start_varnish do
Dir.chdir(aws_dir) do
unless rack_env?(:development) || (RakeUtils.system_('ps aux | grep -v grep | grep varnishd -q') == 0)
HipChat.log 'Starting <b>varnish</b>...'
RakeUtils.start_service 'varnish'
end
end
end
tasks = []
tasks << :configure
tasks << :blockly_core if CDO.build_blockly_core
tasks << :apps if CDO.build_apps
tasks << :shared if CDO.build_shared_js
tasks << :stop_varnish if CDO.build_dashboard || CDO.build_pegasus
tasks << :dashboard if CDO.build_dashboard
tasks << :pegasus if CDO.build_pegasus
tasks << :start_varnish if CDO.build_dashboard || CDO.build_pegasus
task :all => tasks
end
task :build => ['build:all']
##################################################################################################
##
##
## install
##
##
##################################################################################################
# Whether this is a development or adhoc environment where we should install npm and create
# a local database.
def local_environment?
(rack_env?(:development) && !CDO.chef_managed) || rack_env?(:adhoc)
end
def install_npm
if OS.linux?
RakeUtils.system 'sudo apt-get install -y nodejs npm'
RakeUtils.system 'sudo ln -s -f /usr/bin/nodejs /usr/bin/node'
RakeUtils.system 'sudo npm install -g [email protected]'
RakeUtils.npm_install_g 'grunt-cli'
elsif OS.mac?
RakeUtils.system 'brew install node'
RakeUtils.system 'npm', 'update', '-g', 'npm'
RakeUtils.system 'npm', 'install', '-g', 'grunt-cli'
end
end
namespace :install do
# Create a symlink in the public directory that points at the appropriate blockly
# code (either the static blockly or the built version, depending on CDO.use_my_apps).
task :blockly_symlink do
if rack_env?(:development) && !CDO.chef_managed
Dir.chdir(apps_dir) do
apps_build = CDO.use_my_apps ? apps_dir('build/package') : 'apps-package'
RakeUtils.ln_s apps_build, dashboard_dir('public','blockly')
end
end
end
task :hooks do
files = [
'pre-commit',
'post-checkout',
'post-merge',
]
git_path = ".git/hooks"
files.each do |f|
path = File.expand_path("../tools/hooks/#{f}", __FILE__)
system "ln -s #{path} #{git_path}/#{f}"
end
end
task :apps do
if local_environment?
install_npm
end
end
task :shared do
if local_environment?
Dir.chdir(shared_js_dir) do
shared_js_build = CDO.use_my_shared_js ? shared_js_dir('build/package') : 'shared-package'
RakeUtils.ln_s shared_js_build, dashboard_dir('public','shared')
end
install_npm
end
end
task :dashboard do
if local_environment?
Dir.chdir(dashboard_dir) do
RakeUtils.bundle_install
puts CDO.dashboard_db_writer
RakeUtils.rake 'dashboard:setup_db'
end
end
end
task :pegasus do
if local_environment?
Dir.chdir(pegasus_dir) do
RakeUtils.bundle_install
RakeUtils.rake 'pegasus:setup_db'
end
end
end
tasks = []
#tasks << :blockly_core if CDO.build_blockly_core
tasks << :blockly_symlink
tasks << :apps if CDO.build_apps
tasks << :shared if CDO.build_shared_js
tasks << :dashboard if CDO.build_dashboard
tasks << :pegasus if CDO.build_pegasus
task :all => tasks
end
task :install => ['install:all']
task :default do
puts 'List of valid commands:'
system 'rake -P'
end