LATEST VERSION: 1.10 - CHANGELOG
Pivotal Cloud Foundry v1.9

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 if:

  • 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.yaml 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 myapp -b https://github.com/cloudfoundry/go-buildpack.git

When specifying versions, specify only major/minor versions, eg. go1.6, rather than go1.6.0. This will ensure you receive the most recent patches.

Start Command

When pushing go apps, you can specify a start command for the app. The start command can be placed in the file Procfile in your app’s root directory. For example, if the binary generated by your go project is my-go-server, your Procfile could be:

web: my-go-server

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

You can also specify your app’s start command in the manifest.yml file in the root directory, for example:

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

If you do not specify a start command via a Procfile, in the manifest, or via the -c flag for cf push, the generated binary will be used as the start command. (ex. 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

NOTE: if you are using godep with Go 1.6, you must set the GO15VENDOREXPERIMENT environment variable to 0, otherwise your app will not stage.

An example Godeps/Godeps.json:

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

An example manifest.yml:

---
applications:
  - name: my-app-name
    env:
      GO15VENDOREXPERIMENT: 0

Push an App with Glide

If you are using glide to specify and/or package your dependencies, make sure that you have created a valid glide.yaml 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. A glide.lock is not required when deploying a non-vendored app. A glide.lock is required when pushing a vendored app.

Glide

An example glide.yaml:

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

Push an App with Native Go Vendoring

If you are using 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: go-online

Go 1.5

NOTE: For Go 1.5, since native vendoring is turned off by default, you must set the environment variable GO15VENDOREXPERIMENT to 1 in your manifest.yml to use this feature.

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

An example manifest.yml:

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

Go 1.6

An example manifest.yml:

---
applications:
 - name: my-app-name
   command: example-project
   env:
     GOVERSION: go1.6
     GOPACKAGENAME: github.com/example-org/example-project

Pass a Symbol and String to the Linker

This buildpack supports the go linker’s ability (-X symbol value) to set the value of a string at link time. This can be done by setting GO_LINKER_SYMBOL and GO_LINKER_VALUE in the application’s config before pushing code.

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

For an example usage, see the relevant fixture app.

C Dependencies

This buildpack supports building with C dependencies via cgo. You can set config vars to specify CGO flags to, e.g., specify paths for vendored dependencies. E.g., 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 out of the box.

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

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

Create a pull request or raise an issue on the source for this page in GitHub