fanforce-app-factory 2.0.0.rc36 → 2.0.0.rc37
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fanforce/app_factory/cli/lib/env.rb +1 -1
- data/lib/fanforce/app_factory/cli/lib/heroku.rb +66 -48
- data/lib/fanforce/app_factory/cli/scripts/destroy.rb +11 -13
- data/lib/fanforce/app_factory/cli/scripts/push.rb +6 -12
- data/lib/fanforce/app_factory/cli/scripts/restart.rb +1 -7
- data/lib/fanforce/app_factory/version.rb +1 -1
- metadata +1 -1
@@ -36,7 +36,7 @@ class Fanforce::AppFactory::CLI::Env
|
|
36
36
|
File.open("#{app.dir}/.appenv", 'w') {|f| f.write convert_hash_to_shell_env(vars) }
|
37
37
|
else
|
38
38
|
error 'could not find heroku in .fanforce-app-factory' if config[:heroku][environment].blank?
|
39
|
-
Fanforce::AppFactory::CLI::Heroku.new(app).update_config(
|
39
|
+
Fanforce::AppFactory::CLI::Heroku.new(app, environment).update_config(vars)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -1,94 +1,112 @@
|
|
1
1
|
class Fanforce::AppFactory::CLI::Heroku
|
2
2
|
include Fanforce::AppFactory::CLI::Utils
|
3
3
|
|
4
|
-
attr_reader :app
|
4
|
+
attr_reader :app, :environment
|
5
5
|
|
6
6
|
require_gem 'heroku-api', 'heroku-api'
|
7
7
|
|
8
|
-
def initialize(app)
|
8
|
+
def initialize(app, environment)
|
9
9
|
@app = app
|
10
|
+
@environment = environment.to_sym
|
10
11
|
end
|
11
12
|
|
12
|
-
def heroku
|
13
|
-
@heroku ||=
|
14
|
-
@heroku[environment] ||= Heroku::API.new(:username => config[:heroku][environment][:user], :password => config[:heroku][environment][:password])
|
13
|
+
def heroku
|
14
|
+
@heroku ||= Heroku::API.new(:username => config[:heroku][environment][:user], :password => config[:heroku][environment][:password])
|
15
15
|
rescue Exception => e
|
16
16
|
error "OOPS... #{environment.to_s.upcase}".format(:red,:bold) + ' has not been setup for Heroku' if config[:heroku].blank? or config[:heroku][environment].blank?
|
17
17
|
#raise "Heroku user #{config[:heroku][environment][:user]} does not seem to exist: #{e.message}" if e.response.status == 404
|
18
18
|
raise
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
heroku_app_name = app_name(environment)
|
21
|
+
def ensure_git_remote_exists
|
22
|
+
remote_name = "#{env}-heroku"
|
23
|
+
remote_url = "git@#{config[:heroku][environment][:git_ssh_domain] || 'heroku.com'}:#{app_name}.git"
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
puts "#{'Added '.format(:green,:bold)}" + "#{domain} domain to #{environment}"
|
34
|
-
end
|
35
|
-
|
36
|
-
# Setup default short domain
|
37
|
-
domain = "#{app._id}.#{Fanforce::Base::DomainEnvironments.method(environment).call[:default_short_domain]}"
|
38
|
-
domain_found = heroku.get_domains(heroku_app_name).body.inject(false) {|result, d| d['domain'] == domain ? (break true) : false }
|
39
|
-
if domain_found
|
40
|
-
puts "#{'Found '.format(:green,:bold)}" + "#{domain} domain on #{environment}"
|
41
|
-
else
|
42
|
-
heroku.post_domain(heroku_app_name, domain)
|
43
|
-
puts "#{'Added '.format(:green,:bold)}" + "#{domain} domain to #{environment}"
|
25
|
+
found_remote = false
|
26
|
+
found_valid_remote = false
|
27
|
+
(`git remote -v`).lines do |line|
|
28
|
+
next if line !~ Regexp.new("^#{remote_name}[\s\t]")
|
29
|
+
found_remote = true
|
30
|
+
found_valid_remote = true if line.include?(remote_url)
|
31
|
+
break
|
44
32
|
end
|
45
33
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
34
|
+
if found_valid_remote
|
35
|
+
return log "#{'Found '.format(:green,:bold)}" + "git remote for #{remote_name}"
|
36
|
+
elsif found_remote
|
37
|
+
log "#{'Updated '.format(:green,:bold)}" + "git remote for #{remote_name}"
|
50
38
|
`git remote rm #{remote_name}`
|
51
39
|
else
|
52
|
-
|
40
|
+
log "#{'Created '.format(:green,:bold)}" + "git remote for #{remote_name}"
|
53
41
|
end
|
54
|
-
`git remote add #{remote_name}
|
42
|
+
`git remote add #{remote_name} #{remote_url}`
|
43
|
+
end
|
44
|
+
|
45
|
+
def git_remote_name
|
46
|
+
"#{env}-heroku"
|
47
|
+
end
|
48
|
+
|
49
|
+
def restart
|
50
|
+
heroku.post_ps_restart(app_name)
|
55
51
|
end
|
56
52
|
|
57
|
-
def
|
53
|
+
def destroy
|
54
|
+
heroku.delete_app(app_name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def app_exists?
|
58
58
|
heroku.get_app(app_name)
|
59
59
|
return true
|
60
60
|
rescue
|
61
61
|
return false
|
62
62
|
end
|
63
63
|
|
64
|
-
def ensure_app_exists
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
def ensure_app_exists
|
65
|
+
return puts "#{'Found '.format(:green,:bold)}" + "#{environment} app on heroku (#{app_name})" if app_exists?
|
66
|
+
create_app
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_app
|
70
|
+
heroku.post_app(name: app_name)
|
71
|
+
puts "#{'Created '.format(:green,:bold)}" + "#{environment} on heroku (#{app_name})"
|
72
|
+
|
73
|
+
# Setup standard app domain
|
74
|
+
domain = "#{app._id}.#{Fanforce::Base::DomainEnvironments.method(environment).call[:apps_base]}"
|
75
|
+
domain_found = heroku.get_domains(app_name).body.inject(false) {|result, d| d['domain'] == domain ? (break true) : false }
|
76
|
+
if domain_found
|
77
|
+
puts "#{'Found '.format(:green,:bold)}" + "#{domain} domain on #{environment}"
|
78
|
+
else
|
79
|
+
heroku.post_domain(app_name, domain)
|
80
|
+
puts "#{'Added '.format(:green,:bold)}" + "#{domain} domain to #{environment}"
|
81
|
+
end
|
82
|
+
|
83
|
+
# Setup default short domain
|
84
|
+
domain = "#{app._id}.#{Fanforce::Base::DomainEnvironments.method(environment).call[:default_short_domain]}"
|
85
|
+
domain_found = heroku.get_domains(app_name).body.inject(false) {|result, d| d['domain'] == domain ? (break true) : false }
|
86
|
+
if domain_found
|
87
|
+
puts "#{'Found '.format(:green,:bold)}" + "#{domain} domain on #{environment}"
|
69
88
|
else
|
70
|
-
heroku.
|
71
|
-
puts "#{'
|
89
|
+
heroku.post_domain(app_name, domain)
|
90
|
+
puts "#{'Added '.format(:green,:bold)}" + "#{domain} domain to #{environment}"
|
72
91
|
end
|
73
92
|
end
|
74
93
|
|
75
|
-
def update_config(
|
76
|
-
heroku
|
94
|
+
def update_config(vars)
|
95
|
+
heroku.put_config_vars(app_name, vars) if vars
|
77
96
|
end
|
78
97
|
|
79
|
-
def env
|
98
|
+
def env
|
80
99
|
case environment
|
81
100
|
when :staging then env = :stg
|
82
101
|
when :production then env = :prd
|
83
102
|
end
|
84
103
|
end
|
85
104
|
|
86
|
-
def app_name
|
87
|
-
environment = environment.to_sym
|
105
|
+
def app_name
|
88
106
|
raise 'unknown environment' if ![:production, :staging].include?(environment)
|
89
107
|
|
90
|
-
|
91
|
-
|
108
|
+
app_name = app._id.length > 22 ? app._id.gsub(/(a|e|i|o|u)/, '') : app._id
|
109
|
+
"#{env}-app-#{app_name}"
|
92
110
|
end
|
93
111
|
|
94
112
|
end
|
@@ -18,19 +18,17 @@ class Fanforce::AppFactory::CLI::Scripts
|
|
18
18
|
log divider '+-----'
|
19
19
|
confirm("You are about to delete both local and remote files for #{app_id}.\nARE YOU SURE?", true)
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
# end
|
33
|
-
# end
|
21
|
+
log divider '+-----------------------------------------------------------------------------------------------------'
|
22
|
+
log 'DELETING HEROKU APPS...'
|
23
|
+
[:staging,:production].each do |environment|
|
24
|
+
heroku = Fanforce::AppFactory::CLI::Heroku.new(app, environment)
|
25
|
+
if heroku.app_exists?
|
26
|
+
heroku.destroy
|
27
|
+
log "#{'Removed '.format(:green,:bold)}" + " #{heroku.app_name}"
|
28
|
+
else
|
29
|
+
log "#{'Already Removed'.format(:green,:bold)}" + " #{heroku.app_name}"
|
30
|
+
end
|
31
|
+
end
|
34
32
|
|
35
33
|
log divider '+-----------------------------------------------------------------------------------------------------'
|
36
34
|
log 'REMOVING BITBUCKET REPOSITORY...'
|
@@ -35,8 +35,8 @@ class Fanforce::AppFactory::CLI::Scripts
|
|
35
35
|
end
|
36
36
|
|
37
37
|
if [:all,:heroku].include?(command) and environment != :development
|
38
|
-
heroku = Fanforce::AppFactory::CLI::Heroku.new(app)
|
39
|
-
heroku.ensure_app_exists
|
38
|
+
heroku = Fanforce::AppFactory::CLI::Heroku.new(app, environment)
|
39
|
+
heroku.ensure_app_exists
|
40
40
|
end
|
41
41
|
|
42
42
|
if [:all,:iron].include?(command)
|
@@ -69,20 +69,14 @@ class Fanforce::AppFactory::CLI::Scripts
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def push_heroku(heroku, app, environment)
|
72
|
-
|
73
|
-
when :staging then env = :stg
|
74
|
-
when :production then env = :prd
|
75
|
-
end
|
76
|
-
remote_name = "#{env}-heroku"
|
77
|
-
|
78
|
-
heroku.setup(environment) if !(`git remote`).split(/\r?\n/).include?(remote_name)
|
72
|
+
heroku.ensure_git_remote_exists
|
79
73
|
|
80
74
|
vars = Fanforce::AppFactory::CLI::Env.new(app).vars(environment)
|
81
|
-
heroku.update_config(
|
75
|
+
heroku.update_config(vars)
|
82
76
|
log 'Updated ENV'.format(:green,:bold) + " on Heroku #{environment.to_s.titleize} (#{vars.size} variables)..."
|
83
77
|
|
84
|
-
puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Heroku #{environment.to_s.titleize} (#{
|
85
|
-
console_command("git push #{
|
78
|
+
puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Heroku #{environment.to_s.titleize} (#{heroku.git_remote_name})..."
|
79
|
+
console_command("git push #{heroku.git_remote_name} master", true)
|
86
80
|
end
|
87
81
|
|
88
82
|
end
|
@@ -25,13 +25,7 @@ class Fanforce::AppFactory::CLI::Scripts
|
|
25
25
|
FileUtils.mkdir("#{app.dir}/tmp") if !File.directory?("#{app.dir}/tmp")
|
26
26
|
FileUtils.touch("#{app.dir}/tmp/restart.txt")
|
27
27
|
elsif [:production, :staging].include?(environment)
|
28
|
-
|
29
|
-
if config[:heroku].blank? or config[:heroku][environment].blank?
|
30
|
-
puts "#{'OOPS...'.format(:red,:bold)} #{environment} has not been setup on heroku"
|
31
|
-
next
|
32
|
-
end
|
33
|
-
heroku = auth_heroku(environment)
|
34
|
-
heroku.post_ps_restart get_heroku_app_name(app, environment)
|
28
|
+
Fanforce::AppFactory::CLI::Heroku.new(app, environment).restart
|
35
29
|
end
|
36
30
|
log "#{"Restarted #{environment}".format(:bold,:green)} #{app.dir_name}"
|
37
31
|
end
|