Rake 与 Thor 的自动化脚本对比?

发布于 2024-09-15 12:10:45 字数 364 浏览 5 评论 0原文

我想自动化一些事情,比如:

  • 使用预先选择的数据库创建一个新的 Ruby on Rails 应用程序,Git 初始化它,创建一个 Heroku项目,提交所有文件等。
  • 通过SSH将文件夹中的所有文件上传到另一台计算机,但不要覆盖文件。
  • 升级Ubuntu,通过apt-get安装所有基本软件包。

据我了解,这方面的工具有 Rake 和 Thor,但是我应该使用哪一个呢?

在我看来,Rake 更实际、更受欢迎。我听人们推荐雷神。

这些在简述中是如何相互关联的?

I want to automate things like:

  • Creating a new Ruby on Rails application with pre-selected database, Git initialize it, create a Heroku project, commit all files, etc.
  • Upload all files in folder to another computer through SSH, but do not overwrite files.
  • Upgrade Ubuntu, install all basic packages through apt-get.

From what I understand, tools for this are Rake and Thor, however, which one should I use?

Rake seems to me more de-facto and popular. I have heard people recommending Thor.

How do these stand to each other in a rundown?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情泪▽动烟 2024-09-22 12:10:45

Rake 和 Thor 有不同的目的。

Rake 是一个针对特定项目的通用构建脚本工具。换句话说,您将 rakefile 放入项目文件夹和项目的源代码管理中,然后您可以在该 rakefile 中创建、构建和执行特定于您的项目的其他自动化任务。 Rake 需要 rakefile 才能运行。

Thor 是一个通用命令行脚本工具,可以非常轻松地在多个项目中重复使用脚本并进行项目设置等,就像您所建议的那样。 Thor 允许您“安装”一个可执行脚本,您可以从系统上的任何位置调用该脚本,类似于调用“ruby”、“gem”或“rake””命令行。然而,Thor 的脚本更适合通用的跨应用程序自动化,因为 Thor 脚本不依赖于项目特定文件夹中的文件。 Thor 脚本是完整的脚本,经过打包和安装以便在任何地方重复使用。

根据您陈述的需求,您最好使用 Thor,因为您将能够将脚本安装在一个位置并让它在系统上的任何位置运行。您将不受 Rake 文件所在位置或类似内容的限制。

顺便说一句,Rails 3 几乎使用 Thor 来处理所有非项目特定的事情。您仍然拥有 Rake 文件,并且仍然运行“rake db:migrate”或“rake test:units”等内容。 Thor 用于诸如“rails new ...”、“rails server”和“railsgenerate ...”等内容Rails 3 中的 Thor 和 Rake 完美地说明了这些工具最适合的用途。

Rake and Thor serve different purposes.

Rake is a general build script tool that is project-specific. In other words, you put your rakefile into your project folder and in your project's source control, and you can create, build and do other automation tasks that are specific to your project in that rakefile. Rake requires a rakefile to run.

Thor is a general purpose command line scripting tool that makes it very easy to re-use scripts across many projects and to do project setup, etc., like you are suggesting. Thor allows you to "install" an executable script that you can call from anywhere on your system, similar to calling "ruby", "gem" or "rake" command lines. However, Thor's scripts are more suited to general purpose, cross-application automation because the Thor script does not rely on a file sitting in your project-specific folder. A Thor script is the entire script, packed and installed for re-use anywhere.

Based on your stated needs, you are better off using Thor because you will be able to install your script in one location and have it work anywhere on your system. You will not be bound to where a Rake file is sitting or anything like that.

By the way, Rails 3 uses Thor for pretty much everything that is not project specific. You still have a Rake file and you still run things like "rake db:migrate" or "rake test:units". Thor is used for things like "rails new ...", "rails server" and "rails generate ..." The use of Thor AND Rake in Rails 3 is the perfect illustration of where each of these tools is best suited.

茶色山野 2024-09-22 12:10:45

对于设置 Ubuntu 杂务,Chef 可能是更好的选择。

从他们的网站:

Chef 是一个开源系统集成框架,旨在为您的整个基础设施带来服务器配置管理的优势。

它是用 Ruby 编写的,并且有大量的厨师食谱/食谱。 Chef 将负责设置 Ubuntu 并安装软件包、服务器等。

我不知道您是否正在使用虚拟机,但 Vagrant 将设置虚拟机,然后使用 Chef 来配置它。

For setting up Ubuntu chores, Chef might be a better option.

From their web site:

Chef is an open source systems integration framework, built to bring the benefits of server configuration management to your entire infrastructure.

It's written in Ruby and there are tons of Chef recipes/cookbooks. Chef will handle setting up Ubuntu and installing packages, servers, etc.

I don't know if you are working with virtual machines, but Vagrant will set up a virtual machine and then use Chef to configure it.

命硬 2024-09-22 12:10:45

这里有一件重要的事要提。

http://guides.rubyonrails.org/generators.html 第 8 节应用程序模板。

您可以执行 git 命令、选择 gems、capify 项目。

您还可以执行系统命令来满足您的最后一点:升级Ubuntu,通过apt-get安装所有基本软件包

There is something important to mention here.

http://guides.rubyonrails.org/generators.html in its section 8 Application Templates.

You can execute git commands, select gems, capify project.

And you could also execute system commands to satisfy your last point: Upgrade Ubuntu, install all basic packages through apt-get.

始于初秋 2024-09-22 12:10:45

我会选择puppet

顺便说一下,也许流浪者对你有用吗?

I would go with puppet.

By the way, maybe vagrant is useful to you?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文