![DeployHQ](https://i-blog.csdnimg.cn/blog_migrate/231074d5921f3ba95e3950c123f23f84.webp?x-image-process=image/format,png)
This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.
本文是与SiteGround合作创建的系列文章的一部分。 感谢您支持使SitePoint成为可能的合作伙伴。
问题:部署代码 (The Problem: Deploying Code)
So you have your projects in GitHub, whatever they are — an app you’re working on with a small team, a small business brochure site, an ecommerce platform. You’ve decided to version control them, but you still have little in the way of automated processes in place, and you’re still having to update each of your environments — staging, production, whatever you have — by hand, with FTP. Or you’ve got them pulling down Git changes from a branch.
因此,无论项目是什么,您都可以在GitHub上进行项目-您正在与一个小型团队合作的应用程序,一个小型企业手册网站,一个电子商务平台。 您已经决定对它们进行版本控制,但是您仍然无法实现自动化流程,并且仍然必须通过FTP手动更新每个环境-登台,生产,无论您拥有什么。 或者您让他们从分支中提取Git更改。
This pain is only multiplied if you’re deploying to other development or staging servers too, or you have a load-balanced production machine that needs multiple simultaneous deployments. What you really need is an automated process here, that can either automatically deploy when changes to code are made, or can be ready to do so at the push of a button.
仅当您也要部署到其他开发或登台服务器,或者您的负载平衡的生产机器需要同时进行多个部署时,这种痛苦才会加剧。 您真正需要的是一个自动化过程,该过程可以在更改代码后自动部署,也可以按一下按钮就可以进行。
解决方案:DeployHQ (The Solution: DeployHQ)
DeployHQ can be the link between your Git repository and your servers and do your deployments for you. You can make those deployments automatic (every time you commit to your staging
branch, DeployHQ automatically deploys those changes to your Staging server). You can also trigger deployments manually (deploying to Production server from the production
branch requires you to push the button yourself). This flexibility allows for a maximum of convenience and automaton without taking important safeguards away, like a review of code merged into production, or the schedule by which you update your production website.
DeployHQ可以是您的Git存储库和服务器之间的链接,并可以为您进行部署。 您可以使这些部署自动进行(每次您提交到staging
分支时,DeployHQ都会将这些更改自动部署到staging
服务器)。 您还可以手动触发部署(从production
分支部署到生产服务器需要您自己按下按钮)。 这种灵活性可以在不取消重要保护措施的情况下提供最大的便利性和自动性,例如对合并到生产中的代码的审查或更新生产网站的时间表。
DeployHQ seems especially good for a small company or developer who doesn’t have all of their testing, builds, CI, etc automated yet into cohesive processes, and is really looking for a way to push code to various environments with as little friction as possible.
DeployHQ对于尚未将所有测试,构建,CI等进行自动化但尚未整合到内聚流程中的小型公司或开发人员而言似乎特别有用,并且它确实正在寻找一种方式来将代码推送到各种环境中,并且尽可能减少摩擦。
DeployHQ入门 (Getting Started with DeployHQ)
When you sign up for your DeployHQ account, you’ll login and arrive at the welcome screen.
注册DeployHQ帐户后,您将登录并进入欢迎屏幕。
![alt](https://i-blog.csdnimg.cn/blog_migrate/fac4bbe2abc99715f3e628a45426c90b.webp?x-image-process=image/format,png)
Then, you’ll need to follow a few steps in order to get your deployments up and running!
然后,您需要执行一些步骤才能启动并运行您的部署!
1.准备 (1. Preparation)
In the below examples of configuration, GitHub will be used as the version control system. So, head over to GitHub, and if you don’t already have a project in mind, create a repository. The repository, ideally, will have multiple branches (i.e. “staging”, “production”) just to help demonstrate the functionality available at DeployHQ. Both staging and production branches of a test repository will be used in this demonstration. You can leave this open in a tab, as you’ll need to come back.
在下面的配置示例中,GitHub将用作版本控制系统。 因此,转到GitHub,如果您还没有一个项目,请创建一个存储库。 理想情况下,该存储库将具有多个分支(即“阶段”,“生产”),仅用于帮助演示DeployHQ可用的功能。 测试存储库的暂存分支和生产分支将在此演示中使用。 您可以将其保留在标签中,因为需要返回。
2.创建一个新的DeployHQ项目 (2. Create a New DeployHQ Project)
Right from the welcome screen, hit the “Create a new project” button.
在欢迎屏幕上,单击“创建新项目”按钮。
![alt](https://i-blog.csdnimg.cn/blog_migrate/f8ae935a03b7604bb192ebcde308b709.webp?x-image-process=image/format,png)
You’ll need to give the project a name, and choose the version control system that you’re using. For this example, we’re using GitHub. Then, hit “Create Project”! You’ll see a progress screen, and then, if all goes well, you’ll get a screen that requires you to login (or if already logged in, authorize the app) to access your repository.
您需要给项目起一个名字,然后选择您正在使用的版本控制系统。 对于此示例,我们使用的是GitHub。 然后,点击“创建项目”! 您将看到一个进度屏幕,然后,如果一切顺利,则会出现一个屏幕,要求您登录(或者如果已经登录,则授权应用程序)以访问存储库。
Once you’ve authorized DeployHQ to access your GitHub, you’ll be taken to a screen which shows the organizations you’re connected to (and your personal repositories) with a list of those repositories. Pick one to link your project to, and once this is done, DeployHQ will ask you to provide server information.
授权DeployHQ访问GitHub后,您将进入一个屏幕,其中显示了您所连接的组织(以及您的个人存储库)以及这些存储库的列表。 选择一个将您的项目链接到,然后完成,DeployHQ将要求您提供服务器信息。
3.添加服务器 (3. Adding a Server)
To add a server, you’ll give it an internal name, then pick the protocol with which you’d like to access the server, such as SSH/SFTP
.
要添加服务器,请给它一个内部名称,然后选择您要用来访问服务器的协议,例如SSH/SFTP
。
![alt](https://i-blog.csdnimg.cn/blog_migrate/fa70a2193b4c7e0b1ae9c309ebc0a5c5.webp?x-image-process=image/format,png)
Once you’ve made a choice, more options will open up, where you can fill out information about your website hosting, details like the server’s IP and credentials, the path from the FTP root to get to your website files, etc.
做出选择后,将打开更多选项,您可以在其中填写有关网站托管的信息,服务器IP和凭据之类的详细信息,从FTP根目录到网站文件的路径等。
If you have enough active servers on DeployHQ that you need to group them, you’ll be able to choose a group for this server. You’ll also want to choose which branch of the repository the project is linked to you’ll want to deploy from. Picking staging
will mean that when code is committed to the staging
branch in GitHub, DeployHQ will be picking that up and able to deploy using it.
如果在DeployHQ上有足够的活动服务器需要对它们进行分组,则可以为此服务器选择一个组。 您还希望选择项目要链接到的存储库的哪个分支。 选择staging
意味着将代码提交到GitHub中的staging
分支时,DeployHQ将对其进行提取并能够使用它进行部署。
4.部署 (4. Deployment)
Now that you’ve added your server, click the edit button to edit the server in DeployHQ. You’ll see here both the settings you’ve already chosen for the server, as well as a few more, particularly along the right sidebar.
现在,您已经添加了服务器,单击“编辑”按钮以在DeployHQ中编辑服务器。 您将在此处看到已经为服务器选择的设置,以及其他一些设置,尤其是在右侧栏中。
手动部署 (Manual Deployment)
There may be things that you don’t want entirely automatically deployed. For example, your production branch might need to be vetted or go through a final test run before you push it live, or you may have to do so on a schedule. No problem. Simply toggle off automatic deployments for this server in the settings menu on the right.
您可能不希望某些事情完全自动部署。 例如,在正式上架生产分支之前,可能需要对其进行审查或进行最终测试,或者必须按计划进行。 没问题。 只需在右侧的设置菜单中关闭此服务器的自动部署即可。
![alt](https://i-blog.csdnimg.cn/blog_migrate/f4caed68f658bf153b8fe0aefb5de191.webp?x-image-process=image/format,png)
Then, after pushing some code to the appropriate GitHub branch, you’ll be able to zip over to your DeployHQ project and deploy it manually with just a click or two!
然后,在将一些代码推送到适当的GitHub分支之后,您将能够压缩到DeployHQ项目,并只需单击或单击两次即可手动部署它!
This test site started out with nothing in it. After initializing the GitHub with a starter index.html
and then hitting “deploy” on DeployHQ, here’s what we have:
这个测试站点一开始没有任何内容。 用入门者index.html
初始化GitHub,然后在DeployHQ上单击“ deploy”后,我们可以得到以下内容:
![alt](https://i-blog.csdnimg.cn/blog_migrate/9896e2968193c69702876a2417b4b8f5.webp?x-image-process=image/format,png)
自动部署 (Automatic Deployment)
On the other hand, maybe you want your staging environment to just automatically push changes to the server as soon as you make them in GitHub. Head over and look at that server edit screen, at the right side panel. You’ll see the “Automatic Deployment” option — toggle that on. You’ll also want to copy the URL below it. In the same area, you’ll see that DeployHQ has documentation about automatic deployments to assist if you run into any snags.
另一方面,也许您希望您的暂存环境在GitHub中进行更改后就将更改自动自动推送到服务器。 转到头并查看右侧面板上的服务器编辑屏幕。 您将看到“自动部署”选项-启用它。 您还需要复制下面的URL。 在同一区域中,您会看到DeployHQ 包含有关自动部署的文档 ,如果遇到任何麻烦,它们将为您提供帮助。
Now, pop back over to your GitHub repository and go to the repository’s settings, and Webhooks. Add a new Webhook, chose the URL encoded type, and use the copied URL from your DeployHQ server settings as the URL, and save it. This means that every time commits are pushed to the repository, GitHub will send a payload to DeployHQ. DeployHQ, in turn, will check to see if it’s the correct branch, and if so, queue up and enact a deployment, since you have automatic deployments on.
现在,跳回到GitHub存储库,然后转到存储库的设置和Webhooks。 添加一个新的Webhook,选择URL编码类型,然后使用DeployHQ服务器设置中复制的URL作为URL,然后保存它。 这意味着每次将提交推送到存储库时,GitHub都会将有效负载发送到DeployHQ。 依次,DeployHQ将检查它是否是正确的分支,如果是,请排队并执行部署,因为您已经启用了自动部署。
Excellent! Let’s try it out. Head back to GitHub and update your index.html
file (or a different file if need be). Commit the change, and then take a look at your website.
优秀的! 让我们尝试一下。 返回GitHub并更新您的index.html
文件(或根据需要更改其他文件)。 提交更改,然后查看您的网站。
![alt](https://i-blog.csdnimg.cn/blog_migrate/f7c4dc99616dbd03bc0188591921b852.webp?x-image-process=image/format,png)
DeployHQ has pushed it out there automatically without you even needing to do anything. Great stuff!
DeployHQ会自动将其推出,而您甚至无需执行任何操作。 好东西!
结论 (Conclusions)
DeployHQ definitely isn’t the route to go for large organizations with their own complex needs that surpass this application. But for many, many web developers, services like DeployHQ will save time and energy. Match them up with an amazing host that provides proper SSH or SFTP connection ability, like our partner, SiteGround, and you’re ready to get deploying!
对于具有自身复杂需求(超出此应用程序)的大型组织,DeployHQ绝对不是行之有效的方法。 但是对于许多许多Web开发人员而言,像DeployHQ这样的服务将节省时间和精力。 将它们与提供了适当的SSH或SFTP连接功能的出色主机匹配,例如我们的合作伙伴SiteGround ,您就可以开始部署了!
翻译自: https://www.sitepoint.com/using-deployhq-automate-deployments/