Cloud Foundry在将二进制文件推送到cf时下载了错误的Go版本。

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

Cloud foundry downloading wrong go version when binary file pushed to cf

问题

你好,当我将二进制文件推送到cf时,我们发现下载了错误的go版本。

推送代码的步骤如下:
1)运行go build命令

GOOS="linux" GOARCH=amd64 go build ${LDFLAGS} -o localdeploy/some-app main.go

2)cd localdeploy
3)cf push -f manifest.yml

注意:localdeploy文件夹包含manifest.yml和some-app二进制文件

go.mod文件内容如下:

go 1.16

require (
	github.com/cloudfoundry-community/go-cfenv v1.18.0
	github.com/gin-gonic/gin v1.8.1
	github.com/google/uuid v1.3.0
	github.com/rs/zerolog v1.28.0
	github.com/stretchr/testify v1.8.0
)

manifest.yml文件内容如下:

applications:
      - name: some-app-1000-snapshot
        command: ./some-app
        stack: cflinuxfs3
        buildpacks:
          - https://github.com/cloudfoundry/binary-buildpack.git

然后我看到以下日志,下载的是go 1.15.5而不是我mod文件中存在的go 1.16。

推送到cf时获取到的日志如下——应用程序正常工作,但为什么下载的是1.15而不是1.16?

Staging app and tracing logs...
-----> Download go 1.15.5
-----> Running go build supply
/tmp/buildpackdownloads/d612ac0e3047b21e80ecfeae72c39f81 ~
~
-----> Binary Buildpack version 1.0.46
-----> Download go 1.15.5
-----> Running go build finalize
/tmp/buildpackdownloads/d612ac0e3047b21e80ecfeae72c39f81 ~```

英文:

Hi we are seeing wrong go version is downloaded when i push my binary file to cf

Steps followed to push code

  1. run go build command

GOOS="linux" GOARCH=amd64 go build ${LDFLAGS} -o localdeploy/some-app main.go

  1. cd localdeploy
  2. cf push -f manifest.yml

Note: localdeploy folder contains manifest.yml and some-app binary file

Go.mod file


go 1.16

require (
	github.com/cloudfoundry-community/go-cfenv v1.18.0
	github.com/gin-gonic/gin v1.8.1
	github.com/google/uuid v1.3.0
	github.com/rs/zerolog v1.28.0
	github.com/stretchr/testify v1.8.0
)

manifest file.yml

 applications:
      - name: some-app-1000-snapshot
        command: ./some-app
        stack: cflinuxfs3
        buildpacks:
          - https://github.com/cloudfoundry/binary-buildpack.git

Then i see following logs downloading go 1.15.5 instead of go 1.16


Below are the logs getting when pushed to cf --- application is working but why it is downloading 1.15 instead of 1.16 which is present in my mod file

Staging app and tracing logs...
   -----> Download go 1.15.5
   -----> Running go build supply
   /tmp/buildpackdownloads/d612ac0e3047b21e80ecfeae72c39f81 ~
   ~
   -----> Binary Buildpack version 1.0.46
   -----> Download go 1.15.5
   -----> Running go build finalize
   /tmp/buildpackdownloads/d612ac0e3047b21e80ecfeae72c39f81 ~```


</details>


# 答案1
**得分**: 1

二进制构建包不会为您的应用程序安装任何内容。它实际上是一个空操作构建包。

由于您在本地编译了应用程序,因此用于二进制文件的Go版本是在您的计算机上本地安装的版本。您可以根据本地安装的内容来控制该版本。

-----

二进制构建包的输出在这里可能会让人困惑,因为您确实看到它正在下载一个较旧的Go版本。这是因为构建包本身是用Go编写的,并且您在manifest.yml中的构建包定义指向构建包的源代码。因此,为了运行构建包,它首先必须编译自身。它需要Go来完成这个过程,所以它会下载Go,构建自身,然后运行自身。这就是您看到的`Download go 1.15.5`的内容。

大多数(全部?)CloudFoundry安装默认都会有二进制构建包,所以您不需要引用源代码。运行`cf buildpacks`并从列表中获取二进制构建包的名称。它将类似于`binary-buildpack`或`binary_buildpack`。编辑您的manifest.yml文件,并将`https://github.com/cloudfoundry/binary-buildpack.git`替换为该值。

现在当您推送时,它将使用已经编译好的现有构建包,您不应该再看到关于下载Go的消息。

<details>
<summary>英文:</summary>

The binary buildpack doesn&#39;t install anything for your application. It is effectively a no-op buildpack.

Since you have compiled your application locally, the version of Go that is used for your binary is the version installed locally on your computer. You control that version based on what you have installed locally.

-----

The output of the binary buildpack is confusing here, because you do see it downloading an older Go version. The reason this happens is because the buildpack itself is written in Go and you have the buildpack definition in your manifest.yml pointing to the source code of the buildpack. Thus to run the buildpack, it has to compile itself first. It needs Go to do that, so it downloads Go, builds itself, then runs itself. That&#39;s what you&#39;re seeing where it says `Download go 1.15.5`.

Most (all?) CloudFoundry installations are going to have the binary buildpack by default, so you don&#39;t need to reference the source. Run `cf buildpacks` and get the name of the binary buildpack from the list. It&#39;ll be something like `binary-buildpack` or `binary_buildpack`. Edit your manifest.yml and replace `https://github.com/cloudfoundry/binary-buildpack.git` with that value.

Now when you push, it&#39;ll use the existing buildpack which is already compiled and you shouldn&#39;t see those messages about Go being downloaded.

</details>



huangapple
  • 本文由 发表于 2022年10月6日 15:15:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/73969913.html
匿名

发表评论

匿名网友

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

确定