部署Go应用程序

huangapple go评论85阅读模式
英文:

Deploying Go App

问题

我有一个用Go编写的REST API端点,我想知道最佳的部署方式是什么。我知道使用Google App Engine可能会让我的部署更容易。但是,假设我想在AWS上部署它,我有哪些选项/流程/步骤可供选择?有哪些最佳实践?我需要编写自己的任务来构建、SCP和运行它吗?

我对尝试使用Fabric创建部署任务的选项很感兴趣。

英文:

I have a REST API endpoint written in Go and I am wondering what is the best way to deploy it. I know that using Google App Engine would probably make my life easier in terms of deployment. But, suppose that I want to deploy this on AWS. What options/process/procedures do I have. What are some of the best practices out there? Do I need to write my own task to build, SCP and run it?

One option that I am interested in trying is using Fabric to create deployment tasks.

答案1

得分: 9

刚刚从Mountain West DevOps回来,我们在那里讨论了这个问题,非常多的讨论。(虽然不是针对Go,而是一般性的讨论。)

简洁地说,我只能说:这取决于情况。

对于一个不需要高并发的简单应用程序,你可以手动启动一个实例,将二进制文件放在上面,运行它,然后就完成了。(如果你不是在生产平台上开发,你可以交叉编译你的Go二进制文件。)

对于稍微更自动化一些的情况,你可以编写一个Python脚本,使用boto/ssh将最新的二进制文件上传并在EC2实例上运行。

虽然Go程序通常相当安全(尤其是如果你进行了测试),但为了更可靠,你可以将二进制文件作为服务(daemonize)运行,这样如果出现崩溃,它将重新运行。

如果需要更多的自动化,可以使用像Jenkins或Travis这样的CI工具。可以配置这些工具,在提交代码到特定分支或应用标签时自动运行部署脚本。

如果需要更强大的自动化,可以使用PackerChef等工具。除非你的需求非常复杂,否则我建议先从Packer开始。Packer的开发者今天谈到了它,它看起来简单而强大。Chef服务于多个企业,但对你来说可能过于复杂。

简而言之,对于Go程序,基本思路就是将二进制文件复制到生产服务器上并运行。就是这么简单。如何自动化或可靠地执行这个过程取决于你的需求和首选工作流程。

进一步阅读:http://www.reddit.com/r/golang/comments/1r0q79/pushing_and_building_code_to_production/,特别是:https://medium.com/p/528af8ee1a58

英文:

Just got back from Mountain West DevOps today where we talked about this, a lot. (Not for Go specifically, but in general.)

To be concise, all I can say is: it depends.

For a simple application that doesn't receive high use, you might just manually spin up an instance, plop the binary onto it, run it, and then you're done. (You can cross-compile your Go binary if you're not developing on the production platform.)

For slightly more automation, you might write a Python script that uploads and runs the latest binary to an EC2 instance for you (using boto/ssh).

Even though Go programs are usually pretty safe (especially if you test), for more reliability, you might daemonize the binary (make it a service) so that it will run again if it crashes for some reason.

For even more autonomy, use a CI utility like Jenkins or Travis. These can be configured to run deployment scripts automatically when you commit code to a certain branch or apply tags.

For more powerful automation, you can take it up another notch and use tools like Packer or Chef. I'd start with Packer unless your needs are really intense. The Packer developer talked about it today and it looks simple and powerful. Chef serves several enterprises, but might be overkill for you.

Here's the short of it: the basic idea with Go programs is that you just need to copy the binary onto the production server and run it. It's that simple. How you automate that or do it reliably is up to you, depending on your needs and preferred workflow.

Further reading: http://www.reddit.com/r/golang/comments/1r0q79/pushing_and_building_code_to_production/ and specifically: https://medium.com/p/528af8ee1a58

huangapple
  • 本文由 发表于 2014年3月20日 02:14:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/22514669.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定