如何使用Ninefold设置连续部署

tech2023-07-04  107

This post was sponsored by Ninefold. Thank you for supporting the sponsors who make SitePoint possible!

该帖子由Ninefold赞助。 感谢您支持使SitePoint成为可能的赞助商!

I can remember back in the day, nine-ish years ago, when deployment was a manual process. Sometimes, in took 99 minutes to deploy even the simplest of sites. On the Tedium and Frustration Scale, deployment was a solid ‘9’.

我可以回想起九年前的一天,当时部署是一个手动过程。 有时,即使是最简单的网站,也要花99分钟才能部署。 在Tedium and Frustration量表上,部署是可靠的“ 9”。

Thankfully, those days are behind us. With Continuous Integration having grown into a common, nay expected, practice, how could things get better? The answer? Continuous Deployment. Now, let’s get our terms straight, because there are about 999 ways that Continuous Deployment can be defined, so I’ll pick the one I like.

幸运的是,那些日子已经过去了。 随着持续集成已成为一种普遍的,无法预期的实践,情况如何会变得更好? 答案? 持续部署。 现在,让我们直接讲一下术语,因为可以定义大约999种方法来定义持续部署,因此我将选择我喜欢的方法。

Continuous Deployment is the practice of automatically deploying every code change that passes automated tests to production.

连续部署是一种自动部署将自动测试传递到生产的每个代码更改的实践。

This is not the same as Continuous Delivery, where you automatically deliver code changes to a staging environment where rigorous integration testing ensues. Continuous Deployment (CDep for the rest of this article) means, you make a change, push it to the main repository, the tests run AND pass, and the code is deployed to production. BOOM! (Incidentally, this post and I agree on these definitions.)

这与“ 持续交付”不同 ,在“ 持续交付”中 ,您将代码更改自动交付到需要进行严格集成测试的登台环境。 连续部署(本文其余部分为CDep)意味着您进行更改,将其推送到主存储库,运行测试并通过,然后将代码部署到生产中。 繁荣! (顺便说一句, 这个职位和我同意这些定义。)

CDep is not for the weak or weakly test-covered. Those who dare attempt CDep have great confidence that the automated tests cover all the functionality of the application. This is no small feat. I would say 99.999% of projects probably don’t have the test coverage to pull off CDep. But for those that make the effort and have the discipline, their rewards are great: Confidence that changes won’t cause regressions and that you won’t be losing time doing manual deployments. The fruits of CDep labor are the sweetest on the vine.

CDep不是针对弱或弱测试覆盖的。 那些敢于尝试CDep的人很有信心,自动化测试涵盖了应用程序的所有功能。 这是不小的壮举。 我想说99.999%的项目可能没有涵盖CDep的测试范围。 但是对于那些努力工作并有纪律的人来说,他们的回报是巨大的:确信更改不会导致性能下降,并且您不会浪费时间进行手动部署。 CDep劳动的果实是葡萄藤上最甜的。

The growing ubiquity of CDep is directly attributable to the rise of the Platforms-as-a-Service (PaaS). There are many PaaS, and today we’re going to check out Ninefold.

CDep无处不在的增长直接归因于平台即服务(PaaS)的兴起。 PaaS有很多,今天我们要看看Ninefold。

Ninefold is a PaaS that specializes in hosting Rails applications. Alongside the ease of deployment that comes with most PaaS offerings, Ninefold also offers numerous plugins for things like Redis, PostgreSQL, SendGrid, New Relic, Memcached, and others. A critical differentiator for Ninefold is the ability to add raw Virtual Servers. If there isn’t a plugin for a piece of software you want to leverage, simply spin up a VM and host it yourself.

Ninefold是一种Pa​​aS,专门用于托管Rails应用程序。 除了大多数PaaS产品附带的易于部署之外,Ninefold还为Redis,PostgreSQL,SendGrid,New Relic,Memcached等提供了许多插件。 Ninefold的一个关键区别在于添加原始虚拟服务器的能力。 如果没有要使用的软件插件,则只需启动一个VM并自己托管它。

