How to deploy GoLang Binaries to CF

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

How to deploy GoLang Binaries to CF

问题

你好,我们正在尝试将 Golang 二进制文件部署到 cf。

例如,/deploy/ 文件夹中的 main.exe 与 manifest 文件一起。

注意:我们观察到,如果我们推送整个项目应用程序,它可以正常工作。但是,如果我们只尝试推送二进制文件,就会出现以下错误:

How to deploy GoLang Binaries to CF

Manifest 文件包含以下信息:

applications:

  • name: test-app
    command: test-app
    env:
    GO_INSTALL_PACKAGE_SPEC: ./

错误:要使用 Go 本地供应商设置 $GOPACKAGENAME 环境变量为您的应用程序的包名
错误:无法确定导入路径:GOPACKAGENAME 未设置

在添加 GOPACKAGENAME: main 后,由于 main.exe 是我们的二进制文件名,我们得到以下错误:

Failed to compile droplet: Failed to run finalize script: exit status 12
Cell 507b6e9c-c5c5-4685-9a71-d7cc1c876f5a stopping instance 6a92ff73-76ec-4baf-8a3e-54b54cfa307e
BuildpackCompileFailed - App staging failed in the buildpack compile phase

英文:

Hi we are trying to deploy golang binaries to cf.

for example main.exe which is in /deploy/ folder along with mainfest file

Note: It is also observed that if we push the whole project app then it works. but if we try to push only binaries then we get the below error

How to deploy GoLang Binaries to CF

And Manifest file contains following info

 applications:
    - name: test-app
      command: test-app
      env:
        GO_INSTALL_PACKAGE_SPEC: ./



**ERROR** To use go native vendoring set the $GOPACKAGENAME
          environment variable to your app's package name
          **ERROR** Unable to determine import path: GOPACKAGENAME unset

After adding GOPACKAGENAME: main since main.exe is our binary name we get following error below

  Failed to compile droplet: Failed to run finalize script: exit status 12
   Cell 507b6e9c-c5c5-4685-9a71-d7cc1c876f5a stopping instance 6a92ff73-76ec-4baf-8a3e-54b54cfa307e
BuildpackCompileFailed - App staging failed in the buildpack compile phase

答案1

得分: 2

感谢 @Volker 指出上述问题:

首先,我们需要使用以下命令构建(使用 makefile):

GOOS="linux" go build main.go

然后将该主要二进制文件复制到 /deploy 文件夹中。

然后在 deploy 文件夹中创建清单文件:

applications:
    - name: test-app
      command: ./main
      stack: cflinuxfs3
      buildpacks:
        - https://github.com/cloudfoundry/binary-buildpack.git

然后推送到 cf:

cf push -f ./manifest-template.yml
英文:

thanks @Volker for pointing out

for above issue:

first we have to build with following command (used make file)

GOOS="linux" go build main.go

then copy that main binary to /deploy folder

then manifest file in the deploy folder

applications:
    - name: test-app
      command: ./main
      stack: cflinuxfs3
      buildpacks:
        - https://github.com/cloudfoundry/binary-buildpack.git

Then to push to cf

cf push -f ./manifest-template.yml

huangapple
  • 本文由 发表于 2021年10月22日 13:57:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/69672032.html
匿名

发表评论

匿名网友

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

确定