Няма описание http://j1x-huginn.herokuapp.com

setup_heroku 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/usr/bin/env ruby
  2. require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'setup_tools'))
  3. include SetupTools
  4. unless `which heroku` =~ /heroku/
  5. puts "It looks like the heroku command line tool hasn't been installed yet. Please install"
  6. puts "the Heroku Toolbelt from https://toolbelt.heroku.com, run 'heroku auth:login', and then"
  7. puts "run this script again."
  8. exit 1
  9. end
  10. def grab_heroku_config!
  11. grab_config_with_cmd!("heroku config -s", no_stderr: true)
  12. end
  13. def set_env(key, value)
  14. capture("heroku config:set #{key}=#{value}")
  15. end
  16. def check_login!
  17. unless File.exists?(File.expand_path("~/.netrc")) && File.read(File.expand_path("~/.netrc")) =~ /heroku/
  18. puts "It looks like you need to log in to Heroku. Please run 'heroku auth:login' before continuing."
  19. exit 1
  20. end
  21. puts "Welcome #{`heroku auth:whoami`.strip}! It looks like you're logged into Heroku."
  22. puts
  23. end
  24. check_login!
  25. info = capture("heroku info")
  26. if info =~ /No app specified/i
  27. puts "It looks like you don't have a Heroku app set up yet for this repo."
  28. puts "You can either exit now and run 'heroku create', or I can do it for you."
  29. if yes?("Would you like me to create a Heroku app for you now in this repo?")
  30. puts `heroku create`
  31. info = capture("heroku info")
  32. else
  33. puts "Okay, exiting so you can do it."
  34. exit 0
  35. end
  36. end
  37. if (root_id = `git rev-list --max-parents=0 HEAD`.chomp) != '620acffa5a302c6a27165d3214cf3da6be6c1d0d'
  38. if (`git remote`.split - %w[heroku]).empty?
  39. puts "You don't seem to have cantino/huginn set up as upstream repository."
  40. if yes?("Would you like me to set this working tree up for you?")
  41. if system('git remote add origin https://github.com/cantino/huginn.git') &&
  42. system('git remote update origin')
  43. rebase_command = "git rebase #{root_id} --onto origin/master"
  44. if system(rebase_command)
  45. puts "Done!"
  46. else
  47. system('git rebase --abort')
  48. puts "Rebasing your working tree onto the upstream master failed."
  49. puts "Please run the following command and merge your local changes by yourself."
  50. puts "\t#{rebase_command}"
  51. exit 1
  52. end
  53. else
  54. exit 1
  55. end
  56. end
  57. end
  58. end
  59. app_name = info.scan(/http:\/\/([\w\d-]+)\.herokuapp\.com/).flatten.first
  60. confirm_app_name app_name
  61. grab_heroku_config!
  62. print_config
  63. set_defaults!
  64. unless $config['DOMAIN']
  65. set_value 'DOMAIN', "#{app_name}.herokuapp.com", force: false
  66. first_time = true
  67. end
  68. set_value 'BUILDPACK_URL', "https://github.com/ddollar/heroku-buildpack-multi.git"
  69. set_value 'PROCFILE_PATH', "deployment/heroku/Procfile.heroku", force: false
  70. set_value 'ON_HEROKU', "true"
  71. unless $config['SMTP_DOMAIN'] && $config['SMTP_USER_NAME'] && $config['SMTP_PASSWORD'] && $config['SMTP_SERVER'] && $config['EMAIL_FROM_ADDRESS']
  72. puts "Okay, let's setup outgoing email settings. The simplest solution is to use the free sendgrid Heroku addon."
  73. puts "If you'd like to use your own server, or your Gmail account, please see .env.example and set"
  74. puts "SMTP_DOMAIN, SMTP_USER_NAME, SMTP_PASSWORD, and SMTP_SERVER with 'heroku config:set'."
  75. if yes?("Should I enable the free sendgrid addon?")
  76. puts capture("heroku addons:add sendgrid")
  77. set_value 'SMTP_SERVER', "smtp.sendgrid.net", silent: true
  78. set_value 'SMTP_DOMAIN', "heroku.com", silent: true
  79. grab_heroku_config!
  80. set_value 'SMTP_USER_NAME', $config['SENDGRID_USERNAME'], silent: true
  81. set_value 'SMTP_PASSWORD', $config['SENDGRID_PASSWORD'], silent: true
  82. else
  83. puts "Okay, you'll need to set SMTP_DOMAIN, SMTP_USER_NAME, SMTP_PASSWORD, and SMTP_SERVER with 'heroku config:set' manually."
  84. end
  85. unless $config['EMAIL_FROM_ADDRESS']
  86. email = nag("What email address would you like email to appear to be sent from?")
  87. set_value 'EMAIL_FROM_ADDRESS', email
  88. end
  89. end
  90. branch = capture("git rev-parse --abbrev-ref HEAD")
  91. if yes?("Should I push your current branch (#{branch}) to heroku?")
  92. puts "This may take a moment..."
  93. puts capture("git push heroku #{branch}:master -f")
  94. puts "Running database migrations..."
  95. puts capture("heroku run rake db:migrate")
  96. end
  97. if first_time
  98. puts "Restarting..."
  99. puts capture("heroku restart")
  100. puts "Done!"
  101. puts
  102. puts
  103. puts "I can make an admin user on your new Huginn instance and setup some example Agents."
  104. if yes?("Should I create a new admin user and some example Agents?")
  105. done = false
  106. while !done
  107. seed_email = nag "Okay, what is your email address?"
  108. seed_username = nag "And what username would you like to login as?"
  109. seed_password = nag "Finally, what password would you like to use?", noecho: true
  110. puts "\nJust a moment..."
  111. result = capture("heroku run rake db:seed SEED_EMAIL=#{seed_email} SEED_USERNAME=#{seed_username} SEED_PASSWORD=#{seed_password}")
  112. if result =~ /Validation failed/
  113. puts "ERROR:"
  114. puts
  115. puts result
  116. puts
  117. else
  118. done = true
  119. end
  120. end
  121. puts
  122. puts
  123. puts "Okay, you should be all set! Visit https://#{app_name}.herokuapp.com and login as '#{seed_username}' with your password."
  124. puts
  125. puts "If you'd like to make more users, you can visit https://#{app_name}.herokuapp.com/users/sign_up and use the invitation code:"
  126. else
  127. puts
  128. puts "Visit https://#{app_name}.herokuapp.com/users/sign_up and use the invitation code shown below:"
  129. end
  130. puts
  131. puts "\t#{$config['INVITATION_CODE']}"
  132. end
  133. puts
  134. puts "Done!"