git diff from heroku
I've deployed a campfire bot onto heroku (sinatra app using tinder to listen to the campfire room), and I'd like to query it for the git diff between what's deployed on another heroku app and what's in our github repo. If I were doing this locally, I'd just
- clone the github repo
- Add the heroku remote
- Run a
git diff
whenever requested
On heroku, however, I'm limited to only having a tmp directory (on bamboo) or an ephemeral filesystem (on cedar), and also have the dif开发者_开发百科ficulty of managing the ssh keys for the user the app runs as.
How can I accomplish this on heroku, preferably being able to show results in a tree format?
I'm going to assume that you are not happy with cedar's ephemeral filesystem in that files gets lost every dyno reboot and are not visible cross-dyno. Accepting those constraints would obviously be the simplest solution (each dyno might have to create its own particular git repos, but that would be it).
The second most straightforward solution would be having the git log calculated elsewhere. You could write a small, webservice-like app (maybe with Sinatra) that accepted two repository urls, and returned their diff. And then you could query that from the heroku app. But I guess this is ruled out since you are asking to do it "on Heroku".
Which brings us to the last solution; it involves creating everything in memory; the initial folder would have to be created with something like FakeFS and the git control would have to be done from ruby natively; Scott Chacon's grit fork did native calls instead of shelling, so it might work (I don't know if Chacon's changes were ported to the main grit). This way all the filesystem access would be done from ruby, and everything would be in memory (you might want to upgrade your memory, by the way)
I haven't personally tried any of these, I don't know how well would they perform.
If you need persistence, maybe you can marshal the whole thing into / from your database, but that sounds like a lot of trouble.
I hope this helps.
From Heroku support:
jd, Jul-18 03:18 pm (PDT): Hi Ben,
Yes, you can use tmp/ on Bamboo or the ephemeral filesystem on Cedar. Generally, the trouble with using git to access external repositories is the private ssh key. You'll need to include this with you app. You will also need to set the GIT_SSH variable to instruct git on how to use that key, e.g.:
GIT_SSH="ssh -i /app/doc/id_rsa $@"
A bit of experimentation and you should be able to get it working.
The post-deploy hooks might also be of some assistance: http://devcenter.heroku.com/articles/deploy-hooks
Good luck!
Cheers, JD
精彩评论