Ask A Question

Notifications

You’re not receiving notifications from this thread.

Deploying To Production on Heroku with Puma Discussion

So chris im using this on my db.yml file

production:
<<: *default
host: xxxxxxx
database: xxxxxx
password: xxxxx
port: xxxxxx
username:xxxxx

on your video you paste this code

production:
url: <%= ENV["DATABASE_URL"] %>
pool: <%= ENV["DB_POOL"] || ENV['MAX_THREADS'] || 5 %>

• form my db.yml code what parts I need to change.
• on heroku Config Vars I only have the DATABASE_URL its the DB_POOL build by puma??

thank you.

Reply

Heroku really only recommends the two lines for url and pool. The rest of that is all handled by Heroku. The DB_POOL may not be set, which will default it to 5 which is fine. You'll be able to easily change that as you scale up your Heroku servers.

Reply

Do you know a good resource for setting this up with mongoid?

Reply

Great question Jeff. I think Mongoid's docs do a pretty good job outlining the difference between it and ActiveRecord here: https://docs.mongodb.org/ec...

Reply

Chris, great video again. I had to go thru this 2 weeks ago and I wish I had this video back then. I've got a question which is not about this video, but about the very next step after deploying your app on heroku. So I had bought a custom domain (with google) and set up CNAME/ALIAS records with the pointDNS heroku addon. After that I realized that I need to configure my app over https if I use the custom domain instead of xyz.herokuapp.com. I read a bunch of articles, but still not sure what to choose. If it is possible I'd like to avoid the basic heroku addon solution since it costs $20/month. I've also seen the cloudfare free plan solution (https://www.cloudflare.com/..., but I'm not sure if it's good enough for production. Can you tell us/me pls, which one is the preferred solution here in general (not only from these 2 that I mentioned)?

Reply

Your cheapest option would be to use Cloudflare's flexible SSL. You wouldn't have to pay for the $20/mo for SSL hosting on Heroku that way. There are some other SSL options that Cloudflare provides but I think they cost money. https://www.cloudflare.com/...

Also most places require you to purchase an SSL certificate, but you may want to check out Let's Encrypt which let's you get a free SSL certificate. https://letsencrypt.org/

Reply

Hi Chris, I'm trying to follow along with this, but I'm stuck at the point where you use mvim to make a procfile. I don't know what mvim is (and if I have it, I don't know how to use it). I don't know how to make a procfile. I found someone on SO who is stuck with the same thing. Adapting their attempt, I did this in my terminal: echo "web: bundle exec puma -C config/puma.rb" > Procfile. Is that going to work to make a procfile? Thanks Mel

Reply

You can do that, but you can also just use your normal text editor to create and edit the file. Macvim is just what I use.

Reply

Hi Chris, i tried this. My database.yml now looks like yours. Now, when I try to precompile assets i get an error in my terminal that says:

ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter

My default specifies psql

Reply

It may be useful to note that ActionCable can work with Unicorn: https://github.com/rails/ra...

Reply
Masud Rana Hossain Masud Rana Hossain

Hey chris, if we have everything except the procfile...does this mean that puma is not going to start working on heroku?

My chat with actioncable + redis works 100% fine still.

Reply
Thanks! Now I finally know where these weird occasional database connection errors came from on heroku ;). I had a fixed value for pool size in my database.yml, while using multiple threads in my puma config.
Reply

Hey Chris, if I have this setup in puma.rb

workers Integer(2)
threads_count = Integer(5)

do I have to set my database.yml pool to 10? (each thread gets their own db connection?)

production:
url: <%= ENV['DATABASE_URL'] %>
pool: 10

Reply

Yeah, that should be correct. You'd multiple the two together to get your minimum pool size since each thread would need a database connection to operate (since they're doing the work).

Your app would look like this:

worker 1 
-> thread
-> thread
-> thread
-> thread
-> thread
worker 2
-> thread
-> thread
-> thread
-> thread
-> thread
Reply

You can now add a "Release Phase" to Heroku Procfile to script automatically the rake db:migrate, e.g.

release: bundle exec rake db:migrate

Reply

Is there a guide to deploying with Puma to a Linux server (ubuntu) running Nginx?

Reply
Reply

Thanks. You're using Passenger. Do you see any advantages to Passenger over Puma?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.