Home > Software engineering >  How do I know which git revision unicorn/rails has currently loaded into memory?
How do I know which git revision unicorn/rails has currently loaded into memory?

Time:01-27

I am debugging a problem where I experience unicorn not picking up code changes on deploys when I use the master re-spawn procedure for upgrading. I need a way to ask unicorn/my rails app which code revision is currently in memory - but I'm unsure how I would do that?

CodePudding user response:

It depends on how you deploy your application. When you deploy does it get deployed with the .git directory in place and intact? That's not a recommended practice. (because if your server is compromised you don't want potentially sensitive or private information stored on that server, like what might be found in git data) And are git binaries installed on the system? Which again is not a recommended practice because deployed apps shouldn't have applications on them that attackers can leverage to pull down their own malicious code.

If both are present then you can use https://github.com/ruby-git/ruby-git, or more simply https://github.com/NARKOZ/git-revision, and then surface that somewhere in your application. (like a health check endpoint, or in headers) This would all be custom code that you have to write that is dependent on your application.

A better practice would be to inject a static value into your application when it is deployed. Your CI/CD pipeline would clone the repo, get the current revision, then store this in your application in a static file before it ships it, and then the app would serve up this file on demand. (or load it into memory on boot) This has the added benefit of not bloating your application with more gems and binaries that are not technically required and increase your attack surface.

  • Related