Ninefold also integrates with various Continuous Integration platforms, such as Codeship, TravisCI, and CircleCI.

Ninefold还与各种持续集成平台集成,例如Codeship , TravisCI和CircleCI 。

My demonstration today will show you how to use Ninefold and Codeship to easily create a CDep workflow for a Rails application.

今天的演示将向您展示如何使用Ninefold和Codeship轻松为Rails应用程序创建CDep工作流程。

九件事 (NineThings)

Our application is a simple Rails app that services the critical needs of those who desire to list things that come in multiples of 9. Users can add a thing and its nine-multiple to the growing list of NineThings. This is THE /insert current big-time social app here/-killer. Here’s what it looks like:

我们的应用程序是一个简单的Rails应用程序,可满足那些希望以9的倍数列出的事物的用户的关键需求。用户可以将事物及其9倍数添加到不断增长的NineThings列表中。 这是/在此处插入当前的大型社交应用程序/杀手。 看起来是这样的:

Isn’t it beautiful? I am not going into detail about how it’s setup, simply because it is a just-use-the-generator Rails app with the foundation-rails gem added to make it a bit cleaner. The NineThings model-view-controller sequence was generated using the scaffold generator. Oh, and I am using PostgreSQL. Nothing special in this setup.

不漂亮吗 我不会详细介绍它的设置方式,仅因为它是一个刚刚使用的发电机Rails应用程序,并且添加了foundation-rails gem使其更加简洁。 NineThings模型-视图-控制器序列是使用scaffold生成器生成的。 哦,我在用PostgreSQL。 此设置没有什么特别的。

The source is in this Github repository, which is what I will use when registering the application with Ninefold. Feel free to fork the app (or pick your own Rails app) and follow along.

源在此Github存储库中 ,这是我在Ninefold中注册应用程序时将使用的存储库 。 随意派生该应用程序(或选择自己的Rails应用程序)并继续。

注册九折 (Signing Up for Ninefold)

In order to use Ninefold as our PaaS platform, you’ll need to sign up. Go to the Ninefold site and fill out the sign up form. Submitting the form lands you on your dashboard with a welcome message.

为了使用Ninefold作为我们的PaaS平台,您需要注册。 转到Ninefold网站并填写注册表格。 提交表单的土地,你在你的仪表板欢迎消息。

Close the welcome screen and click on “Deploy New App”. The first piece of information Ninefold requires is the location of your source code repository. In my case, it’s the Github repository I mentioned previously. So, I click on “Sign in with Github”, approve what Ninefold wants to do, and a list of my Github organizations and repositories show up on the dashboard. That’s cool.

关闭欢迎屏幕,然后单击“部署新应用”。 Ninefold要求的第一条信息是源代码存储库的位置。 就我而言,这是我之前提到的Github存储库。 因此,我单击“使用Github登录”,批准Ninefold想要做的事情,并且我的Github组织和存储库的列表显示在仪表板上。 这很酷。

After selecting the repository and branch for Ninefold to watch, you need to decide if you want Ninefold to deploy on every push to the selected branch. Let’s say ‘Yes’ for now and move on to the next step and setup our deployment environment.

选择供Ninefold观看的存储库和分支之后,您需要确定是否要在每次推送到所选分支时都部署Ninefold。 让我们暂时说“是”,然后继续下一步并设置我们的部署环境。

Ninefold offers various infrastructure options based on the scalability needs of your application. For this application, I am just testing things out and want to keep it cheap/free. I can do that using the 1.5GB option for the web server, the smallest PostgreSQL database, and saying ‘No’ to background workers (though Ninefold does not charge for those). That shows a monthly cost of $46.91, and Ninefold will waive the first $50 of my bill under a current promotion, so perfect. Next step. please.

Ninefold根据您的应用程序的可伸缩性需求提供各种基础结构选项。 对于此应用程序,我只是测试一下东西,并希望使其保持便宜/免费。 我可以使用1.5GB的Web服务器选项(最小的PostgreSQL数据库),对后台工作人员说“不”(尽管Ninefold对此不收费)。 这表明每月费用为46.91 美元,在目前的促销活动下 ,Ninefold 将免收我账单中的前50美元 ,非常完美。 下一步。 请。

