|
| 1 | +There are a number of issues and additional items that need to been done when deploying to Heroku (or other production environments.) |
| 2 | +Even if not deploying to Heroku these steps will cover most of the gotchas that you will encounter. |
| 3 | + |
| 4 | +If you do find any problems please log an issue, or better yet do a pull request on this page. |
| 5 | + |
| 6 | +1. **You need to use postgresql rather than sqlite or mysql.** You can find instructions on how to do this online, or better yet when you create your rails app, create it from the beginning with postgresql: https://www.digitalocean.com/community/tutorials/how-to-set-up-ruby-on-rails-with-postgres |
| 7 | + |
| 8 | +2. **Remove `app/models/application_record.rb`** This is no longer needed due to a recent rails fix, and confuses Heroku. |
| 9 | + |
| 10 | +3. **Use harmonly uglifier.** In config/environments/production.rb you need to change this line from: |
| 11 | +`config.assets.js_compressor = :uglifier` |
| 12 | +to |
| 13 | +`config.assets.js_compressor = Uglifier.new(harmony: true)` |
| 14 | + |
| 15 | +4. **Insure webpacker:compile occurs before assets:precompile:** at the end of the `Rakefile` (in the root directory) add this line: |
| 16 | +`Rake::Task["assets:precompile"].enhance(['yarn:install', 'webpacker:compile'])` |
| 17 | + |
| 18 | +5. **Setup your database** Make sure you run |
| 19 | +`Heroku run rake db:migrate` |
| 20 | + |
| 21 | +6. **Update your production policies** By default the Hyperstack installer will leave your Policies wide open but **not** in production. |
| 22 | +For a production app you will want to add restrictive Policies to protect your data. If you just want to get things working on Heroku you can remove the guard from the end of the `policies/application.rb` file. |
| 23 | + |
| 24 | +5. Add `stylesheet_pack_tag`s: Hyperstack does not automatically pull in the `.css` packs. Instead you have to add one or both these lines to your layouts, if you are requiring css assets in the pack files: |
| 25 | +`<%= stylesheet_pack_tag 'client_only' %>` |
| 26 | +If you are requiring css libraries in the `client_only.js` pack file |
| 27 | +and |
| 28 | +`<%= stylesheet_pack_tag 'client_and_server' %>` |
| 29 | + If you are requiring css libraries in the `client_and_server.js` pack file |
| 30 | + |
| 31 | +6. Setup ActionCable (see [full instructions](https://blog.Heroku.com/real_time_rails_implementing_websockets_in_rails_5_with_action_cable#deploying-our-application-to-Heroku) for details) |
| 32 | +provision Redis on Heroku `Heroku addons:add redistogo` |
| 33 | +then get the Heroku url: `Heroku config --app action-cable-example | grep REDISTOGO_URL` |
| 34 | +use the url in config/cable.yml (in the production section) |
| 35 | +in config/environments/production.rb add these two lines: |
| 36 | +`config.web_socket_server_url = "wss://your-app.Herokuapp.com/cable" ` |
| 37 | +`config.action_cable.allowed_request_origins = ['https://your-app.Herokuapp.com', 'http://action-your-app.Herokuapp.com']` |
| 38 | + |
| 39 | +### On Going Development |
| 40 | + |
| 41 | +After updating anything in the hyperstack initializer you will need to force Heroku to clear the cache: |
| 42 | + |
| 43 | +First install the Heroku-repo plugin (on your console) |
| 44 | +`$ Heroku plugins:install Heroku-repo` |
| 45 | + |
| 46 | +and then to clear the cache do: |
| 47 | + |
| 48 | +`$ Heroku repo:purge_cache -a appname` |
| 49 | +`$ git commit --allow-empty -m "Purge cache"` |
| 50 | +`$ git push Heroku master` |
0 commit comments