Elastic Beanstalk的go应用程序的Procfile

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

Elastic Beanstalk Procfile for go

问题

我正在尝试将我的Go Restful服务器程序部署到EC2 Linux上使用Elastic Beanstalk。文档上说我需要在根目录下创建一个Procfile文件,所以我按照以下步骤进行操作:

  1. 使用以下命令将我的Go程序myapp.go编译为可执行文件:

     $ go build -o myapp -i myapp.go
    
  2. 在根目录下创建一个名为Procfile的文件,内容如下:

     web: myapp
    
  3. 将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:

  1. Build my go program myapp.go to using

     $ go build -o myapp -i myapp.go
    
  2. Create a Procfile with exact name at the root with

     web: myapp
    
  3. 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有一些要求:

  1. 主文件的名称应为application.go

  2. 确保你的应用程序监听5000端口。

  3. 在主目录下需要一个Procfile,内容如下:

     web: bin/application
    
  4. 需要一个Buildfile,内容如下:

     make: ./build.sh
    
  5. 最后,你需要一个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:

  1. The name of your main file should be application.go.

  2. Make sure your app is listening on port 5000.

  3. You'll need a Procfile in the main root with

     web: bin/application
    
  4. You'll need a Buildfile with

     make: ./build.sh
    
  5. 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.

huangapple
  • 本文由 发表于 2017年4月12日 12:44:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/43360476.html
匿名

发表评论

匿名网友

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

确定