The last details consist of the desired Ruby version, application name, plugins, and any custom deployment plans to run. My app isn’t going to use any of these, so I excitedly click “Deploy”.

最后的详细信息包括所需的Ruby版本,应用程序名称,插件以及要运行的任何自定义部署计划。 我的应用程序不会使用其中任何一个,因此我激动地单击“部署”。

It takes a few minutes to deploy, so this is a good time to introduce Brutus, Ninefold’s shaven yak. Brutus comes with the Ninefold CLI, which can be installed with the ninefold gem (gem install ninefold or add it to your Gemfile and bundle). Open up a terminal, go to your Rails app project directory, and install the gem.

部署需要几分钟,因此这是介绍Ninefold剃过的牛Brutus的好时机。 Brutus附带了Ninefold CLI,可以与ninefold gem一起安装( gem install ninefold或将其添加到您的Gemfile和bundle )。 打开一个终端,转到Rails应用程序项目目录,然后安装gem。

The CLI is based around a ninefold command, sensibly. Typing ninefold gives you an idea of the available options:

CLI明智地基于9 ninefold命令。 键入ninefold可让您ninefold了解可用选项:

The first thing to do is sign in. Type ninefold signin and enter your Ninefold user information. Brutus will run off and sign you in. Once signed in, the CLI allows you to interact with your Ninefold applications using the ninefold app command. ninefold app list lists my single ninethings application. (BTW: There are also ninefold brutus commands where you can make our favorite yak chew and say stuff. Try it, it’s fun.)

要做的第一件事是登录。键入ninefold signin并输入您的Ninefold用户信息。 Brutus将运行并登录。一旦登录,CLI允许您使用ninefold app命令与您的Ninefold应用程序进行交互。 ninefold app list列出了我的单个ninefold app list程序。 (顺便说一句:还有ninefold brutus命令,您可以在其中进行我们最喜欢的ninefold brutus嚼和说些什么。尝试一下,这很有趣。)

I won’t go over all the CLI commands, as they are pretty self-explanatory. The one I will highlight is ninefold app redeploy_command, which lists the CLI command to redeploy your application. In my case:

我不会介绍所有的CLI命令,因为它们很容易解释。 我将重点介绍的是ninefold app redeploy_command ,它列出了重新部署应用程序的CLI命令。 就我而言:

AUTH_TOKEN=<my auth token> APP_ID=10906 ninefold app redeploy --robot --sure

This command is important because it’s the easiest way to get your auth token and application id, which is needed (in some cases) if you want to redeploy the app outside of the Ninefold dashboard. I will not be using that command today, but if you’re on Ninefold, it’s good to know.

此命令很重要,因为它是获取身份验证令牌和应用程序ID的最简单方法,在某些情况下(如果要在Ninefold仪表板之外重新部署应用程序,这是必需的)。 我今天不会使用该命令,但是如果您使用的是Ninefold,则很高兴知道。

OK, by now, your Ninefold app should be deployed. The Ninefold application dashboard looks like:

好的,到目前为止,应该已经部署了您的Ninefold应用程序。 Ninefold应用程序仪表板如下所示:

The “Overview” tab has all the information you would expect: application name, URL, repository, branch, etc. The “Deployment URL” is something we’ll use later to get our CDep on. Notice the “Automatically redeploy my app when I push updates to my code” checkbox is enabled.

“概述”选项卡提供了您期望的所有信息:应用程序名称,URL,存储库,分支等。“部署URL”是我们稍后将用来使用CDep的内容。 请注意,“当我将更新推送到我的代码时自动重新部署我的应用程序”复选框已启用。

The “Configuration” tab allows for environment variables, custom deploy commands, and plugin configuration. The remaining tabs are self-explanatory, so you can explore those on your own.

“配置”选项卡允许环境变量,自定义部署命令和插件配置。 其余选项卡是不言自明的,因此您可以自己浏览。

