2

Can we deploy/push our Go web service binary to Cloud Foundry, instead of pushing codebase and build there? If we can then how? I tried to find anything related but could not find anything.

Thanks in advance

John Topley
  • 113,588
  • 46
  • 195
  • 237
kamal
  • 996
  • 15
  • 25

2 Answers2

4

Can we deploy/push our GO web service binary to CloudFoundry, instead of pushing codebase and build there?

Yes. You can push any binary as long as it's compiled in a compatible way, and that you ship with any library dependencies (not included in the root file system). Building compatible binaries is often the tricky part, but for a Golang app I don't think it should be as hard.

If we can then how?

Don't use the Go build pack. It expects code and will try to compile it for you.

Instead, build as you normally would but do so on a Linux machine, VM or w/Docker. For best compatibility use a system that matches the stack on your CF platform (run cf stacks to see). The default stack at the time of writing is cflinuxfs2, which is based on Ubuntu 14.04 Trusty. You can also use the cloudfoundry/cflinuxfs2 docker image.

Then push the resulting binary using the binary build pack.

https://docs.cloudfoundry.org/buildpacks/binary/index.html

Ex: cf push -b binary_buildpack -c './my_binary_name'

You might also need -p to indicate the folder / path where your binaries reside, otherwise cf push will send up everything from the current directory.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
0

For Go, you push your binaries, not code, to the cloud foundry as any other app.

Here is a sample app in Go. It shows how to use a concourse pipeline to build and push the app. You can skip the ci/cd aspects. Just compile the code and do a cf push.

Here's another example that may help https://blog.anynines.com/how-to-deploy-a-go-app-on-anynines-and-cloud-foundry/

John Topley
  • 113,588
  • 46
  • 195
  • 237
K.AJ
  • 1,292
  • 11
  • 17
  • Correct me If I am wrong, `cf push` pushes the whole codebase and compile the code in CF, as unlike java it creates binary which is machine and OS architecture and platform dependent, so if i compile on mac and push that binary to CF, how will it work? @askX – kamal Feb 22 '17 at 08:31
  • refer this link https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#intro it says it deploys whole codebase. – kamal Feb 22 '17 at 08:42
  • You may be confusing the staging process with an app compilation. On `cf push`, I pass the archive details (jar, war, zip or a folder location) and optionally the buildpack to use. Extraneous files and artifacts are excluded from upload. Cloud Foundry, as part of staging process, will download runtime dependencies as needed (e.g. nodejs apps, it will download packages). Please see the staging process flow https://docs.pivotal.io/pivotalcf/1-9/concepts/how-applications-are-staged.html – K.AJ Feb 22 '17 at 15:56
  • Kamal, to your point on building the binary, you can build binaries for GO apps on you mac for whatever platform. $> OOS=windows go build -o .exe $> OOS=linux go build -o $> OOS=linux go build -o And then do the `cf push` on the appropriate archive. – K.AJ Feb 22 '17 at 16:15