anynines website

Categories

Series

Julian Fischer

Published at 08.01.2014

How-To’s & Tutorials

How to Deploy a Go App on anynines and Cloud Foundry

Thanks to Cloud Foundry’s support of buildpacks it’s very easy to deploy mostly any app of any language to anynines.

This of course includes the Go language.

Derived from Heroku’s Go buildpack Michael Jemala was so nice to create a slightly modified Cloud Foundry buildpack for Go. As all Cloud Foundry buildpacks can also be used on anynines it’s just a matter of minutes to get a Go app running.

In case the application starts a web server the server shouldn’t bind to a particular host and must read the port from the environment variable provided by the executing application server (called DEA in Cloud Foundry terms).

This may look like this (full example):
func main() {   port := os.Getenv("PORT")   fmt.Println("PORT:", port)

  var h Hello   http.ListenAndServe(":" + port, h) }
In addition to this your project should contain two files.

.godir – This file contains the desired name of your executable, “server” in our example.

Procfile – This file contains the name of the executable to be started. “web: server” in our case.

The push command then looks like this:
cf push --name goexample --buildpack https://github.com/michaljemala/cloudfoundry-buildpack-go.git
Have fun!

Find a working example of the anynines go example app on github.

© anynines GmbH 2024

Imprint

Privacy Policy

About

© anynines GmbH 2024