Rodrigo
Rodrigo

Reputation: 3278

Deploying golang app in cmd folder to AWS Beanstalk

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'

Upvotes: 9

Views: 2409

Answers (2)

Vishwa Ratna
Vishwa Ratna

Reputation: 6390

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:

enter image description here

Upvotes: 0

Kenny Grant
Kenny Grant

Reputation: 9623

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.

Upvotes: 2

Related Questions