I’ve been trying to learn the easiest yet most stable way to deploy an app, but it’s been quite tough as many tutorials suggest different strategies. My end mission is to have a dedicated postgres database running in the cloud, and running my app from a paas provider or even from a VM using Dokku or a new tool which I found from DHH called kamal.
I have successfully deployed the app to Railway.app because it uses de Dockerfile to create the app, but this raises some questions:
I tried doing the exact same thing locally but somehow I got to the part where I needed to use a docker compose file. If I have a Dockerfile, and I want to have a database + webapp, do i still need docker compose or is it possible to just build it using the Dockerfile?
I see that in other tutorials as I use Tailwindcss, they add a Procfile, even though it’s not using Heroku. What is a Procfile and why should I use it? I deployed to Railway.app without using a Procfile and tailwindcss is working correctly as I see the styles.
Finally, as you can see, I am a little bit confused with all this. What strategy do you guys recommend to deploy my app without having to be an expert at Devops - just focusing on developing my SaaS. Is there a tutorial you guys recommend?
No, there is not a standard way because everyone has different needs. That being said there are some ways that are easier than others. If you are just starting out, a PAAS is probably one of the easier ways. They may come with trade-offs (flexibility, cost, etc) but those are challenges you can tackle once you have your feet wet.
Heroku is the OG of easy PAAS platform for Rails. It’s sort of fallen out of favor for a lot of folks since they got bought out by Salesforce. They have has stability problems and aren’t as innovative as they used to be. Also they are generally much higher cost than other options and got rid of their free tier that used to be so popular. That being said it’s still probably not a bad place to start and they have a guide to getting started on Rails for their platform.
Other PAAS platforms like fly.io and render are well liked and also have guides to get you started so those are other options to consider. And of course if you prefer to use big tech, then GCP, AWS, Azure all have PAAS-like services. I don’t have a lot of experience with those other than GCP’s App Engine platform (which is ok, but not great). I think the equiv in AWS is Lightsail?
I have used Dokku before and if you plan to stay on just a single server it’s really a great option. Heroku-like experience but on your own VM so lower cost and more flexibility. You are of course a bit more on your own than a PAAS so it’s a bit of a double-edge sword. I have been using Kamal with success and it’s getting a lot of attention because of it’s simplicity (compared to K8S) and flexibility (host anywhere). Like Dokku, it’s a double-edge sword. The flexibility gives you more options and lower cost but also puts more on you. Unlike Dokku it’s multi-server so it can grow to meet your needs. My overall suggestion is if you are just starting out on Rails then trying to learn Kamal and Rails is too much at once and you are probably better starting out on a PAAS.
As to some of your specific questions:
Containers are usually single-purpose. Technically you could run a bunch of software under a single container but that’s not recommended as different software has different needs. For example your web app scales horizontally while your database scales vertically. Also the isolation between different services helps with both security and management.
This means you need some sort of container orchestration tool to manage getting these different containers running and talking to each other. Docker compose can be used for that, but it’s really more meant as a dev tool since it just runs on a single machine. This means it can be used locally to help you but its use likely ends when you need to deploy.
Docker has a multi-server container orchestration tool called Swarm although it doesn’t have a lot of industry support. There are others such as Apache Mesos but the real 800lb gorilla is Kubernetes (K8S). The main issue with K8S is complexity. It was designed to solve needs Google has. This means while it likely can also solve all your needs it probably also can solve a bunch of needs you don’t have adding unnecessary complexity. Kamal is a simpler more imperative approach to solve needs that are more common to companies that aren’t Google’s size. A PAAS is basically abstracting you from container orchestration (often their own tool internally).
If your frontend needs pre-processing a Procfile is often used to run additional processes to do that during development so as you make changes to your frontend that pre-processing is done as soon as you save your changes. When you deploy your app to a PAAS that pre-processing just needs to be done during deployment so there is not the need for the Procfile (Heroku uses a Procfile for other purposes).
Rails lately has been encouraging frontends that don’t need pre-processing. If developing an app in that style there is no need for a Procfile as there is no “compile” step to the frontend. That being said it also fully supports frontends that do need the pre-processing if your preferred tools need that.
If I was wanting to focus just on my app and not devops I would pick a PAAS that meets my cost and feature goals and then use whatever tutorial they provide for getting up and running with Rails on their platform. The good news is if you change your mind and want to go with Kamal, K8S, etc later you can always do that.
Wow, this is an incredible response! I really appreciate that you took the time to answer with so much details and clarity.
I don’t even have a follow up question as you covered almost everything. I will stick to Railway as you said - which i guess is going to charge me from 5-10usd (or at least that’s what they charged me with a Nextjs app, until I moved it to Vercel). Its going to be years until i have to worry about having a personal PAAS with huge traffic.
From question number two, I wanted to share the video that covers how he used the Procfile to deploy to rails (which i deployed without needing it) to the same PAAS which is Railway: