首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在弹力豆杆上部署私有github repo golang应用

在弹力豆杆上部署私有github repo golang应用
EN

Stack Overflow用户
提问于 2018-04-26 06:30:43
回答 1查看 593关注 0票数 3

几天来,我一直在努力将我的Golang应用部署到AWS。

我正试图通过我的app文件夹中的命令eb deploy使用EB服务器eb deploy将我的应用程序部署到eb服务器上。

几秒钟后,我收到一条错误消息,上面说我的应用程序没有被部署是因为一个错误。看看eb-activity.log,我在这里可以看到:

代码语言:javascript
运行
复制
    /var/log/eb-activity.log
    -------------------------------------
    Fetching https://golang.org/x/crypto?go-get=1
    Parsing meta tags from https://golang.org/x/crypto?go-get=1 (status code 200)
    golang.org/x/crypto (download)
    Fetching https://golang.org/x/sys/unix?go-get=1
    Parsing meta tags from https://golang.org/x/sys/unix?go-get=1 (status code 200)
    get "golang.org/x/sys/unix": found meta tag main.metaImport{Prefix:"golang.org/x/sys", VCS:"git", RepoRoot:"https://go.googlesource.com/sys"} at https://golang.org/x/sys/unix?go-get=1
    get "golang.org/x/sys/unix": verifying non-authoritative meta tag
    Fetching https://golang.org/x/sys?go-get=1
    Parsing meta tags from https://golang.org/x/sys?go-get=1 (status code 200)
    golang.org/x/sys (download)
    github.com/randomuser/private-repo (download)
    # cd .; git clone https://github.com/randomuser/private-repo /go/src/github.com/randomuser/private-repo
    Cloning into '/go/src/github.com/randomuser/private-repo'...
    fatal: could not read Username for 'https://github.com': No such device or address
    package github.com/Sirupsen/logrus
            imports golang.org/x/crypto/ssh/terminal
            imports golang.org/x/sys/unix
            imports github.com/randomuser/private-repo/apis: exit status 128
    package github.com/Sirupsen/logrus
            imports golang.org/x/crypto/ssh/terminal
            imports golang.org/x/sys/unix
            imports github.com/randomuser/private-repo/app
            imports github.com/randomuser/private-repo/app
            imports github.com/randomuser/private-repo/app: cannot find package "github.com/randomuser/private-repo/app" in any of:
            /usr/src/go/src/github.com/randomuser/private-repo/app (from $GOROOT)
            /go/src/github.com/randomuser/private-repo/app (from $GOPATH)

当服务器试图安装应用程序时,我想有一个问题,似乎是试图从我在github上的私人回购中检索.

我把我的应用程序子包作为github.com/randomuser/private-repo/subpackage引用,我认为这就是为什么它的行为会这样。

有没有一种方法可以部署我的所有代码,迫使我的私有回购被填充在GOROOT src/github.com/随机用户/私有- repo /这样服务器就不必尝试获取它?

我没有从亚马逊文档(多包应用程序)或Github那里找到任何恰当的例子。

我有遗漏什么吗?有没有更好的解决办法?

另外,我还试图直接部署编译好的二进制文件(创建一个只放置二进制文件、将其压缩并上传到ebs env上的文件夹),但这两种方法都不起作用.也许这个选项还需要另一个env配置(如果是,哪一个?)

(谢谢你的帮助:)

配置

  • Golang应用程序有以下文件夹: Gopkg.lock├──Gopkg.lock├──├──Makefile├──app│app├──├──Makefile├──app│志愿技术发展公司产品开发公司业务技术开发公司业务开发公司业务技术应用程序业务开发公司业务开发公司产品开发公司产品技术─/T1597-1996/1998/1998/1998/1998/2001/1999/2001/1999/2001/1999/2001/1999/2001/2001/1999/2001/2001/1999/2001/2001/2001/2001/1999/2001/1999/2001/2001/2001/1999/2001/2001/1999/2001/1999/2003/2001/1999/2001/1999/2001/1999/2003/2004/2003/2004/2004/2001/2004/2004/2003/2004/2004/2004/2004errors.go
  • 这是我的server.go的内容 主要进口包装(“标志”"fmt“"net/http”"github.com/jinzhu/gorm“_ "github.com/jinzhu/gorm/dialects/mysql”“github.com/随机用户/私有-repo/app”“github.com/随机用户/私有-repo/app”“github.com/repo/private-repo/daos”“github.com/随机用户/私有-回购/错误”“github.com/随机用户/私有-repo/services”) func (){ //从命令行// env获取env,默认情况下,env是prod env := flag.String("env“、" prod”、"environment: prod、preprod或dev") flag.Parse() .router.To("GET,HEAD","/ping",func(c *routing.Context)错误{ c.Abort() //跳过所有其他中间件/处理程序返回c.Write("OK“+ app.Version) }) . //在端口5000上服务
  • 我的Dockerfile内容: 来自戈朗:1.4.2-开始构建加法。/ go /src/github.com/随机用户/私有回购运行go安装github.com/随机用户/私有回购公开5000入口点/go/bin/private-repo
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-08 13:11:12

我终于成功了。

因此,我创建了一个全新的eb应用程序(没有停靠)。然后我发现我的应用程序无法检索控制台设置的env .因此,我使用build.sh脚本强制在启动时将env变量从我的产品配置文件中传递给我的应用程序,如下所示:

代码语言:javascript
运行
复制
#!/bin/bash -xe
# See http://tldp.org/LDP/abs/html/options.html
# -x -> Print each command to stdout before executing it, expand commands
# -e -> Abort script at first error, when a command exits with non-zero status
#   (except in until or while loops, if-tests, list constructs)

# $GOPATH isn't set by default, nor do we have a usable Go workspace :'(
GOPATH="/var/app/current"
APP_BUILD_DIR="$GOPATH/src/to-be-defined"     # We will build the app here
APP_STAGING_DIR="/var/app/staging"            # Current directory
DEP_VERSION="v0.3.2"                          # Use specific version for stability
ENV_VAR_PREFIX="TO_BE_DEFINED_"

# Install dep, a Go dependency management tool, if not already installed or if
# the version does not match.
if ! hash dep 2> /dev/null ||\
    [[ $(dep version | awk 'NR==2{print $3}') != "$DEP_VERSION" ]]; then
    # /usr/local/bin is expected to be on $PATH.
    curl -L \
        -s https://github.com/golang/dep/releases/download/$DEP_VERSION/dep-linux-amd64 \
        -o /usr/local/bin/dep

    chmod +x /usr/local/bin/dep
fi

# Remove the $APP_BUILD_DIR just in case it was left behind in a failed build.
rm -rf $APP_BUILD_DIR

# Setup the application directory
mkdir -p $APP_BUILD_DIR

# mv all files to $APP_BUILD_DIR
# https://superuser.com/questions/62141/how-to-move-all-files-from-current-directory-to-upper-directory
mv * .[^.]* $APP_BUILD_DIR
cd $APP_BUILD_DIR

# Pull in dependencies into vendor/.
dep ensure

# Build the binary with jsoniter tag.
go build -o application -tags=jsoniter .

# Modify permissons to make the binary executable.
chmod +x application
# Move the binary back to staging dir.
# Along with the configuration files.
mkdir $APP_STAGING_DIR/bin
# By default, `bin/application` is executed. This way, a Procfile isn't needed.
mv application $APP_STAGING_DIR/bin
cp -r config $APP_STAGING_DIR
# TODO: Fix the viper not working with env var
# Generate prod config from env variables
/opt/elasticbeanstalk/bin/get-config environment --output YAML | sed s/${ENV_VAR_PREFIX}//g > $APP_STAGING_DIR/config/prod.app.yaml
# Copy .ebextensions back to staging directory.
# cp -r .ebextensions $APP_STAGING_DIR

# Clean up.
rm -rf $APP_BUILD_DIR

echo "Build successful!!"

EBS使用此Buildfile调用我的build.sh文件:

代码语言:javascript
运行
复制
make: ./build.sh

等等!)现在一切正常工作:)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50036218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档