1
0
Эх сурвалжийг харах

Merge pull request #464 from knu/heroku_button

Add a "Deploy to Heroku" button.
Akinori MUSHA 10 жил өмнө
parent
commit
3afd215457

+ 2 - 0
README.md

@@ -71,6 +71,8 @@ If you need more detailed instructions, see the [Novice setup guide][novice-setu
 
 ## Deployment
 
+[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
+
 Huginn can run on Heroku for free!  Please see [the Huginn Wiki](https://github.com/cantino/huginn/wiki#deploying-huginn) for detailed deployment strategies for different providers.
 
 ### Optional Setup

+ 23 - 0
app.json

@@ -0,0 +1,23 @@
+{
+    "name": "Huginn",
+    "description": "Build agents that monitor and act on your behalf.  Your agents are standing by!",
+    "website": "https://github.com/cantino/huginn",
+    "repository": "https://github.com/cantino/huginn",
+    "env": {
+        "BUILDPACK_URL": "https://github.com/ddollar/heroku-buildpack-multi.git",
+        "APP_SECRET_TOKEN": {
+            "generator": "secret"
+        },
+        "PROCFILE_PATH": "deployment/heroku/Procfile.heroku",
+        "ON_HEROKU": "true",
+        "FORCE_SSL": "true",
+        "INVITATION_CODE": {
+            "generator": "secret"
+        },
+        "USE_GRAPHVIZ_DOT": "dot"
+    },
+    "scripts": {
+      "postdeploy": "bundle exec rake db:migrate"
+    },
+    "success_url": "/users/sign_up"
+}

+ 31 - 0
app/assets/stylesheets/application.css.scss.erb

@@ -117,6 +117,37 @@ span.not-applicable:after {
   }
 }
 
+// Heroku
+
+.heroku-instructions {
+  color: rgba(255, 255, 255, 0.9);
+  background-color: rgba(132, 132, 196, 0.8);
+  border: 3px solid rgba(132, 132, 196, 0.5);
+  -webkit-border-radius: 4px;
+     -moz-border-radius: 4px;
+          border-radius: 4px;
+  padding: 12px;
+  margin-bottom: 10px;
+
+  a {
+    text-decoration: underline;
+  }
+
+  a:link {
+    color: inherit;
+  }
+
+  a:hover, a:visited, a:active {
+    color: #fff;
+  }
+
+  pre {
+    background-color: #ffffff;
+    color: #3F3F44;
+    margin: 4px;
+  }
+}
+
 // Logs
 
 #logs .action-icon {

+ 22 - 0
app/views/devise/registrations/new.html.erb

@@ -7,6 +7,28 @@
 
         <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :class => 'form-horizontal' }) do |f| %>
           <%= devise_error_messages! %>
+          <% if ENV['ON_HEROKU'] && User.count.zero? %>
+          <div class="heroku-instructions">
+            <% app_name = request.host[/\A[^.]+/] %>
+            <p>If you are the owner of this application, take the following steps to complete the setup:</p>
+
+            <ul>
+              <li>Read <a href="https://github.com/cantino/huginn/wiki/Run-Huginn-for-free-on-Heroku" target="_target">this document</a> carefully if you are going to try out Huginn for free on <a href="https://id.heroku.com/" target="_target">Heroku</a>.</li>
+
+              <li>Install the <a href="https://toolbelt.heroku.com/" target="_target">Heroku Toolbelt</a> and run <kbd>heroku login</kbd> if you haven't already.</li>
+
+              <li>Run the following commands:<br />
+                <%= content_tag :pre do -%>
+heroku git:clone <%= content_tag :var, app_name %>
+cd <%= content_tag :var, app_name %>
+bundle
+bin/setup_heroku
+<%- end %>
+
+              <li>Get back to this page and sign up with the invitation code shown by the last command.</li>
+            </ul>
+          </div>
+          <% end %>
 
           <div class="form-group">
             <%= f.label :invitation_code, :class => 'col-md-4 control-label' %>

+ 20 - 2
bin/setup_heroku

@@ -48,6 +48,7 @@ def set_value(key, value, options = {})
   if $config[key].nil? || $config[key] == '' || ($config[key] != value && options[:force] != false)
     puts "Setting #{key} to #{value}" unless options[:silent]
     puts capture("heroku config:set #{key}=#{value}")
+    $config[key] = value
   end
 end
 
@@ -94,11 +95,15 @@ unless $config['APP_SECRET_TOKEN']
   puts capture("heroku config:set APP_SECRET_TOKEN=`rake secret`")
 end
 
+unless $config['DOMAIN']
+  set_value 'DOMAIN', "#{app_name}.herokuapp.com", force: false
+  first_time = true
+end
+
 set_value 'BUILDPACK_URL', "https://github.com/ddollar/heroku-buildpack-multi.git"
 set_value 'PROCFILE_PATH', "deployment/heroku/Procfile.heroku", force: false
 set_value 'ON_HEROKU', "true"
 set_value 'FORCE_SSL', "true"
-set_value 'DOMAIN', "#{app_name}.herokuapp.com", force: false
 set_value 'USE_GRAPHVIZ_DOT', 'dot'
 
 unless $config['INVITATION_CODE']
@@ -133,6 +138,19 @@ unless $config['SMTP_DOMAIN'] && $config['SMTP_USER_NAME'] && $config['SMTP_PASS
   end
 end
 
+if first_time
+  puts "Restarting..."
+  puts capture("heroku restart")
+
+  puts "Done!"
+  puts
+  puts "Visit https://#{app_name}.herokuapp.com/users/sign_up and use the invitation code shown below:"
+  puts
+  puts "\t#{$config['INVITATION_CODE']}"
+
+  exit
+end
+
 branch = capture("git rev-parse --abbrev-ref HEAD")
 if yes?("Should I push your current branch (#{branch}) to heroku?")
   puts "This may take a moment..."
@@ -158,4 +176,4 @@ if yes?("Should I push your current branch (#{branch}) to heroku?")
 end
 
 puts
-puts "Done!"
+puts "Done!"