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
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
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.
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/