简体   繁体   中英

How to use Hubot to deploy a Github repo to Heroku?

Back when they announced Hubot one of the things GitHub said they do with theirs is deployment. I'm attempting to do the same for my project the code for which is hosted on GitHub while the app itself is on Heroku. My Hubot also lives on Heroku but I'm doing all my testing locally first.

My idea was to either clone the target repo in tmp, add a remote in that repo to point to the Heroku app, then run git push heroku or (like this SO question ) create two remotes and push that way. While I've gotten the git clone to work locally when I try to run

Exec "cd #{dir}; git remote add #{proj_loc} git@heroku.com:#{heroku_app}.git"

it ends up adding the remote to the git repo that exists in the directory from which I started bin/hubot not the git repo that now exists in tmp. I know dir is set correctly and that cd works because I've run

Exec "cd #{dir}; pwd"

and the results are what I'd expect. So the behavior of git remote confuses me.

Has anyone done anything like this or can at least tell me why git remote doesn't add the remote to the temp in tmp and how to fix it?

I've also yet to try to tackle the issue of the keys required to 1) access a private repo on GitHub; and 2) deploy to Heroku. I'll figure that out if I can get this working.

I did this with my system. I had my hubot contact my build box via SSH and run the git pull / deploy command. The deploy command would shoot a POST payload back to the hubot instance and all the statuses are posted to the hubot's chat client. I wrote an entire blog post about it: http://tritarget.org/blog/2014/10/13/new-site-ship-it/

I considered the same when I heard how Github were using Hubot. At a guess though, they are hosting it on a machine that they manage, like a physical or a VPS which is much more like a local machine when it comes to deploying code. Whilst you may get bits working on Heroku I think you're going to struggle with keys and actually deployment - but I'm open to being proven wrong :)

I created a Java / Play Framework app that might do what you want:
https://github.com/heroku/shareheroku-java

The app does the following:

  1. Clones (or updates) a git repo from a git url
  2. Creates a new ssh key for an existing Heroku user
  3. Adds the key to the user's account
  4. Ceates a new app on Heroku
  5. Pushes the cloned app to Heroku
  6. Adds another user as a collaborator
  7. Transfers ownership to the user
  8. Removes the original user from the app
  9. Removes the ssh key from the original user

You can see it in action at:
http://java.herokuapp.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM