将golang应用程序部署到AWS Beanstalk的cmd文件夹中。

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

Deploying golang app in cmd folder to AWS Beanstalk

问题

我有一个现有的golang项目,具有以下文件夹结构(为了可读性而缩小了文件夹)。

  • postgre
    • service.go
  • cmd
    • vano
      • main.go
    • vanoctl
      • main.go
        vano.go

现在,由于我的项目Web服务器位于./cmd/vano,我需要创建一个自定义的BuildfileProcfile。所以我这样做了

这是我的Buildfile

make: ./build.sh

build.sh文件:

#!/usr/bin/env bash

安装依赖项。

go get ./...

构建应用程序

go build ./cmd/vano -o bin/application

最后是我的Procfile:

web: bin/application

所以现在我的文件夹结构如下:

  • postgre
    • service.go
  • cmd
    • vano
      • main.go
    • vanoctl
      • main.go
        vano.go
        Buildfile
        build.sh
        Procfile

我使用git将源代码打包:

git archive --format=zip HEAD > vano.zip

然后将其上传到AWS Beanstalk。然而,我一直收到错误消息,而AWS的错误似乎并不是最易读的。这是我的错误信息

所有实例上的命令执行已完成。摘要:[成功:0,失败:1]。

错误消息

[Instance: i-0d8f642474e3b2c68]实例上的命令执行失败。返回代码:1 输出:(已截断)...'无法执行'HOME=/tmp /opt/elasticbeanstalk/lib/ruby/bin/ruby /opt/elasticbeanstalk/lib/ruby/bin/foreman start --procfile /tmp/d20170213-1941-1baz0rh/eb-buildtask-0 --root /var/app/staging --env /var/elasticbeanstalk/staging/elasticbeanstalk.env'。钩子/opt/elasticbeanstalk/hooks/appdeploy/pre/01_configure_application.sh失败。有关详细信息,请使用控制台或EB CLI检查/var/log/eb-activity.log。

额外的错误信息:

无法执行'HOME=/tmp /opt/elasticbeanstalk/lib/ruby/bin/ruby /opt/elasticbeanstalk/lib/ruby/bin/foreman start --procfile /tmp/d20170213-1941-1baz0rh/eb-buildtask-0 --root /var/app/staging --env /var/elasticbeanstalk/staging/elasticbeanstalk.env'。

英文:

I have a pre-existing golang project with the a following folder structure (minimized the folder for readability).

- postgre
    - service.go
- cmd
    - vano
        - main.go
    - vanoctl
        - main.go
vano.go

Now since my project web server is in ./cmd/vano I need to create a custom Buildfile and Procfile. So I did that

Here is my Buildfile

make: ./build.sh

build.sh file:

#!/usr/bin/env bash

# Install dependencies.
go get ./...
# Build app
go build ./cmd/vano -o bin/application

and finally my Procfile:

web: bin/application

So now my folder structure looks like this:

- postgre
    - service.go
- cmd
    - vano
        - main.go
    - vanoctl
        - main.go
vano.go
Buildfile
build.sh
Procfile

I zip up the source using git:

git archive --format=zip HEAD > vano.zip

And upload it to AWS Beanstalk. How ever I keep getting errors and AWS errors don't seem to be the most read. Here is my error

Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].

Error Message

[Instance: i-0d8f642474e3b2c68] Command failed on instance. Return code: 1 Output: (TRUNCATED)...' Failed to execute 'HOME=/tmp /opt/elasticbeanstalk/lib/ruby/bin/ruby /opt/elasticbeanstalk/lib/ruby/bin/foreman start --procfile /tmp/d20170213-1941-1baz0rh/eb-buildtask-0 --root /var/app/staging --env /var/elasticbeanstalk/staging/elasticbeanstalk.env'. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/01_configure_application.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

Extra Error info:

Failed to execute 'HOME=/tmp /opt/elasticbeanstalk/lib/ruby/bin/ruby /opt/elasticbeanstalk/lib/ruby/bin/foreman start --procfile /tmp/d20170213-1941-1baz0rh/eb-buildtask-0 --root /var/app/staging --env /var/elasticbeanstalk/staging/elasticbeanstalk.env'

答案1

得分: 2

这里还有另一种方法,而不是使用procfile等方式,可以通过交叉编译你的二进制文件(在Go语言中通常很简单),然后按照指南中的简单说明上传它:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-environment.html

你可以在本地进行编译:

GOARCH=amd64 GOOS=linux go build -o bin/application ./cmd/vano 

然后将应用程序文件打包成zip文件上传,假设你的设置只需要这一个二进制文件来运行,应该就可以工作了。

英文:

Another approach here instead of using a procfile etc would be to cross-compile your binary (usually pretty painless in go) and upload it that way, as per the simple instructions in the guide:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-environment.html

You can just compile it locally with:

GOARCH=amd64 GOOS=linux go build -o bin/application ./cmd/vano 

Then upload zip of the application file and it should work, assuming your setup only requires this one binary to run.

答案2

得分: 0

部署的最佳方式是使用命令行创建一个二进制文件。

在终端中使用以下命令创建一个二进制文件:go build -o bin/application application.go

然后将所有文件添加到一个 zip 文件中。

进入您的 eb 环境并上传该 zip 文件。

您应该会看到如下的日志:

将golang应用程序部署到AWS Beanstalk的cmd文件夹中。

英文:

The best way to deploy is creating a binary file using cmd.

In the terminal create a binary file using cmd-> go build -o bin/application application.go

then add all the files in a zip file.

go to your eb environment and upload the zip file.

You should see logs as below:

将golang应用程序部署到AWS Beanstalk的cmd文件夹中。

huangapple
  • 本文由 发表于 2017年2月14日 00:41:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/42209109.html
匿名

发表评论

匿名网友

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

确定