git 我可以在不重新编译 slug 的情况下更新 Heroku 上的单个源文件吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11405619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I update a single source file on Heroku without recompiling the slug?
提问by baash05
I'm working on a rails project that's being hosted on Heroku. I'm wondering if it's possible to update one file, without restarting the app.
我正在开发一个在 Heroku 上托管的 Rails 项目。我想知道是否可以在不重新启动应用程序的情况下更新一个文件。
Why. I have a bug, but I can't track it down. It works perfectly on my local system, but it seems to stop mid way through processing on heroku.
为什么。我有一个错误,但我无法追踪它。它在我的本地系统上运行良好,但它似乎在处理 heroku 中途停止。
As there are no break points, I'm scattering status updates in the code. (to be removed later) But adding one line of code to a rails app is like a five minute process.
由于没有断点,我在代码中散布状态更新。(稍后将被删除)但是向 rails 应用程序添加一行代码就像一个五分钟的过程。
- change file
- stage file to git
- commit file
- push git (all the above is quite fast)
- wait for heroku to pull down the app, do what looks like a gem install, or at least a gem update.
- change a few files to reflect the local url
- start up the service again.
- 更改文件
- 暂存文件到 git
- 提交文件
- push git(以上都是相当快的)
- 等待 heroku 拉下应用程序,执行 gem 安装,或者至少是 gem 更新。
- 更改一些文件以反映本地 url
- 再次启动服务。
Is there a way to push the git without running all those other things? Perhaps a special parameter to add to the push?
有没有办法在不运行所有其他东西的情况下推送 git?也许要添加到推送中的特殊参数?
另一个烦恼是我的 git 现在有一堆我不想让我的同事看到的签到。我的目标是我自己的 heroku 非生产实例(仅用于测试),并且没有理由将所有这些尝试都包含在全局源代码管理中。
回答by John Beynon
There's a good reason as to why it's not possible. When you push to Heroku, they produce a 'slug' of your application (https://devcenter.heroku.com/articles/slug-compiler). To provide the massive scalability that Heroku provides this slug is read only so that it can be spun up on multiple dynos which are likely to be distributed across many different physical machines. Each of these dynos runs a separate instance of your application whilst the routing mesh ensures that requests to your application goes to the correct dynos.
有一个很好的理由说明为什么这是不可能的。当您推送到 Heroku 时,它们会生成您的应用程序的“slug”(https://devcenter.heroku.com/articles/slug-compiler)。为了提供 Heroku 提供的大规模可扩展性,此 slug 是只读的,以便它可以在可能分布在许多不同物理机器上的多个 dyno 上运行。这些 dynos 中的每一个都运行您的应用程序的一个单独实例,而路由网格确保对您的应用程序的请求转到正确的 dynos。
Now consider what would occur if any of these instances were writeable, if you're running 5 dynos you'd have your application running on 5 seperate instances - if a file is written how is it then distributed across of your running dynos? Yes, Heroku could have considered some kind of shared file system for running applications out of but that's complicated. By making the file system read only (https://devcenter.heroku.com/articles/read-only-filesystem) this problem is alleviated.
现在考虑如果这些实例中的任何一个是可写的会发生什么,如果您正在运行 5 个 dynos,那么您的应用程序将在 5 个单独的实例上运行 - 如果一个文件被写入,那么它如何分布在您正在运行的 dynos 上?是的,Heroku 可以考虑使用某种共享文件系统来运行应用程序,但这很复杂。通过将文件系统设为只读 ( https://devcenter.heroku.com/articles/read-only-filesystem),这个问题得到缓解。
If you've built an app and deployed to Heroku but forgotten to use S3 type peristant storage your application will let you upload files to it (via Paperclip of such like in the Ruby world) but that uploaded asset will only exist on the dyno that received it and will then be lost when new code is deployed or the application restarted as the dyno receives the latest code from the slug.
如果您已经构建了一个应用程序并部署到 Heroku 但忘记使用 S3 类型的持久存储,您的应用程序将允许您将文件上传到它(通过像 Ruby 世界中的 Paperclip),但上传的资产将只存在于 dyno 上收到它,然后在部署新代码或重新启动应用程序时丢失,因为 dyno 从 slug 接收最新代码。
If you're debugging against Heroku don't forget you've got the usual git arsenal available, git commit --amend
. Alternatively work in a branch and deploy that to directly to Heroku (git push heroku <yourbranchname>:master
) then when you've isolated the problem rebase (http://git-scm.com/book/en/Git-Branching-Rebasing) your branch onto master squashing any commits you no longer need.
如果您正在针对 Heroku 进行调试,请不要忘记您有常用的 git 武器库,git commit --amend
. 或者在一个分支中工作并将其直接部署到 Heroku ( git push heroku <yourbranchname>:master
) 然后当你隔离问题时 rebase ( http://git-scm.com/book/en/Git-Branching-Rebasing) 你的分支到 master 上压缩任何提交你不再需要。
回答by Todd A. Jacobs
XY Problem
XY问题
This is a classic XY Problem. X is your non-working code; Y is your search for a non-existent Git misfeature.
这是一个经典的XY 问题。X 是您的非工作代码;Y 是您对不存在的 Git 错误功能的搜索。
How Git Works
Git 的工作原理
Git commits fundamentally work at the tree level, not the file level. As a gross over-simplification, a commit points to a tree, which points to a set of files. When you push a commit, you have to push all the objects related to that commit unless the objects already exist on the receiver.
Git 提交基本上是在树级别工作,而不是文件级别。作为粗略的过度简化,提交指向一个树,它指向一组文件。当你推送一个提交时,你必须推送与该提交相关的所有对象,除非这些对象已经存在于接收器上。
How Heroku Works
Heroku 的工作原理
Heroku compiles the applicationin your Git repository into a slug. While you can ignore certain filesduring compilation, you can't avoid compiling the slug. That's just the way the platform works.
Heroku将Git 存储库中的应用程序编译为 slug。虽然您可以在编译期间忽略某些文件,但您无法避免编译 slug。这就是平台的运作方式。
This is not a problem if you have a reasonable slug size; my Heroku apps only take a couple of seconds to compile. If your slugs are very large, and therefore take a long time to compile (you claim it takes you 5+ minutes), then you have another XY problem on your hands if you're trying to solve for "don't compile."
如果您有合理的 slug 尺寸,这不是问题;我的 Heroku 应用程序只需几秒钟即可编译。如果您的 slug 非常大,因此需要很长时间来编译(您声称需要 5 分钟以上),那么如果您试图解决“不编译”问题,那么您将面临另一个 XY 问题。
Debugging on Heroku
在 Heroku 上调试
Heroku has lots of features and add-ons to aid debugging. Here's a short list to get you started.
Heroku 有很多功能和附加组件来帮助调试。这是一个简短的列表,可帮助您入门。
See Also
也可以看看
回答by Dty
It's not possible. The way heroku is setup, every time you push up a change the server will restart.
这是不可能的。heroku 的设置方式,每次推送更改时服务器都会重新启动。
回答by Jason Kim
Yes you can.
是的你可以。
First, list all the files that have been modified since the last commit.
首先,列出自上次提交以来修改过的所有文件。
git status
git status
Add the files you want to commit individually.
添加要单独提交的文件。
git add location/file_name.rb
git add location/file_name2.rb
...
git add location/file_name.rb
git add location/file_name2.rb
...
Make commit to the files you added to push.
提交您添加到推送的文件。
git commit -m "committing files one at a time or two at a time"
git commit -m "committing files one at a time or two at a time"
Now push
现在推
git push heroku
git push heroku