There is any way to deploy a heroku rails app after a travis-ci success build?
在travis-ci成功构建之后,有什么方法可以部署heroku rails应用程序吗?
4 个解决方案
#1
9
Travis CI now has built-in support for deploying to Heroku: http://about.travis-ci.org/blog/2013-07-09-introducing-continuous-deployment-to-heroku/
Travis CI现在已经内置支持部署到Heroku:http://about.travis-ci.org/blog/2013-07-09-introducing-continuous-deployment-to-heroku/
#2
5
I just implemented this case with an application of mine. It's actually not that hard to do, but it requires some steps:
我刚用我的应用程序实现了这个案例。它实际上并不难,但它需要一些步骤:
- You need your heroku API key
- 你需要你的heroku API密钥
- See this gist for an example
.travis.yml
and get thetravis_deployer.rb
script - 请参阅此要点以获取示例.travis.yml并获取travis_deployer.rb脚本
- Then install the travis gem, see the answer to another question on how to secure your API key.
- If you don't care about it, just use the example from gist above.
- 如果你不关心它,只需使用上面的gist中的例子。
- Run
travis encrypt your_username/your_repo HEROKU_API_KEY=<your key here>
- 运行travis加密your_username / your_repo HEROKU_API_KEY = <您的密钥在这里>
- Copy the result in your
.travis.yml
in the env -> global section - 将结果复制到env - > global部分的.travis.yml中
- 然后安装travis gem,查看有关如何保护API密钥的另一个问题的答案。如果你不关心它,只需使用上面的gist中的例子。运行travis加密your_username / your_repo HEROKU_API_KEY = <你的密钥在这里> 将结果复制到env - > global部分的.travis.yml中
The travis_deployer.rb
file takes care of the ssh keys and the remote branch for heroku.
travis_deployer.rb文件负责heroku的ssh密钥和远程分支。
If you've performed all these steps you .travis.yml
might look like this:
如果您执行了所有这些步骤,则.travis.yml可能如下所示:
env:
global:
- secure: "1u21hjnmHjkghduUIJhhs76saljlkajdlfhGhgdJgfaVtgasfLLmNBnb87dad="
after_success:
- gem install heroku
- yes | ruby travis_deployer.rb
- heroku keys:clear
- yes | heroku keys:add
- git push heroku master
#3
2
Here is a version I found on Mark Bates' blog. It's similar to Odi's, just that it relies on the after_script
in your .travis.yml
file alone.
这是我在Mark Bates的博客上找到的版本。它与Odi类似,只是它依赖于.travis.yml文件中的after_script。
-
First of all, use Travis' feature to encrypt environment variables so your secret API keys remain protected:
首先,使用Travis的功能加密环境变量,以便保护您的秘密API密钥:
gem install travis travis encrypt username/repository HEROKU_API_KEY=YOUR_HEROKU_API_KEY
-
Then append the following to your
.travis.yml
file:然后将以下内容附加到.travis.yml文件中:
env: global: - secure: YOUR_SECURED_HEROKU_API_KEY after_script: # Install the Heroku gem (or the Heroku toolbelt) - gem install heroku # Add your Heroku git repo: - git remote add heroku git@heroku.com:YOUR_HEROKU_APP.git # Turn off warnings about SSH keys: - echo "Host heroku.com" >> ~/.ssh/config - echo " StrictHostKeyChecking no" >> ~/.ssh/config - echo " CheckHostIP no" >> ~/.ssh/config - echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config # Clear your current Heroku SSH keys: - heroku keys:clear # Add a new SSH key to Heroku - yes | heroku keys:add # Push to Heroku! - yes | git push heroku master
-
And you're done: commit your new changes and enjoy deploying to Heroku via TravisCI.
并且您已完成:提交您的新更改并享受通过TravisCI部署到Heroku。
Edit: If you get any errors on travis encrypt
, this might be your solution.
编辑:如果您在travis加密时遇到任何错误,这可能是您的解决方案。
#4
0
I had just been thinking of this kind of scenario, though I didn't specifically consider Heroku as the platform of choise. Anyhow, this is what I have come-up with:
我刚刚考虑过这种情况,虽然我没有特别考虑Heroku作为选择的平台。无论如何,这就是我的想法:
- Pull requests go to "development" branch
- 拉请求转到“开发”分支
- Travis test the pull request for you
- Travis为您测试拉取请求
- If we are about to deploy what's currently in "develop" - humans pull request, review and merge that into "release/candidate" branch
- 如果我们即将部署当前正在“开发”的东西 - 人类拉动请求,审查并将其合并到“发布/候选”分支
- Travis tests again once merged
- 一旦合并,特拉维斯再次测试
- Once test on that branch passed - get Travis to create a pull request targeting "release/production" (perhaps write a wrapper for GitHub API for creating the actual pull request form Travis).
- 一旦对该分支的测试通过 - 让Travis创建一个针对“发布/生产”的拉取请求(也许为GitHub API编写一个包装器,用于创建Travis的实际拉取请求)。
- Depending on whether we actually want to deploy or not quite yet - a human merges (into "release/production") or closes the pull request created from Travis
- 取决于我们是否真的想要部署或者还没有 - 人类合并(进入“发布/生产”)或关闭从Travis创建的拉取请求
- Have either a deployer host or have each of the app hosts (if you have many and don't want to have an SPF) to track the "release/production" branch.
- 拥有部署主机或拥有每个应用程序主机(如果您有许多并且不想拥有SPF)来跟踪“发布/生产”分支。
I'm sure you could implement a Heroku app that will handle the role of being the deployer host or something even more crazy.
我相信你可以实现一个Heroku应用程序来处理作为部署主机或更疯狂的角色。
Also, you may wish to try having Travis to notify you via IRC and have another IRC bot on your client side which will have access to you personal SSH key and make a push to Heroku, you could also implement a confirmation interface there by means of having a private conversation with your own bot or scripted GUI interface with a "Go ahead!" button. If you are not so old-school, you can use Hubot for that purpose.
此外,您可能希望尝试让Travis通过IRC通知您,并在您的客户端有另一个IRC bot,它可以访问您的个人SSH密钥并推送到Heroku,您也可以通过它实现一个确认界面与您自己的机器人或脚本化GUI界面进行私密对话,并带有“Go ahead!”按钮。如果你不是那么老派,你可以将Hubot用于此目的。
By the way, you could also introduce some sort of staging branch or whatever you like in between some of the above steps. You probably should also use tags and the rollback would just pushing a know working tag into "release/production" from where it'll be picked up by your deployer script.
顺便说一句,您还可以在上述某些步骤之间引入某种分段分支或任何您喜欢的分支。您可能还应该使用标记,并且回滚只会将已知的工作标记推送到“发布/生产”中,然后由部署程序脚本将其拾取。
#1
9
Travis CI now has built-in support for deploying to Heroku: http://about.travis-ci.org/blog/2013-07-09-introducing-continuous-deployment-to-heroku/
Travis CI现在已经内置支持部署到Heroku:http://about.travis-ci.org/blog/2013-07-09-introducing-continuous-deployment-to-heroku/
#2
5
I just implemented this case with an application of mine. It's actually not that hard to do, but it requires some steps:
我刚用我的应用程序实现了这个案例。它实际上并不难,但它需要一些步骤:
- You need your heroku API key
- 你需要你的heroku API密钥
- See this gist for an example
.travis.yml
and get thetravis_deployer.rb
script - 请参阅此要点以获取示例.travis.yml并获取travis_deployer.rb脚本
- Then install the travis gem, see the answer to another question on how to secure your API key.
- If you don't care about it, just use the example from gist above.
- 如果你不关心它,只需使用上面的gist中的例子。
- Run
travis encrypt your_username/your_repo HEROKU_API_KEY=<your key here>
- 运行travis加密your_username / your_repo HEROKU_API_KEY = <您的密钥在这里>
- Copy the result in your
.travis.yml
in the env -> global section - 将结果复制到env - > global部分的.travis.yml中
- 然后安装travis gem,查看有关如何保护API密钥的另一个问题的答案。如果你不关心它,只需使用上面的gist中的例子。运行travis加密your_username / your_repo HEROKU_API_KEY = <你的密钥在这里> 将结果复制到env - > global部分的.travis.yml中
The travis_deployer.rb
file takes care of the ssh keys and the remote branch for heroku.
travis_deployer.rb文件负责heroku的ssh密钥和远程分支。
If you've performed all these steps you .travis.yml
might look like this:
如果您执行了所有这些步骤,则.travis.yml可能如下所示:
env:
global:
- secure: "1u21hjnmHjkghduUIJhhs76saljlkajdlfhGhgdJgfaVtgasfLLmNBnb87dad="
after_success:
- gem install heroku
- yes | ruby travis_deployer.rb
- heroku keys:clear
- yes | heroku keys:add
- git push heroku master
#3
2
Here is a version I found on Mark Bates' blog. It's similar to Odi's, just that it relies on the after_script
in your .travis.yml
file alone.
这是我在Mark Bates的博客上找到的版本。它与Odi类似,只是它依赖于.travis.yml文件中的after_script。
-
First of all, use Travis' feature to encrypt environment variables so your secret API keys remain protected:
首先,使用Travis的功能加密环境变量,以便保护您的秘密API密钥:
gem install travis travis encrypt username/repository HEROKU_API_KEY=YOUR_HEROKU_API_KEY
-
Then append the following to your
.travis.yml
file:然后将以下内容附加到.travis.yml文件中:
env: global: - secure: YOUR_SECURED_HEROKU_API_KEY after_script: # Install the Heroku gem (or the Heroku toolbelt) - gem install heroku # Add your Heroku git repo: - git remote add heroku git@heroku.com:YOUR_HEROKU_APP.git # Turn off warnings about SSH keys: - echo "Host heroku.com" >> ~/.ssh/config - echo " StrictHostKeyChecking no" >> ~/.ssh/config - echo " CheckHostIP no" >> ~/.ssh/config - echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config # Clear your current Heroku SSH keys: - heroku keys:clear # Add a new SSH key to Heroku - yes | heroku keys:add # Push to Heroku! - yes | git push heroku master
-
And you're done: commit your new changes and enjoy deploying to Heroku via TravisCI.
并且您已完成:提交您的新更改并享受通过TravisCI部署到Heroku。
Edit: If you get any errors on travis encrypt
, this might be your solution.
编辑:如果您在travis加密时遇到任何错误,这可能是您的解决方案。
#4
0
I had just been thinking of this kind of scenario, though I didn't specifically consider Heroku as the platform of choise. Anyhow, this is what I have come-up with:
我刚刚考虑过这种情况,虽然我没有特别考虑Heroku作为选择的平台。无论如何,这就是我的想法:
- Pull requests go to "development" branch
- 拉请求转到“开发”分支
- Travis test the pull request for you
- Travis为您测试拉取请求
- If we are about to deploy what's currently in "develop" - humans pull request, review and merge that into "release/candidate" branch
- 如果我们即将部署当前正在“开发”的东西 - 人类拉动请求,审查并将其合并到“发布/候选”分支
- Travis tests again once merged
- 一旦合并,特拉维斯再次测试
- Once test on that branch passed - get Travis to create a pull request targeting "release/production" (perhaps write a wrapper for GitHub API for creating the actual pull request form Travis).
- 一旦对该分支的测试通过 - 让Travis创建一个针对“发布/生产”的拉取请求(也许为GitHub API编写一个包装器,用于创建Travis的实际拉取请求)。
- Depending on whether we actually want to deploy or not quite yet - a human merges (into "release/production") or closes the pull request created from Travis
- 取决于我们是否真的想要部署或者还没有 - 人类合并(进入“发布/生产”)或关闭从Travis创建的拉取请求
- Have either a deployer host or have each of the app hosts (if you have many and don't want to have an SPF) to track the "release/production" branch.
- 拥有部署主机或拥有每个应用程序主机(如果您有许多并且不想拥有SPF)来跟踪“发布/生产”分支。
I'm sure you could implement a Heroku app that will handle the role of being the deployer host or something even more crazy.
我相信你可以实现一个Heroku应用程序来处理作为部署主机或更疯狂的角色。
Also, you may wish to try having Travis to notify you via IRC and have another IRC bot on your client side which will have access to you personal SSH key and make a push to Heroku, you could also implement a confirmation interface there by means of having a private conversation with your own bot or scripted GUI interface with a "Go ahead!" button. If you are not so old-school, you can use Hubot for that purpose.
此外,您可能希望尝试让Travis通过IRC通知您,并在您的客户端有另一个IRC bot,它可以访问您的个人SSH密钥并推送到Heroku,您也可以通过它实现一个确认界面与您自己的机器人或脚本化GUI界面进行私密对话,并带有“Go ahead!”按钮。如果你不是那么老派,你可以将Hubot用于此目的。
By the way, you could also introduce some sort of staging branch or whatever you like in between some of the above steps. You probably should also use tags and the rollback would just pushing a know working tag into "release/production" from where it'll be picked up by your deployer script.
顺便说一句,您还可以在上述某些步骤之间引入某种分段分支或任何您喜欢的分支。您可能还应该使用标记,并且回滚只会将已知的工作标记推送到“发布/生产”中,然后由部署程序脚本将其拾取。