Go back to the “Overview” tab an click on the “Domains” link. Your app will open up and you can add/see all the NineThings. We’re on the internets. Let’s push a trivial change.

返回“概述”选项卡,然后单击“域”链接。 您的应用程序将打开,您可以添加/查看所有NineThings。 我们正在上网。 让我们推动一个微不足道的改变。

# app/views/layouts/application.html.erb <body> <div class="row"> <h1>All the NineThings!!</h1> <h2>Let's get over 9000 NineThings!</h2> <!-- I ADDED THIS --> <%= yield %> </div> <%= javascript_include_tag "application" %> </body>

A trivial change to our layout. Commit the change and push it to your Github repo, making sure that you are using the master branch. Go back to the Ninefold application dashboard and wait a few seconds. The following notification will pop-up in the lower-left hand corner:

对我们的布局进行了微不足道的更改。 提交更改并将其推送到您的Github存储库,确保您使用的是master分支。 返回Ninefold应用程序仪表板,然后等待几秒钟。 以下通知将在左下角弹出:

Excellent. Right now, we are in the realm of Continuous Delivery (if we had good tests). We want more, we want Continuous Deployment. This is where CodeShip comes in.

优秀的。 目前,我们处于持续交付的领域(如果我们有良好的测试)。 我们想要更多,我们想要持续部署。 这是CodeShip出现的地方。

代号 (Codeship)

Codeship is a company that offers Continuous Integration and Delivery (and, today, Deployment) as a service. We’ve written about Codeship before, but in a nutshell, Codeship will watch your source code repository for changes, running your tests for each change. With a bit of configuration, Codeship can also notify you of failures/successes, run just about any command, and/or deploy your code. That last one is our focus today.

Codeship是一家提供持续集成和交付(以及今天的部署)服务的公司。 之前 , 我们已经写过有关Codeship的文章 ,但简而言之,Codeship将监视源代码存储库中的更改,并针对每个更改运行测试。 通过一些配置,Codeship还可以通知您失败/成功,几乎运行任何命令和/或部署您的代码。 这是我们今天的重点。

Go ahead and sign up for a Codeship account. When you first sign up, Codeship onboards you with a wizard to create your first project.

继续并注册一个Codeship帐户。 首次注册时,Codeship会附带向导来创建您的第一个项目。

You’ll be prompted to pick your source code provider, either Github or Bitbucket. It’ll then connect to that provider (with your approval, of course) and list your repositories. Pick the ninethings repo.

系统将提示您选择您的源代码提供程序,即Github或Bitbucket。 然后它将连接到该提供程序(当然需要您的批准)并列出您的存储库。 选择九号仓库。

At that point, you need to specify your setup and test commands:

此时,您需要指定设置和测试命令:

Setup commands run to get your project to the point where the tests are ready to go. Test commands run your tests. In our case, we install the Ruby version of our choice, bundle, set the RAILS_ENV, and load the schema. Codeship had this all setup by default, but you can change or add whatever you need.

运行安装程序命令可使您的项目到达可以进行测试的地步。 测试命令运行您的测试。 在本例中,我们将安装所选的Ruby版本,进行捆绑,设置RAILS_ENV并加载模式。 默认情况下,Codeship具有所有这些设置,但是您可以更改或添加所需的任何内容。

Once you’re through the wizard, you’ll land on the project page. At the top of the page, Codeship has some suggestions on what to do next:

完成向导后,您将进入项目页面。 在页面顶部,Codeship提供了有关下一步操作的一些建议:

Well, lookie there! It’s like they read our mind. The first button is “Set up Continuous Deployment”. I say we click on it.

好吧,那边的家伙! 就像他们读我们的思想一样。 第一个按钮是“设置持续部署”。 我说我们点击它。

Codeship offers many options to deploy after a successful build. Ninefold isn’t on one of those buttons, but that is because there are 9,999 ways to redeploy your application on Ninefold. It may be the easiest service to integrate with in the nine galaxies.

成功构建后,Codeship提供了许多可供部署的选项。 Ninefold不在这些按钮之一上,但这是因为有9,999种方法可以在Ninefold上重新部署您的应用程序。 与这九个星系整合可能是最简单的服务。

