英文:
Elastic Beanstalk Procfile for go
问题
我正在尝试将我的Go Restful服务器程序部署到EC2 Linux上使用Elastic Beanstalk。文档上说我需要在根目录下创建一个Procfile文件,所以我按照以下步骤进行操作:
-
使用以下命令将我的Go程序myapp.go编译为可执行文件:
$ go build -o myapp -i myapp.go
-
在根目录下创建一个名为Procfile的文件,内容如下:
web: myapp
-
将Procfile和myapp可执行文件打包成一个名为
myapp.zip
的压缩文件。
通过Elastic Beanstalk控制台将压缩文件上传到服务器。但是我一直得到Degraded
健康状态和以下警告信息:
>WARN Process termination taking longer than 10 seconds.
有什么建议吗?顺便说一下,我还尝试使用Elastic Beanstalk示例库中提供的简单的application.go
压缩文件进行相同的Procfile操作,但也没有成功。
英文:
I'm trying to deploy my go restful server program to EC2 Linux using Elastic Beanstalk. The document says that I need to create a Procfile at the root. So I did. Here are the steps:
-
Build my go program myapp.go to using
$ go build -o myapp -i myapp.go
-
Create a Procfile with exact name at the root with
web: myapp
-
Zip up the Procfile and the myapp image to a
myapp.zip
file.
Upload to the server via Elastic Beanstalk console. But I keep getting Degraded
health and warning with
>WARN Process termination taking longer than 10 seconds.
Any suggestions. By the way, I tried to use the same procfile procedure on the simple application.go
zip file came from the Elastic Beanstalk example library. It didn't work either.
答案1
得分: 3
我终于成功使用eb客户端将Go应用程序部署到Elastic Beanstalk上了。EB有一些要求:
-
主文件的名称应为
application.go
。 -
确保你的应用程序监听5000端口。
-
在主目录下需要一个Procfile,内容如下:
web: bin/application
-
需要一个Buildfile,内容如下:
make: ./build.sh
-
最后,你需要一个
build.sh
文件,内容如下:#!/usr/bin/env bash # 如果出现错误,停止进程 set -xe # 获取项目所需的所有依赖项 # 例如: go get "github.com/gin-gonic/gin" # 创建EB使用的应用程序二进制文件 GOOS=linux GOARCH=amd64 go build -o bin/application -ldflags="-s -w"
然后,如果你运行eb deploy
(在创建初始eb仓库之后),应该可以正常工作。我在这里编写了一个完整的Gin应用程序在EB上部署的教程。关于使用Elastic Beanstalk部署的部分在这里。
英文:
I was finally able to get a Go application to deploy with Elastic Beanstalk using the eb client. There are a few things that EB requires:
-
The name of your main file should be
application.go
. -
Make sure your app is listening on port 5000.
-
You'll need a Procfile in the main root with
web: bin/application
-
You'll need a Buildfile with
make: ./build.sh
-
And finally you'll need a
build.sh
file with#!/usr/bin/env bash # Stops the process if something fails set -xe # All of the dependencies needed/fetched for your project. # FOR EXAMPLE: go get "github.com/gin-gonic/gin" # create the application binary that eb uses GOOS=linux GOARCH=amd64 go build -o bin/application -ldflags="-s -w"
Then if you run eb deploy
(after creating your initial eb repository), it should work. I wrote a whole tutorial for deploying a Gin application on EB here. The section specifically on deploying with Elastic Beanstalk is here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论