-
Notifications
You must be signed in to change notification settings - Fork 15
/
Rakefile
80 lines (66 loc) · 1.98 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
require "rake"
desc "run application"
task :run do
pids = [
spawn("cd backend && bundle install && foreman start -f Procfile.local"),
spawn("cd frontend && rm -rfd ./dist && ./node_modules/.bin/ember serve --port 4300")
]
trap "INT" do
Process.kill "INT", *pids
exit 1
end
pids.each do |pid|
Process.wait pid
end
end
{production: "flaredown", staging: "flaredown-staging"}.each do |env, application|
namespace env.to_sym do
desc "restart application"
task :restart do
log "Restart #{application}"
restart "#{application}-api"
end
desc "deploy application"
task :deploy do
Rake::Task["#{env}:deploy:backend"].invoke
Rake::Task["#{env}:deploy:frontend"].invoke
end
namespace :deploy do
desc "deploy frontend application"
task :frontend do
log "Deploy frontend #{application} with revision: #{revision}"
deploy_to "git@heroku.com:#{application}-webapp.git", "frontend"
end
desc "deploy backend application"
task :backend do
log "Deploy backend #{application} with revision: #{revision}"
deploy_to "git@heroku.com:#{application}-api.git", "backend"
migrate "#{application}-api"
end
end
desc "setup application"
task :setup do
system("heroku pg:reset DATABASE --app #{application}-api --confirm #{application}-api")
system("heroku run rake app:setup --app #{application}-api")
end
desc "invite user to join into application"
task :invite do
system("heroku run rake app:invite --app #{application}-api")
end
end
end
def deploy_to(remote, subtree)
system("git push #{remote} `git subtree split --prefix #{subtree} #{revision}`:master --force")
end
def migrate(application)
system("heroku run rake db:migrate --app #{application}")
end
def restart(application)
system("heroku restart --app #{application}")
end
def revision
ENV.fetch("REVISION") { "master" }
end
def log(message)
puts ">>> #{message}"
end