Go Buildpack

Page last updated:

Supported Versions

Supported Go versions can be found in the release notes.

Push an App

The Go buildpack will be automatically detected in the following circumstances:

  • Your app has been packaged with godep using godep save.
  • Your app has a vendor/ directory and has any files ending with .go.
  • Your app has a GOPACKAGENAME environment variable specified and has any files ending with .go.
  • Your app has a glide.yml file and is using glide, starting in buildpack version 1.7.9.

If your Cloud Foundry deployment does not have the Go Buildpack installed, or the installed version is out of date, you can use the latest version with the command:

$ cf push my_app -b https://github.com/cloudfoundry/go-buildpack.git

When specifying versions, specify only major/minor versions, such as Go 1.6, rather than Go 1.6.0. This ensures you receive the most recent patches.

Start Command

When pushing Go apps, you can specify a start command for the app. You can place the start command in the Procfile file in root directory of your app. For example, if the binary generated by your Go project is my-go-server, your Procfile could contain the following:

web: my-go-server

For more information about Procfiles, see the Configuring a Production Server topic.

You can also specify the start command for your app in the manifest.yml file in the root directory. For example, your manifest.yml could contain the following:

---
applications:
  - name: my-app-name
    command: my-go-server

If you do not specify a start command in a Procfile, in the manifest, or with the -c flag for cf push, the generated binary will be used as the start command. Example: my-go-server

Push an App with godep

If you are using godep to package your dependencies, make sure that you have created a valid Godeps/Godeps.json file in the root directory of your app by running godep save.

When using godep, you can fix your Go version in GoVersion key of the Godeps/Godeps.json file.

Go 1.5

An example Godeps/Godeps.json:

{
    "ImportPath": "go_app",
    "GoVersion": "go1.5",
    "Deps": []
}

An example manifest.yml:

---
applications:
  - name: my-app-name

Go 1.6

An example Godeps/Godeps.json:

{
    "ImportPath": "go_app",
    "GoVersion": "go1.6",
    "Deps": []
}

Push an App with Glide

If you use glide to specify or package your dependencies, make sure that you have created a valid glide.yml file in the root directory of your app by running glide init.

To vendor your dependencies before pushing, run glide install. This will generate a vendor directory and a glide.lock file specifying the latest compatible versions of your dependencies. You must have a glide.lock file when pushing a vendored app. You do not need a glide.lock file when deploying a non-vendored app.

Glide

An example glide.yml file:

package: go_app_with_glide
import:
- package: github.com/ZiCog/shiny-thing
  subpackages:
  - foo

Push an App with Native Go Vendoring

If you use the native Go vendoring system, which packages all local dependencies in the vendor/ directory, you must specify your app’s package name in the GOPACKAGENAME environment variable.

An example manifest.yml:

---
applications:
  - name: my-app-name
    command: go-online
    env:
      GOPACKAGENAME: app-package-name

Go 1.5

NOTE: For Go 1.5, native vendoring is disabled by default. You must set the GO15VENDOREXPERIMENT environment variable to 1 in your manifest.yml file to use this native vendoring.

If you use the vendor/ directory for dependencies, you can set the Go version with the GOVERSION environment variable.

An example manifest.yml file:

---
applications:
  - name: my-app-name
    env:
      GOVERSION: go1.5
      GOPACKAGENAME: app-package-name
      GO15VENDOREXPERIMENT: 1

Go 1.6

Go 1.6 has vendoring enabled by default. Set the GO15VENDOREXPERIMENT environment variable to 0 to disable vendoring.

An example manifest.yml file:

---
applications:
 - name: my-app-name
   command: example-project
   env:
     GOVERSION: go1.6
     GOPACKAGENAME: app-package-name

Go 1.7+

Go 1.7 always has vendoring enabled, and you cannot disable it with an environment variable.

An example manifest.yml:

---
applications:
 - name: my-app-name
   command: example-project
   env:
     GOVERSION: go1.7
     GOPACKAGENAME: app-package-name

Pass a Symbol and String to the Linker

The Go buildpack supports the Go linker’s ability, -X symbol value, to set the value of a string at link time. Set the GO_LINKER_SYMBOL and GO_LINKER_VALUE in the application’s configuration before pushing code.

This can be used to embed the commit SHA or other build-specific data directly into the compiled executable.

For example usage, see the relevant fixture app.

C Dependencies

The Go buildpack supports building with C dependencies using cgo. You can set config vars to specify cgo flags to, for example, specify paths for vendored dependencies. As an example, to build gopgsqldriver, add the config var CGO_CFLAGS with the value -I/app/code/vendor/include/postgresql and include the relevant Postgres header files in vendor/include/postgresql/ in your app.

Proxy Support

If you need to use a proxy to download dependencies during staging, you can set the http_proxy and/or https_proxy environment variables. For more information, see the Proxy Usage topic.

BOSH Configured Custom Trusted Certificate Support

Go uses certificates stored in /etc/ssl/certs and supports BOSH configured custom trusted certificates with no additional configuration necessary.

Help and Support

Join the #buildpacks channel in our Slack community if you need any further assistance.

For more information about using and extending the Go buildpack in Cloud Foundry, see the go-buildpack GitHub repository.

You can find current information about this buildpack on the Go buildpack release page in GitHub.

View the source for this page in GitHub