• Stars
    star
    790
  • Rank 57,622 (Top 2 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 13 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Heroku Go Buildpack

Heroku Buildpack for Go

CI

Heroku Buildpack for Go

This is the official Heroku buildpack for Go.

Getting Started

Follow the guide at https://devcenter.heroku.com/articles/getting-started-with-go

There's also a hello world sample app at https://github.com/heroku/go-getting-started

Example

$ ls -A1
.git
vendor
Procfile
web.go

$ heroku create
Creating polar-waters-4785...
...

$ git push heroku main
...
-----> Go app detected
-----> Installing go1.11... done
-----> Running: go install -tags heroku .
-----> Discovering process types
       Procfile declares types -> web

-----> Compressing... done, 1.6MB
-----> Launching... done, v4
       https://polar-waters-4785.herokuapp.com/ deployed to Heroku

This buildpack will detect your repository as Go if you are using either:

This buildpack adds a heroku build constraint, to enable heroku-specific code. See the App Engine build constraints article for more info.

Go Module Specifics

When using go modules, this buildpack will search the code base for main packages, ignoring any in vendor/, and will automatically compile those packages. If this isn't what you want you can specify specific package spec(s) via the go.mod file's // +heroku install directive (see below).

The go.mod file allows for arbitrary comments. This buildpack utilizes build constraint style comments to track Heroku build specific configuration which is encoded in the following way:

  • // +heroku goVersion <version>: the major version of go you would like Heroku to use when compiling your code. If not specified this defaults to the buildpack's DefaultVersion. Specifying a version < go1.11 will cause a build error because modules are not supported by older versions of go.

    Example: // +heroku goVersion go1.11

  • // +heroku install <packagespec>[ <packagespec>]: a space seperated list of the packages you want to install. If not specified, the buildpack defaults to detecting the main packages in the code base. Generally speaking this should be sufficient for most users. If this isn't what you want you can instruct the buildpack to only build certain packages via this option. Other common choices are: ./cmd/... (all packages and sub packages in the cmd directory) and ./... (all packages and sub packages of the current directory). The exact choice depends on the layout of your repository though.

    Example: // +heroku install ./cmd/... ./special

If a top level vendor directory exists and the go.sum file has a size greater than zero, go install is invoked with -mod=vendor, causing the build to skip downloading and checking of dependencies. This results in only the dependencies from the top level vendor directory being used.

Pre/Post Compile Hooks

If the file bin/go-pre-compile or bin/go-post-compile exists and is executable then it will be executed either before compilation (go-pre-compile) of the repo, or after compilation (go-post-compile).

These hooks can be used to install additional tools, such as github.com/golang-migrate/migrate:

#!/bin/bash
set -e

go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/[email protected]

Because the buildpack installs compiled executables to bin, the go-post-compile hook can be written in go if it's installed by the specified <packagespec> (see above).

Example:

$ cat go.mod
// +heroku install ./cmd/...
$ ls -F cmd
client/ go-post-compile/ server/

dep specifics

The Gopkg.toml file allows for arbitrary, tool specific fields. This buildpack utilizes this feature to track build specific configuration which are encoded in the following way:

  • metadata.heroku['root-package'] (String): the root package name of the packages you are pushing to Heroku.You can find this locally with go list -e .. There is no default for this and it must be specified.

  • metadata.heroku['go-version'] (String): the major version of go you would like Heroku to use when compiling your code. If not specified this defaults to the buildpack's DefaultVersion. Exact versions (ex go1.9.4) can also be specified if needed, but is not generally recommended. Since Go doesn't release .0 versions, specifying a .0 version will pin your code to the initial release of the given major version (ex go1.10.0 == go1.10 w/o auto updating to go1.10.1 when it becomes available).

  • metadata.heroku['install'] (Array of Strings): a list of the packages you want to install. If not specified, this defaults to ["."]. Other common choices are: ["./cmd/..."] (all packages and sub packages in the cmd directory) and ["./..."] (all packages and sub packages of the current directory). The exact choice depends on the layout of your repository though. Please note that ./..., for versions of go < 1.9, includes any packages in your vendor directory.

  • metadata.heroku['ensure'] (String): if this is set to false then dep ensure is not run.

  • metadata.heroku['additional-tools'] (Array of Strings): a list of additional tools that the buildpack is aware of that you want it to install. If the tool has multiple versions an optional @<version> suffix can be specified to select that specific version of the tool. Otherwise the buildpack's default version is chosen. Currently the only supported tool is github.com/golang-migrate/migrate at v3.4.0 (also the default version).

[metadata.heroku]
  root-package = "github.com/heroku/fixture"
  go-version = "go1.8.3"
  install = [ "./cmd/...", "./foo" ]
  ensure = "false"
  additional-tools = ["github.com/golang-migrate/migrate"]
...

govendor specifics

The vendor.json spec that govendor follows for its metadata file allows for arbitrary, tool specific fields. This buildpack uses this feature to track build specific bits. These bits are encoded in the following top level json keys:

  • rootPath (String): the root package name of the packages you are pushing to Heroku. You can find this locally with go list -e .. There is no default for this and it must be specified. Recent versions of govendor automatically fill in this field for you. You can re-run govendor init after upgrading to have this field filled in automatically, or it will be filled the next time you use govendor to modify a dependency.

  • heroku.goVersion (String): the major version of go you would like Heroku to use when compiling your code. If not specified this defaults to the buildpack's DefaultVersion. Exact versions (ex go1.9.4) can also be specified if needed, but is not generally recommended. Since Go doesn't release .0 versions, specifying a .0 version will pin your code to the initial release of the given major version (ex go1.10.0 == go1.10 w/o auto updating to go1.10.1 when it becomes available).

  • heroku.install (Array of Strings): a list of the packages you want to install. If not specified, this defaults to ["."]. Other common choices are: ["./cmd/..."] (all packages and sub packages in the cmd directory) and ["./..."] (all packages and sub packages of the current directory). The exact choice depends on the layout of your repository though. Please note that ./... includes any packages in your vendor directory.

  • heroku.additionalTools (Array of Strings): a list of additional tools that the buildpack is aware of that you want it to install. If the tool has multiple versions an optional @<version> suffix can be specified to select that specific version of the tool. Otherwise the buildpack's default version is chosen. Currently the only supported tool is github.com/golang-migrate/migrate at v3.4.0 (also the default version).

Example with everything, for a project using go1.9, located at $GOPATH/src/github.com/heroku/go-getting-started and requiring a single package spec of ./... to install.

{
    ...
    "rootPath": "github.com/heroku/go-getting-started",
    "heroku": {
        "install" : [ "./..." ],
        "goVersion": "go1.9"
         },
    ...
}

A tool like jq or a text editor can be used to inject these variables into vendor/vendor.json.

glide specifics

The glide.yaml and glide.lock files do not allow for arbitrary metadata, so the buildpack relies solely on the glide command and environment variables to control the build process.

The base package name is determined by running glide name.

The Go version used to compile code defaults to the buildpack's DefaultVersion. This can be overridden by the $GOVERSION environment variable. Setting $GOVERSION to a major version will result in the buildpack using the latest released minor version in that series. Setting $GOVERSION to a specific minor Go version will pin Go to that version. Since Go doesn't release .0 versions, specifying a .0 version will pin your code to the initial release of the given major version (ex go1.10.0 == go1.10 w/o auto updating to go1.10.1 when it becomes available).

Examples:

heroku config:set GOVERSION=go1.9   # Will use go1.9.X, Where X is that latest minor release in the 1.9 series
heroku config:set GOVERSION=go1.7.5 # Pins to go1.7.5

glide install will be run to ensure that all dependencies are properly installed. If you need the buildpack to skip the glide install you can set $GLIDE_SKIP_INSTALL to true. Example:

heroku config:set GLIDE_SKIP_INSTALL=true
git push heroku main

Installation defaults to .. This can be overridden by setting the $GO_INSTALL_PACKAGE_SPEC environment variable to the package spec you want the go tool chain to install. Example:

heroku config:set GO_INSTALL_PACKAGE_SPEC=./...
git push heroku main

Usage with other vendoring systems

If your vendor system of choice is not listed here or your project only uses packages in the standard library, create vendor/vendor.json with the following contents, adjusted as needed for your project's root path.

{
    "comment": "For other heroku options see: https://devcenter.heroku.com/articles/go-support",
    "rootPath": "github.com/yourOrg/yourRepo",
    "heroku": {
        "sync": false
    }
}

Default Procfile

If there is no Procfile in the base directory of the code being built and the buildpack can figure out the name of the base package (also known as the module), then a default Procfile is created that includes a web process type that runs the resulting executable from compiling the base package.

For example, if the package name was github.com/heroku/example, this buildpack would create a Procfile that looks like this:

$ cat Procfile
web: example

This is useful when the base package is also the only main package to build.

If you have adopted the cmd/<executable name> structure this won't work and you will need to create a Procfile.

Note: This buildpack should be able to figure out the name of the base package in all cases, except when gb is being used.

Private Git Repos

The buildpack installs a custom git credential handler. Any tool that shells out to git (most do) should be able to transparently use this feature. Note: It has only been tested with Github repos over https using personal access tokens.

The custom git credential handler searches the application's config vars for vars that follow the following pattern: GO_GIT_CRED__<PROTOCOL>__<HOSTNAME>. Any periods (.) in the HOSTNAME must be replaces with double underscores (__).

The value of a matching var will be used as the username. If the value contains a ":", the value will be split on the ":" and the left side will be used as the username and the right side used as the password. When no password is present, x-oauth-basic is used.

The following example will cause git to use the FakePersonalAccessTokenHere as the username when authenticating to github.com via https:

heroku config:set GO_GIT_CRED__HTTPS__GITHUB__COM=FakePersonalAccessTokenHere

Hacking on this Buildpack

To change this buildpack, fork it on GitHub & push changes to your fork. Ensure that tests have been added to test/run.sh and any corresponding fixtures to test/fixtures/<fixture name>.

Tests

Make, jq & docker are required to run tests.

make test

Run a specific test in test/run.sh:

make BASH_COMMAND='test/run.sh -- testGBVendor' test

Compiling a fixture locally

Make & docker are required to compile a fixture.

make FIXTURE=<fixture name> compile

You will then be dropped into a bash prompt in the container that the fixture was compiled in.

Using with cgo

The buildpack supports building with C dependencies via cgo. You can set config vars to specify CGO flags to specify paths for vendored dependencies. The literal text of ${build_dir} will be replaced with the directory the build is happening in. For example, if you added C headers to an includes/ directory, add the following config to your app: heroku config:set CGO_CFLAGS='-I${ build_dir}/includes'. Note the usage of '' to ensure they are not converted to local environment variables.

Using a development version of Go

The buildpack can install and use any specific commit of the Go compiler when the specified go version is devel-<short sha>. The version can be set either via the appropriate vendoring tools config file or via the $GOVERSION environment variable. The specific sha is downloaded from Github w/o git history. Builds may fail if GitHub is down, but the compiled go version is cached.

When this is used the buildpack also downloads and installs the buildpack's current default Go version for use in bootstrapping the compiler.

Build tests are NOT RUN. Go compilation failures will fail a build.

No official support is provided for unreleased versions of Go.

Passing a symbol (and optional 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. If GO_LINKER_SYMBOL is set, but GO_LINKER_VALUE isn't set then GO_LINKER_VALUE defaults to $SOURCE_VERSION.

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

Testpack

This buildpack supports the testpack API used by Heroku CI.

Golanglint-ci

If the source code contains a golanglint-ci configuration file in the root of the source code (one of /.golangci.yml, /.golangci.toml, or /.golangci.json) then golanci-lint is run at the start of the test phase.

Use one of those configuration files to configure the golanglint-ci run.

More Repositories

1

react-refetch

A simple, declarative, and composable way to fetch data for React components
JavaScript
3,439
star
2

legacy-cli

Heroku CLI
Ruby
1,370
star
3

heroku-pg-extras

A heroku plugin for awesome pg:* commands that are also great and fun and super.
JavaScript
1,306
star
4

heroku-buildpack-nodejs

The official Heroku buildpack for Node.js apps.
Shell
1,265
star
5

node-js-getting-started

Getting Started with Node on Heroku
EJS
1,054
star
6

logplex

[DEPRECATED] Heroku log router
Erlang
984
star
7

heroku-buildpack-python

The official Heroku buildpack for Python apps
Ruby
953
star
8

heroku-django-template

A Django 2.0 base template featuring all recommended best practices for deployment on Heroku and local development.
Python
901
star
9

node-js-sample

This repository is deprecated. Head over to https://github.com/heroku/node-js-getting-started
JavaScript
847
star
10

cli

Heroku CLI
JavaScript
847
star
11

rails_12factor

Ruby
845
star
12

python-getting-started

Getting Started with Python on Heroku.
Python
818
star
13

heroku-buildpack-php

The official PHP buildpack for Heroku.
Shell
799
star
14

heroku-buildpack-ruby

Heroku's Ruby Buildpack
Ruby
778
star
15

hk

DEPRECATED: see
Go
709
star
16

heroku-buildpack-static

[DEPRECATED] Heroku buildpack for handling static sites and single page web apps
Ruby
681
star
17

heroku-repo

Plugin for heroku CLI that can manipulate the repo
JavaScript
680
star
18

vegur

Vegur: HTTP Proxy Library
Erlang
620
star
19

heroku-accounts

Helps use multiple accounts on Heroku.
JavaScript
548
star
20

django-heroku

[DEPRECATED] Do not use! See https://github.com/heroku/django-heroku/issues/56
Python
465
star
21

heroku-buildpack-pgbouncer

Run pgbouncer in a dyno along with your application
Shell
335
star
22

devcenter-embedded-tomcat

Java
330
star
23

webapp-runner

Lightweight Application Launcher. Launch your webapp in the most popular open source web container available with a single command.
Java
319
star
24

docker-registry-client

A Go API client for the v2 Docker Registry API
Go
287
star
25

heroku-buildpack-google-chrome

Run (headless) Google Chrome on Heroku
Shell
283
star
26

stack-images

Recipies for building Heroku's stack images
Shell
264
star
27

java-getting-started

Getting Started with Java on Heroku
HTML
248
star
28

identity

[DEPRECATED] Login and OAuth management service for Heroku
CSS
247
star
29

go-getting-started

Getting Started with Go on Heroku https://devcenter.heroku.com/articles/getting-started-with-go
Dockerfile
246
star
30

heroku-buildpack-nginx

Run NGINX in a Heroku app
Shell
242
star
31

heroku-buildpack-apt

Buildpack that installs APT based dependencies
Shell
239
star
32

log-shuttle

HTTP log transport.
Go
236
star
33

terrier

Terrier is a Image and Container analysis tool that can be used to scan Images and Containers to identify and verify the presence of specific files according to their hashes.
Go
227
star
34

umpire

HTTP metrics monitoring endpoint
Ruby
221
star
35

platform-api

Ruby HTTP client for the Heroku API
Ruby
211
star
36

starboard

onboarding, offboarding, or crossboarding made easy
SCSS
204
star
37

salesforce-bulk

Python interface to the Salesforce.com Bulk API
Python
203
star
38

php-getting-started

Getting Started with PHP on Heroku
Twig
200
star
39

heroku-container-tools

DEPRECATED Heroku Toolbelt plugin to help configure, test and release apps to Heroku using local containers.
JavaScript
195
star
40

heroku-buildpack-scala

Heroku buildpack: Scala
Shell
190
star
41

node-heroku-client

A wrapper around the Heroku API for Node.js
JavaScript
188
star
42

vulcan

A build server in the cloud.
Ruby
172
star
43

pg_lock

Use Postgres advisory lock to isolate code execution across machines
Ruby
168
star
44

awsdetailedbilling

A toolkit for importing AWS detailed billing reports into Redshift
JavaScript
167
star
45

heroku-buildpack-java

A Heroku buildpack for Java apps.
Shell
167
star
46

pulse

DEPRECATED: Real-time Heroku operations dashboard
Clojure
161
star
47

heroku.rb

DEPRECATED! Official Heroku Ruby Legacy API wrapper
Ruby
161
star
48

heroku-buildpack-multi

[DEPRECATED] Please use https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app instead
Shell
157
star
49

erlang-in-anger

A little guide about how to be the Erlang medic in a time of war. It is first and foremost a collection of tips and tricks to help understand where failures come from, and a dictionary of different code snippets and practices that helped developers debug production systems that were built in Erlang.
TeX
157
star
50

plexy

A toolkit for building excellent APIs with Elixir
Elixir
154
star
51

heroku-buildpack-multi-procfile

Everyone gets a Procfile!
Shell
150
star
52

log2viz

DEFUNCT: Realtime analysis of your Heroku app logs.
Ruby
145
star
53

heroku.py

DEPRECATED! Heroku API wrapper for Python.
Python
142
star
54

facebook-template-nodejs

JavaScript
136
star
55

ruby-getting-started

Getting Started with Ruby on Heroku
Ruby
120
star
56

heroku-buildpack-chromedriver

Installs chromedriver in a Heroku slug
Shell
117
star
57

heroku-buildpack-clojure

Heroku's buildpack for Clojure applications.
Shell
115
star
58

mobile-template1

JavaScript
115
star
59

instruments

Collecting metrics over discrete time intervals
Go
112
star
60

heroku-sbt-plugin

An sbt plugin for deploying Heroku Scala applications
Scala
111
star
61

heroku-buildpack-erlang

Erlang buildpack
Shell
107
star
62

terraform-provider-heroku

Terraform Heroku provider
Go
99
star
63

cli-engine

TypeScript
97
star
64

semver.io

*DEPRECATED* The semver.io instance has now been sunset: https://github.com/heroku/semver.io/issues/74
CoffeeScript
96
star
65

facebook-template-php

example facebook app for heroku
PHP
96
star
66

dotnet-buildpack

ASP.NET 5 Buildpack
Shell
92
star
67

kensa

A tool to help Heroku add-on providers integrate their services with Heroku
Ruby
92
star
68

netrc

Reads and writes netrc files.
Ruby
89
star
69

hstore_example

Ruby
89
star
70

alpinehelloworld

An Alpine-based Docker example
Python
85
star
71

heroku-kong

🐒 Kong API gateway as a Heroku app
Lua
84
star
72

heroku-buildpack-hello

Shell
82
star
73

heroku-releases-retry

CLI plugin to allow retrying the latest release-phase command
JavaScript
79
star
74

faceplate

A Node.js wrapper for Facebook authentication and API
JavaScript
76
star
75

rails_stdout_logging

Logs to stdout so you don't have to
Ruby
76
star
76

shaas

Shell as a Service: API to inspect and execute scripts in a server's environment via HTTP and WebSockets
Go
75
star
77

devcenter-spring-mvc-hibernate

AspectJ
75
star
78

heroku-buildpack-core-data

A Heroku Buildpack that generates a REST webservice from a Core Data model
Shell
74
star
79

heroku-buildpack-emberjs

**This buildpack is deprecated!** Please use the official Node.js buildpack combined with the static or nginx buildpack instead.
Ruby
72
star
80

facebook-template-python

Python
69
star
81

devcenter-java

Java
62
star
82

heroku-buildpack-c

C Language Pack
Shell
62
star
83

nibs

JavaScript
61
star
84

heroku-buildpack-gradle

This is a Heroku buildpack for Gradle apps. It uses Gradle to build your application and OpenJDK to run it.
Shell
61
star
85

heroku-buildpack-ember-cli

A Heroku buildpack for ember-cli apps; powers dashboard.heroku.com
Shell
60
star
86

heroku-guardian

Easy to use CLI security checks for the Heroku platform. Validate baseline security configurations for your own Heroku deployments.
Python
60
star
87

cnb-builder-images

Recipes for building Heroku's Cloud Native Buildpacks builder images
Java
59
star
88

list-of-ingredients

An example of using Create React App with Rails 5 API and ActiveAdmin on Heroku
Ruby
57
star
89

heroku-fork

Heroku CLI plugin to fork an existing app into a new app
JavaScript
55
star
90

salesforce-buildpack

Heroku Buildpack for Salesforce
Shell
53
star
91

ruby-rails-sample

Ruby
52
star
92

facebook-template-ruby

CSS
52
star
93

heroku-jupyterlab

An example of running JupyterLab on Heroku, with Amazon S3.
Python
52
star
94

heroku-maven-plugin

This plugin is used to deploy Java applications directly to Heroku without pushing to a Git repository.
Java
51
star
95

stillir

Cache environment variables as Erlang app variables
Erlang
51
star
96

rails_serve_static_assets

Ruby
49
star
97

heroku-gradle-plugin

A Gradle plugin for deploying JAR and WAR files to Heroku.
Java
49
star
98

x

A set of packages for reuse within Heroku Go applications
Go
49
star
99

template-java-spring-hibernate

Java
48
star
100

scala-getting-started

Getting Started with Scala / Play on Heroku
HTML
48
star