Straight from the Codeship blog, setting up deployment to Ninefold is easy as:

直接来自Codeship博客 ,将部署设置为Ninefold很容易,因为:

Clicking the “$script” button

点击“ $ script”按钮 Enter your Ninefold “Deployment URL”

输入您的Ninefold“部署URL” Done.

做完了

Where do you get the Deployment URL? The savvy reader remembers it was on the Ninefold application dashboard “Overview” page:

您从哪里获得部署URL? 精明的读者记得它在Ninefold应用程序仪表板的“概述”页面上:

There it is. Also, be sure to uncheck the “Automatically deploy” check box. Otherwise, Ninefold will deploy your app on every push, regardless of passing tests.

在那里。 另外,请确保取消选中 “自动部署”复选框。 否则,Ninefold将在每次推送时部署您的应用程序,而不管通过测试如何。

Ok, return to the Codeship.io project page and paste in that Deployment URL.

好的,返回到Codeship.io项目页面,然后粘贴该Deployment URL。

Save the step, and we’re done. Really.

保存该步骤,我们就完成了。 真。

CDep在房子里 (CDep in the House)

If you don’t believe me, I’ll prove it. Let’s make another noticeable change to our app:

如果您不相信我,我会证明这一点。 让我们对应用程序进行另一个明显的更改:

# app/views/layouts/application.html.erb <body> <div class="row"> <h1>All the NineThings!!</h1> <h2>Let's get over 9000 NineThings!</h2> <h3>Over 9000!!</h3> <!-- I ADDED THIS --> <%= yield %> </div> <%= javascript_include_tag "application" %> </body>

Now, introduce a test failure into the app, like so:

现在,将测试失败引入应用程序,如下所示:

# test/models/nine_thing_test.rb class NineThingTest < ActiveSupport::TestCase test "the truth" do assert false end end

Running rake in your local app directory will show the failure. Commit and push that change to your GitHub repository. If you’re watching the Codeship.io project page for your project, a build will kick off, like so:

在本地应用程序目录中运行rake将显示失败。 提交更改并将其推送到您的GitHub存储库。 如果您正在查看项目的Codeship.io项目页面,则将开始构建,如下所示:

As you can see, it failed. If you reload the Ninefold hosted app, our h3 is not there.

如您所见,它失败了。 如果您重新加载Ninefold托管应用程序,则我们的h3不存在。

For this next bit, open up two browser windows: one on the Codeship project page and one on the Ninefold app dashboard. Fix the test (change false to true), commit, and push.

接下来,打开两个浏览器窗口:一个在Codeship项目页面上,一个在Ninefold应用程序仪表板上。 修复测试(将false更改为true ),提交并推送。

Codeship runs the build, runs the test, the tests pass, and it deploys to Ninefold. Ninefold then redeploys the app. I told you we were done. On a scale of 1 to 9, I give this whole process a 9+!

Codeship运行构建,运行测试,测试通过,然后部署到Ninefold。 然后,Ninefold重新部署该应用程序。 我告诉你我们做完了。 在1到9的范围内,我给整个过程加了9+!

Reloading the Ninefold application URL will show our change is deployed:

重新加载Ninefold应用程序URL将显示我们的更改已部署:

Voila! We are going to party like it’s 1999.

瞧! 我们将像1999年一样参加聚会。

结语 (Wrapping Up)

Continuous Deployment is the holy grail of making developers lives easier. It gives you a chance to focus on the code, while Ninefold focuses on infrastructure and Codeship focuses on deployment. Hopefully, you’re inspired to get this into your workflow. I guarantee 9X more free time!

持续部署是使开发人员生活更轻松的圣杯。 它使您有机会专注于代码,而Ninefold专注于基础架构,而Codeship专注于部署。 希望您受到启发将其纳入您的工作流程。 我保证有9倍的空闲时间!

翻译自: https://www.sitepoint.com/set-continuous-deployment-ninefold/

相关资源:jdk-8u281-windows-x64.exe
最新回复(0)