无法在Cloud Foundry中推送Go应用程序。

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

Unable to push Go app inside cloud foundry

问题

我正在尝试将Go应用程序推送到Cloud Foundry。当我尝试构建二进制文件并推送应用程序时,应用程序崩溃并返回启动失败。

这是我的清单文件:

---
applications:
- name: project-suspension
  instances: 1
  memory: 256MB
  disk_quota: 512MB
  buildpacks: 
  - go_buildpack
  - binary_buildpack
env:
  GOPACKAGENAME: dev.azure.com/.../service-infrastructure

我尝试将每个文件放在项目的根文件夹中,但是当我推送应用程序时,它仍然崩溃。我尝试的另一种方法是使用命令标志"-c 'project-suspension'",但它仍然崩溃。

英文:

I'm trying to push Go app into cloud foundry. When I try to build the binary and push it the app crashes and it returns start unsuccessful.

This is my manifest file

---
applications:
- name: project-suspension
  instances: 1
  memory: 256MB
  disk_quota: 512MB
  buildpacks: 
  - go_buildpack
  - binary_buildpack
 env:
    GOPACKAGENAME: dev.azure.com/.../service-infrastructure

I tried putting every file inside the root folder of the project but the app is still crashing when I push it. The other thing i tried is using the command flag -c "project-suspension" and it still crashes.

答案1

得分: 0

如评论中所提到的,你不需要同时使用两个构建包。如果你正在推送源代码,可以使用go-buildpack;如果你正在本地构建并推送二进制文件,则可以使用binary_buildpack。如果要推送本地构建的二进制文件,你需要交叉编译为Linux(除非你的工作站正在运行Linux)。

示例:

---
applications:
- name: project-suspension
  instances: 1
  memory: 256MB
  disk_quota: 512MB
  buildpacks: 
  - go_buildpack
  env:
    GOPACKAGENAME: dev.azure.com/.../service-infrastructure

或者

---
applications:
- name: project-suspension
  instances: 1
  memory: 256MB
  disk_quota: 512MB
  buildpacks: 
  - binary_buildpack
  command: ./project-suspension

后者假设你要运行的二进制文件名为project-suspension,并且它存在于cf push运行的相同目录中(或者你已经设置了path:-p的相同目录)。

此外,请注意应用程序可能因其他原因无法启动,例如健康检查未通过。默认的健康检查将基于端口,因此它将期望你的应用程序在设置为$PORT的端口号上进行监听。确保你的应用程序读取$PORT并在该端口上进行监听。

英文:

As mentioned in the comment, you don't need both buildpacks. Use either the go-buildpack, if you are pushing source code, or the binary buildpack if you are building locally and pushing the binary. If pushing a binary built locally, you need to cross-compile for Linux (unless you are running Linux as your workstation).

Ex:

---
applications:
- name: project-suspension
  instances: 1
  memory: 256MB
  disk_quota: 512MB
  buildpacks: 
  - go_buildpack
 env:
    GOPACKAGENAME: dev.azure.com/.../service-infrastructure

or

---
applications:
- name: project-suspension
  instances: 1
  memory: 256MB
  disk_quota: 512MB
  buildpacks: 
  - binary_buildpack
  command: ./project-suspension

The latter assumes that the binary you want to run is called project-suspension and that it exists in the same directory from which cf push is run (or the same directory where you've set path: or -p.

Also, be aware that applications can fail to start for other reasons, like if the health check does not pass. The default health check is going to be port-based, so it'll expect your application to be listening on the port number set with $PORT. Make sure your app reads $PORT and listens on that port.

huangapple
  • 本文由 发表于 2022年11月4日 20:20:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/74316987.html
匿名

发表评论

匿名网友

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

确定