Is there a way to make Rails deployments faster?

I'm using nixpacks and it always takes around 7 minutes for a Rails app to build and deploy. What can I do to make it faster? Project ID: 9c6db4bc-b375-44fd-87b5-09e05a5e88f1
30 Replies
Percy
Percy2y ago
Project ID: 9c6db4bc-b375-44fd-87b5-09e05a5e88f1
Percy
Percy2y ago
⚠️ experimental feature
milo
milo2y ago
we dont do proper caching for ruby rn, and we dont know how to. if u can figure out what we need to cache i can spin up a pr to make it faster
Stibnite
StibniteOP2y ago
The key question for me right now is how you invalidate cache when using nixpack?
milo
milo2y ago
We have no cache invalidation, we always bring in the cache then just update it if something changes.
Stibnite
StibniteOP2y ago
What's that "something"? What do you mean by "something changes"? Let's take npm modules for example. If package-lock.json changes, do you update the cache automatically? Or how does it work?
milo
milo2y ago
basically regardless of if it changes, we always update the cache with the latest package-lock.json
Stibnite
StibniteOP2y ago
And what if the contents of package-lock.json don't change at all? Will nixpacks build the npm packages again? Or will it use cache and therefore make the deployment faster? Let me explain what I'm thinking about. 90% of the build time takes building the gems (Ruby libraries). They are located in a file called Gemfile and Gemfile.lock. We could cache Gemfile.lock to make the deployment faster.
milo
milo2y ago
We still run the cache update I don’t think that’ll work tbh
Stibnite
StibniteOP2y ago
Okay, I think I don't understand how your cache works then. I assumed it was similar to Docker image cache.
milo
milo2y ago
it works how the github actions cache works. we always recache it, it doesnt matter if the file hasnt changed Gemfile.lock is a lockfile, caching that won't do anything, and im pretty sure that should be commited. we need to commit the directory with the built gems
Stibnite
StibniteOP2y ago
I see I'll try to think of other ways of improving the build then Thanks 🙌
milo
milo2y ago
do u know where built gems are sent/located?
Stibnite
StibniteOP2y ago
You want to know the directory where the gems are located? They are not located in the project like it's with node_modules You can check where the specific gem is located with bundle show <gem_name> or bundle info <gem_name> --path (I believe bundle show is deprecated) Should the path be "static" (defined) in order to optimize it with nixpacks?
milo
milo2y ago
yeah the built gems not sure will look into later
Stibnite
StibniteOP2y ago
All right Milo, I'm sending a kind reminder 😄 I'd love to help but I need some directions Why did you ask about the locations of the gems?
milo
milo2y ago
oh shit my badi forgot basically, we need to cachce the built direction of the gems if u can figure out where the built gems are, this'll work and we can cache it
Stibnite
StibniteOP2y ago
It would be great gems take 80% of the build time Haha, it happens, no worries ^^
milo
milo2y ago
yea. jus lmk if u find it
Stibnite
StibniteOP2y ago
sure thing Can the cache be turned on and off? For example when someone has custom build directory
milo
milo2y ago
no dont think so
Stibnite
StibniteOP2y ago
Looks like nixpacks are using rbenv
milo
milo2y ago
yes we are
Stibnite
StibniteOP2y ago
With rbenv the gems location is: .rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pay-6.3.1 Where: 3.1.1 is the installed Ruby version 3.1.0 is the minor version. pay-6.3.1 is an example library. --- So the gems location looks like this ~/.rbenv/versions/{version-number}/lib/ruby/gems/{minor-version}
milo
milo2y ago
~/.rbenv/versions/{version-number}/lib/ruby/gems so we will cache that
milo
milo2y ago
GitHub
Better Ruby caching by Milo123459 · Pull Request #817 · railwayapp/...
This PR caches the .rbenv directory. This will lead to significant speedups in Ruby builds.
Stibnite
StibniteOP2y ago
Awesome, thanks! When are changes like this usually merged?
milo
milo2y ago
depends. usually when jr reviews them 😄
Stibnite
StibniteOP2y ago
Fingers crossed 🤞 Thanks once again. It's going to be huge for me. I love quick deployments.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server