英文:
Deploying Golang Applications to AWS OPSWORKS
问题
在过去的几个月里,我对AWS OpsWorks部署过程(特别是针对Node.js的部署)有了一些了解,但Go的部署似乎是另一回事。
根据我所了解的情况,以下是成功进行Go部署所需的步骤:
- 在EC2实例上安装Go
- 从GitHub拉取私有存储库
- 拉取所有依赖项
- 为实例的架构编译主要包
- 使用一些标志启动二进制文件
我在各个地方阅读的内容似乎都强调了Go部署的简便性,因为依赖项已包含在二进制文件中,但这似乎意味着您需要在开发环境中编译应用程序,然后将其推送到云端。这似乎不适用于开发团队。
https://github.com/crowdmob/chef-golang-web-server-cookbook
我一直在尝试使用CrowdMob的Chef脚本,但一直没有成功。我一直遇到以下类似的错误:
[2014-08-01T16:08:22+00:00] WARN: Cookbook 'templates' is empty or entirely chefignored at /opt/aws/opsworks/current/merged-cookbooks/templates
在部署过程中,处理依赖项的正确方法是什么?
在使用Chef将Go部署到AWS上是否有已经确立的做法?
英文:
Over the last few months I've become familiar with the AWS OpsWorks deployment process as it pertain to Node.js - deployment for Go seems to be another animal.
From what I've gathered, this is what I need to compile a successful Go deployment:
- Install go on the EC2 box
- Pull the private repository from GitHub
- Pull in all dependencies
- Compile the main package for the box's arch
- Start the binary with a couple of flags that I use
Everywhere I have read seems to tout the ease of Go deployments because dependencies are included in the binary, but that seems to imply that you are compiling the application in your development environment and pushing that up to the cloud. This doesn't seem like a process that works well across a development team.
https://github.com/crowdmob/chef-golang-web-server-cookbook
I have been attempting to get the Chef Scripts from CrowdMob working, but to no avail. I continue to get errors that look like this:
[2014-08-01T16:08:22+00:00] WARN: Cookbook 'templates' is empty or entirely chefignored at /opt/aws/opsworks/current/merged-cookbooks/templates
What is the proper way to deal with dependencies during deployment?
Are there any established practices for deploying Go onto AWS with Chef?
答案1
得分: 3
使用类似CircleCi、Travis或你自己设置的Jenkins这样的持续集成服务。
在持续集成服务上:
- 添加一个GitHub提交后钩子。
- 测试/构建二进制文件。
- 创建zip文件作为构建产物。
在这一点上,你可以使用AWS命令行和从该版本创建的zip文件,在Elastic Beanstalk上创建一个新版本。
venv/bin/aws elasticbeanstalk create-application-version ...
然后只需从EB仪表板中选择要部署的版本。
对于简单的服务来说,使用Chef可能有些过度,我认为使用Docker提供了一个简单的工作流程。
英文:
Use a continuous integration service like CircleCi, Travis or your own setup Jenkins.
On the Continuous integration service then
- Add a github post commit hook .
- Test / Build the binary
- Create the zip file as artifact
At this point you can create an new version on Elastic Beanstalk using the AWS commandline and the zip file created from this version.
venv/bin/aws elasticbeanstalk create-application-version ...
Then just select which version to deploy from the EB dashboard.
For simple services using Chef is overkill IMHO. Docker offers a simple workflow.
答案2
得分: 2
使用Docker容器选项,然后使用elastic beanstalk的命令行客户端在项目根目录中初始化您的环境,然后您可以在同一位置简单地执行'git aws.push'。
在您的项目中正确配置了Dockerfile
并将其推送到eb后,EBS的Docker容器应用程序将拉取安装了golang的正确镜像,然后在您的项目依赖项上执行go get
,然后编译和运行您的应用程序。听起来更复杂,但实际上非常简单。
以下是我为在EBS上运行简单的golang web应用程序制作的视频演示。上传项目的方法不使用git
。相反,我将其压缩并上传,但推荐使用git方法(我也使用)来自动化部署。
YouTube:如何在Amazon的Elastic Beanstalk上运行go web应用程序
英文:
Use the Docker container option and then use elastic beanstalk's command-line client to initialize your environment in the project root directory and then you can simply do a 'git aws.push' from the same place.
With the correctly configured Dockerfile
in your project and pushed to eb, the EBS' docker container app will pull the correct image with golang installed, then do a go get
on your projects dependencies, and then compile and run your app. It sounds way more complicated but it's actually very easy.
Below is a link to a video walkthrough I did for running a simple golang webapp on EBS. The method for uploading the project does not use git
. Instead, I zip it up and upload it, but the git method is recommended (and I do it) for automating deployment.
YouTube: How to run a go web app on Amazon's Elastic Beanstalk
答案3
得分: 1
我也遇到了一些在Elastic Beanstalk和Go中设置良好的构建过程的问题。我不想使用Docker,而且似乎所有人都在朝这个方向发展。所以,你可以看一下这个项目:https://github.com/battle-arena/heimdall
在那里,你会找到一个使用Buildfile
和Procfile
的自定义设置。我依赖于一个CI系统来构建发布包。
基本上,我做了以下几步:
- 将提交的代码钩子到一个CI系统上
- 在CI系统上运行测试和
install.sh
(如果一切正常) install.sh
将创建一个构建文件夹和一个结构,然后使用aws-cli
工具将其发送到Elastic Beanstalk- 在发送到EB之后,
Buildfile
将运行build.sh
,该脚本将解压缩的包以正确的结构进行处理,并运行go get ./...
和go build
Procfile
将运行生成的二进制文件
我认为结果非常好,你可以在任何CI工具中使用它。
英文:
I also had some problems to setup a good building process with Elastic Beanstalk and Go.. I don't want to use Docker, and all the people seems to be going on this direction.. so.. you can take a look at this project: https://github.com/battle-arena/heimdall
There you will find a custom setup using the Buildfile
and the Procfile
.. and I rely on a CI system to build the release package...
Basically I do the following:
- Hook the commits to a CI system
- On the CI system I run the test and the
install.sh
if all good - The
install.sh
will create a build folder and a structure that will be sended to the Elastic Beanstalk with theaws-cli
tool - After send to the
EB
theBuildfile
will run thebuild.sh
that will basically extract the compressed package with the proper structure, and run ago get ./...
andgo build
- The
Procfile
will run the generated binary
I think the result is pretty good, and you can use with any CI tool.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论