使用 Git 在 Ubuntu 服务器上部署 Rails 应用程序
我对 Linux 完全陌生,但今天我发现自己从头开始设置一个服务器(Ubuntu 10.04 LTS lucid)来托管 Rails 应用程序。
不管怎样,我设法在服务器本身上启动并运行了一个 Rails 应用程序,但我不得不放弃它,因为我想使用 Git。因此,我在服务器上设置了一个 git 存储库,然后将所有代码从本地计算机推送到存储库。不过,当然,Git 实际上并不将文件本身存储在存储库中——我的 Rails 应用程序的所有代码现在仅位于我的本地计算机上。我该如何告诉服务器托管它?
现在我的解决方案是让服务器使用 git 从它自己的存储库中提取代码。这就是我将向全世界展示的代码。为了更新代码,我想我必须执行以下操作:
- 更新本地计算机上的代码。
- 执行一些 git 添加、git 提交和 git 推送。
- 在服务器上,执行 git pull 来更新代码。
所以我的问题是,我这样做的方式正确吗?
I'm completely new to Linux, but today I find myself setting up a server (Ubuntu 10.04 LTS lucid) from scratch to host a Rails application.
Anyway, I managed to get a Rails app up and running on the server itself, but I had to scrap that because I want to use Git. So I setup a git repository on the server, then pushed all the code from my local machine to the repository. Buuuut, of course Git doesn't actually store the files themselves in the repository -- all the code for my Rails app is now only on my local machine. How am I supposed to tell the server to host that?
Right now my solution is to have the server use git to pull the code from its own repository. That's the code I'll host for all the world to see. In order to update the code, I guess I'll have to do something like this:
- Update the code on my local machine.
- Do some git adds, git commits, and a git push.
- On the server, do a git pull to update the code.
So my question is, am I doing this the right way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您使用 Capistrano 将应用程序部署到切片。 Slicehost 在这方面有一些优秀的指南。
I recommend that you use Capistrano to deploy your application to your slice. Slicehost have some excellent guides available on this.
Cap 很可靠,是 Rails 应用程序的常见做法。检查一下确定一下。
我还强烈建议 Github 托管您的存储库。它真的很便宜并且提供了很多价值。对于您所描述的情况,最简单的工作流程是将开发计算机上的存储库推送到 github。然后,从您的服务器将 github 存储库克隆到您的服务器上。
在开发过程中,不断将增量更改推送到 github。当您准备好发布更新时,只需从服务器中 git pull ,它就会提取您所做的所有更改。
Cap is solid and is common practice for Rails apps. Check it out for sure.
I also highly suggest Github to host your repo. It's really inexpensive and provides a ton of value. The simplest workflow for the situation you described would be to push the repo you have on your development machine up to github. Then, from your server, clone the github repo onto your server.
As you develop, keep pushing incremental changes up to github. When you're ready to release an update, simply git pull from your server and it will pull in all the changes you've made.