Reputation: 1437
I have an application that's split across a few different files and I'm having trouble deploying it. I've followed this documentation, but I'm getting the following:
application.go:7:5: cannot find package "github.com/gorilla/handlers" in any of:
I assume I need to install the libraries I'm using in the $GOPATH
as part of the deployment process, but I don't know how to do that and haven't found any examples of it. Using the Procfile seems promising, but all of my searches keep leading me to Heroku resources.
Upvotes: 1
Views: 1410
Reputation: 40641
This works for me as of mid-2019. The gist is to compile locally and upload your binary. Run this from your project root:
GOARCH=amd64 GOOS=linux go build -o bin/application
Then include this binary in your application zip that you upload to the EB console.
Upvotes: 0
Reputation: 31
I ran into the same issue, and was able to fix it by using the eb client.
Just to cover the basics:
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.
# This is what actually fixes the problem so that EB can find your dependencies.
# 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 inital eb replository), it should work. I think you can get the same results by then zipping your application.go
, Procfile
, Buildfield
, and build.sh
script and loading that into the Elastic Beanstalk console, but I haven't tried it.
I wrote a whole tutorial for deploying a Gin application on EB here. The section specifically on deploying with Elastic Beanstalk is here.
Upvotes: 0
Reputation: 6345
You could use a vendoring tool to store all your dependencies within a vendor folder.
I use govendor.
Steps:
1. go get -u github.com/kardianos/govendor
2. cd $GOPATH/yourProject
3. govendor init
4. govendor add +external
Now the directory 'yourProject' can be build independently on any machine provided it is in $GOPATH.
Note : Requires Go 1.6+ or 1.5 with GO15VENDOREXPERIMENT=1.
Edit : As per fl0cke's comment. If Elastic Beanstalk only supports Go 1.4, the possible options are :
Upvotes: 2