Vagrant Push入门

Vagrant Push is a new feature with the release of Vagrant 1.7 that allows you to deploy any application with a single command - vagrant push. In simple uses, this helps improve a developer's single workflow when building an application. In more complex uses, it allows developers to collaborate and integrate vagrant directly with their existing continuous integration tools.

Vagrant PushVagrant 1.7发行版中的一项新功能,使您可以使用单个命令vagrant push部署任何应用程序。 在简单的使用中,这有助于在构建应用程序时改善开发人员的单一工作流程。 在更复杂的用途中,它允许开发人员直接将流浪汉与现有的持续集成工具进行协作和集成。

In this article, I'll discuss the different uses of the vagrant push command, provide a quick tutorial on how to use it, and, lastly, a walk-through of how you can use Vagrant Push with our open-source Vagrant setup "Scotch Box".

在本文中,我将讨论vagrant push命令的不同用法,提供有关如何使用它的快速教程,最后,介绍如何在我们的开源Vagrant设置中使用Vagrant Push。 苏格兰威士忌盒 ”。

Looking for a quick and easy Vagrant Intro? Check out 寻找快速便捷的Vagrant Intro吗? 只需几分钟,就可以查看 Scotch Box for a painless and hassle-free Vagrant Lamp Stack in minutes. Scotch Box,以确保无痛苦且无忧无虑的游民灯堆叠。

总体思路 (The General Idea)

One of the most important things to understand is that even though the verbiage "push" and "deploy" are loosely interrupted and used to mean the same thing, it is not necessarily the case at all. The actual meaning of a Vagrant "Push" is to simply move your application to the next step in the deployment process (with the ultimate goal of moving your changes into production).

要理解的最重要的事情之一是,即使“ push ”和“ deploy ”一词被松散地打断并用来表示相同的事物,也不一定完全是这种情况。 Vagrant“ Push ”的实际含义是简单地将应用程序移至部署过程的下一步(最终目的是将更改移入生产环境)。

This is all contigent on your application, the project, the team in hand, and your current workflow setup. So the general idea is that a "vagrant push" actually can do or trigger many different things. Hashicorp, the creators of Vagrant, calls each of these "things" a push strategy. The current types of push strategies are:

这一切都取决于您的应用程序,项目,手头的团队以及您当前的工作流程设置。 因此,一般的想法是,“ 无所事事的推动 ”实际上可以完成或触发许多不同的事情。 Vagrant的创建者Hashicorp将这些“事物”中的每一个称为推动策略 。 当前的推送策略类型为:

  • FTP/SFTP strategy: Copying all files somewhere via FTP/SFTP

    FTP / SFTP策略 :通过FTP / SFTP将所有文件复制到某处
  • Heroku strategy: Deploying your code to Heroku

    Heroku策略 :将代码部署到Heroku
  • Atlas strategy: Pushing your code up to Hashicorp's Atlas

    Atlas策略 :将代码推向Hashicorp的Atlas
  • Local Execution strategy: Invoke an arbitrary shell command or script

    本地执行策略 :调用任意的shell命令或脚本

Since you have all these options, you can easily change up your Push Strategy as your application grows.

由于具有所有这些选项,因此您可以随着应用程序的增长轻松地更改推送策略。

推策略 (Push Strategies)

FTP / SFTP (FTP / SFTP)

ftp

The FTP / SFTP push strategy is dead simple. All it does is copy your files to another location via FTP / SFTP. This can be really useful for super simple deployments, small apps, or even small sites like WordPress.

FTP / SFTP推送策略非常简单。 它所做的就是通过FTP / SFTP将文件复制到另一个位置。 这对于超级简单的部署,小型应用程序甚至是WordPress之类的小型站点而言确实非常有用。

Heroku策略 (Heroku Strategy)

heroku

Heroku is a platform that takes the pain out of hosting. With Heroku, you can easily deploy all types (PHP, Ruby, Node, Python ,etc.) applications on easily scalable infrastructure. Heroku uses git for deployment. Running "vagrant push" with the Heroku strategy will push only your committed changes to Heroku.

