当我部署该应用程序时,它在首次安装时运行良好。但是以下任何eb deploy
过程都失败,并显示错误:go.mod was found, but not expected
。
我必须设置特定的配置以使用Go模块进行部署吗?
我改用Docker化应用程序并以这种方式进行部署,效果很好。但这对我来说有点麻烦,因为AWS Elastic Beanstalk提供了特定的Go环境。
答案 0 :(得分:3)
您可以使用go模块。
build.sh
#!/usr/bin/env bash
set -xe
# get all of the dependencies needed
go get
# create the application binary that EB uses
go build -o bin/application application.go
并覆盖GOPATH以指向$ HOME,该值默认为/var/app/current
,如EB配置管理仪表板中所给出。
.ebextensions / go.config
option_settings:
aws:elasticbeanstalk:application:environment:
GOPATH: /home/ec2-user
答案 1 :(得分:0)
我遇到了同样的问题,我终于能够解决它,在我的build.sh脚本文件中添加了这一行:
sudo rm / var / app / current / go。*
就我而言,就是这样:
#!/usr/bin/env bash
# Stops the process if something fails
set -xe
sudo rm /var/app/current/go.*
# get all of the dependencies needed
go get "github.com/gin-gonic/gin"
go get "github.com/jinzhu/gorm"
go get "github.com/jinzhu/gorm/dialects/postgres"
go get "github.com/appleboy/gin-jwt"
# create the application binary that eb uses
GOOS=linux GOARCH=amd64 go build -o bin/application -ldflags="-s -w"