Heroku是一个减轻托管负担的平台。 使用Heroku,您可以在易于扩展的基础架构上轻松部署所有类型(PHP,Ruby,Node,Python等)的应用程序。 Heroku使用git进行部署。 使用Heroku策略运行“无用推送”只会将您已提交的更改推送到Heroku。

地图集策略 (Atlas Strategy)

ci

Atlas is Hashicorp's commericial offering of integrating all their open source tools - Vagrant, Packer, Terraform, Consul - into one smooth development workflow for you.

Atlas是Hashicorp的所有的开源工具集成的提供商业产品- 放浪帕克Terraform领事 -进入一个平稳发展的工作流程为您服务。

I'm in no way an expert on using their platform, but the process as I understand it, for say building a simple LAMP stack based application, would go roughly something like this:

我绝不是使用他们的平台的专家,但是据我了解,例如构建一个基于LAMP堆栈的简单应用程序的过程大致如下:

  • Use Packer.io to build identical LAMP machine images (aka to be used in each developer's local Vagrant VirtualBox environment and on the remote production server such as Amazon)

    使用Packer.io构建相同的LAMP机器映像(也可以在每个开发人员的本地Vagrant VirtualBox环境和远程生产服务器(如Amazon)中使用)
  • Use Vagrant to develop the application locally and comfortably

    使用Vagrant在本地舒适地开发应用程序
  • Use Terraform to build out the infrastructure for production (maybe building out nodes connected to a load balancer, a separate database server, etc.)

    使用Terraform构建用于生产的基础架构(也许构建连接到负载平衡器的节点,单独的数据库服务器等)
  • Push your code from Vagrant to Atlas, upload your machine configurations from Packer, and move your infrastructure settings from Terraform up to Atlas

    将您的代码从Vagrant推送到Atlas,从Packer上传您的计算机配置,并将基础结构设置从Terraform移至Atlas
  • Use Atlas to combine and deploy all the separate pieces together

    使用Atlas将所有单独的部分组合并部署在一起
  • Maintain and monitor with Consul

    与领事保持和监督

In a sense, the concept is you're not just deploying code to different servers anymore, but, instead, you're also deploying servers and infrastructure all from one place.

从某种意义上说,这个概念是您不再只是将代码部署到不同的服务器上,而是还要从一个地方部署服务器和基础结构。

Atlas essentially lets you manage all these things on their platform so you can pick and choose your apps and their deployments in one smooth process. Big teams will probably eat all this up, while smaller teams might struggle with the added overhead of using it. I imagine in time that this whole process and concept will become configurable and painless for less server savvy people.

Atlas本质上使您可以在其平台上管理所有这些内容,因此您可以在一个平稳的过程中选择和选择应用程序及其部署。 大型团队可能会吃光所有这些,而小型团队可能会为使用它带来的额外开销而苦苦挣扎。 我可以想象到,对于那些精通服务器的人来说,整个过程和概念将变得可配置且不费吹灰之力。

本地执行策略 (Local Execution Strategy)

ci

You can also use Vagrant Push to initiate a custom command or shell script. This can be useful for team's or people who alredy have deployment systems or some sort of continuous integration built out. This way you're able to integrate vagrant seamlessly into your existing workflow with little disruption or changes.

您也可以使用Vagrant Push来启动自定义命令或Shell脚本。 这对于团队或渴望部署系统或建立某种持续集成的人员很有用。 这样,您就可以将流浪汉无缝地集成到现有工作流程中,而不会造成任何干扰或更改。

快速演示 (A Quick Demo)

For our simple demo, I'll show you a simple workflow using Scotch Box, Digital Ocean, and the FTP / SFTP Vagrant Push strategy.

对于我们的简单演示,我将向您展示一个使用Scotch Box,Digital Ocean和FTP / SFTP Vagrant Push策略的简单工作流程。

克隆并运行苏格兰威士忌盒 (Clone and Run Scotch Box)

The first step is to clone Scotch Box. If you aren't familiar with Scotch Box, you can check out the article on it here. In short, it's a preconfigured Vagrant LAMP Box that's dead simple and hassle free. Just follow these steps:

第一步是克隆苏格兰威士忌盒。 如果您不熟悉Scotch Box,可以在此处查看有关它的文章。 简而言之,这是一个预先配置的Vagrant LAMP Box,非常简单且无麻烦。 只需按照以下步骤操作:

git clone https://github.com/scotch-io/scotch-box.git my-project
cd my-project
vagrant up

loader

Now that we have a full lamp stack, we can now see a preview of it at 192.168.33.10. Since we're doing a static application, let's quickly replace index.php in the public folder with a Less and Gulp Starter I made.

现在我们有一个完整的灯堆,现在可以在192.168.33.10看到它的预览。 由于我们正在做一个静态应用程序,因此让我们用我制作的Less and Gulp Starter快速替换公用文件夹中的index.php。

cd public
rm index.php
git clone https://github.com/scotch-io/gulp-and-less-starter-kit .

设置数字海洋滴 (Setup a Digital Ocean Droplet)

Now that we have a local application, let's setup a production server. We're using Digital Ocean, but you can use any server you want really. The only thing to note about the server is to make sure you have FTP / SFTP access with a username and password.

现在我们有了本地应用程序,让我们设置生产服务器。 我们正在使用Digital Ocean,但是您可以使用任何您真正想要的服务器。 关于服务器的唯一要注意的是确保您具有用户名和密码的FTP / SFTP访问。

Screen Shot 2015-02-08 at 2.33.25 PM

配置流浪文件 (Configure the Vagrant File)

Now that we have a web server setup, we'll need to configure the Vagrantfile. In the Scotch Box Vagrantfile, let's add the Vagrant Push config to our settings.

现在我们有了Web服务器的设置,我们需要配置Vagrantfile。 在Scotch Box Vagrantfile中,让我们将Vagrant Push配置添加到我们的设置中。

config.push.define "ftp" do |push|

        # Login Credentials
        push.host = "104.131.46.134"
        push.username = "root"
        push.password = "password"

        # FTP vs SFTP
        push.secure = "true"

        # Where to copy the files on the server
        push.destination = "/var/www/html"

        # Where are App is
        push.dir = "public"
    end

Now, reload Vagrant with vagrant reload to save the settings.

现在,用vagrant reload重新加载Vagrant以保存设置。

运行无业游民推 (Run Vagrant Push)

That's all there is to set this up. Now, each time we run vagrant push it will package and copy the files to the Digital Ocean server we setup.

这就是设置的全部。 现在,每次我们运行vagrant push ,它将打包并将文件复制到我们设置的Digital Ocean服务器。

vagrant push

If you're getting errors, trying SSHing into the box first and setting a new password. You can adjust this in many different ways. For example, you can have a setup for staging and production so you're running vagrant push staging or vagrant push production. You can also configure a bunch of custom rules for your setup like excluding or including a specific file. A good example of this could be vagrant push docs.

如果您遇到错误,请先尝试通过SSH进入框中并设置新密码。 您可以通过许多不同的方式进行调整。 例如,你可以有分期和生产,使你在运行安装vagrant push stagingvagrant push production 。 您还可以为设置配置一堆自定义规则,例如排除或包括特定文件。 一个很好的例子就是vagrant push docs

结论 (Conclusion)

Having a solid workflow is infinitely important to successful development. With Vagrant Push, Vagrant makes the development process easy from start to finish.

拥有可靠的工作流程对于成功开发至关重要。 借助Vagrant Push,Vagrant使开发过程从头到尾变得容易。

If you're interested in learning more about Vagrant Push, check out these articles:

如果您有兴趣了解有关Vagrant Push的更多信息,请查看以下文章:

If you want to learn more about Vagrant, check out our other articles:

如果您想了解有关Vagrant的更多信息,请查看我们的其他文章:

翻译自: https://scotch.io/tutorials/getting-started-with-vagrant-push

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值