Giter Club home page Giter Club logo

heroku-buildpack-go's Introduction

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.

heroku-buildpack-go's People

Contributors

abitrolly avatar attilaolah avatar azr avatar bmizerany avatar cga1123 avatar danielleadams avatar danp avatar dzuelke avatar edmorley avatar heroku-linguist[bot] avatar hone avatar jboursiquot-sfdc avatar jmorrell avatar josharian avatar joshwlewis avatar kennyp avatar kotarou1192 avatar kr avatar kyleconroy avatar lstoll avatar mmcgrana avatar owenthereal avatar rochesterinnyc avatar ryanbrainard avatar schneems avatar sheax0r avatar sowjumn avatar thepwagner avatar tt avatar xe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heroku-buildpack-go's Issues

Should be possible to ignore .go files?

I'm having trouble deploying my app since I have a few .go files (database migration scripts) that I don't want to be compiled but I want to be part of the repo. Would it be possible to add support to ignore certain files/folders?

runtime.main: call to external function main.main
runtime.main: undefined: main.main

 !     Push rejected, failed to compile Go app

Erroneous Error Message on Build Failure

There are cases where the build fails, but the error message is erroneous:

screen shot 2014-12-12 at 10 20 16 am

First, it directs you to http://mmcgrana.github.io/2012/09/getting-started-with-go-on-heroku for info on how to configure a .godir file, but there is no reference to .godir on that tutorial.

Second, I don't think lack of a .godir file is the problem. I received that message on another application that I was finally able to get working, without adding a .godir. I believe it was a folder structure issue in that case.

Build inconsistency when pushing go to Heroku

Hey @freeformz, I might need some expert help with one :) I have a project that I've managed to push to Heroku many times successfully in the past, but after a minor refactor, will no longer build.

It seems that the package that I refactored can't be located:

$ git push staging master
Counting objects: 544, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (308/308), done.
Writing objects: 100% (544/544), 249.16 KiB | 0 bytes/s, done.
Total 544 (delta 203), reused 517 (delta 185)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Go app detected
remote: -----> Checking Godeps/Godeps.json file.
remote: -----> Using go1.4.2
remote: -----> Running: godep go install -tags heroku ./...
remote: cmd/midgard-drip/main.go:6:2: cannot find package "github.com/heroku/midgard/log" in any of:
remote:         /app/tmp/cache/go1.4.2/go/src/github.com/heroku/midgard/log (from $GOROOT)
remote:         /tmp/build_cb970858d6be73d56650d7d715998909/.heroku/go/src/github.com/heroku/midgard/Godeps/_workspace/src/github.com/heroku/midgard/log (from $GOPATH)
remote:         /tmp/build_cb970858d6be73d56650d7d715998909/.heroku/go/src/github.com/heroku/midgard/log
remote: godep: go exit status 1
remote:
remote:  !     Push rejected, failed to compile Go app
remote:
remote: Verifying deploy....
remote:
remote: !       Push rejected to midgard-staging.
remote:
To https://git.heroku.com/midgard-staging.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/midgard-staging.git'

It builds fine on Travis though, and also locally:

$ godep go install -tags heroku ./...
$

It seems that the package is in the expected directory:

$ pwd
/Users/brandur/Documents/go/src/github.com/heroku/midgard
$ ls log
log.go          log_test.go

And that the files within the package correctly define their package:

$ head -n 1 log/*
==> log/log.go <==
package log

==> log/log_test.go <==
package log

Git is clean:

$ git status
On branch master
nothing to commit, working directory clean

The project is located at heroku/midgard if you want to take a look. Any ideas? Possibly a caching issue?

Appengine 1.8.3 not found in archive

Hi I followed the demoapp example and it appears there is an error on Heroku when trying to deploy the app. Any ideas?

$ git push heroku master
Initializing repository, done.
Counting objects: 109, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (99/99), done.
Writing objects: 100% (109/109), 1.42 MiB | 653.00 KiB/s, done.
Total 109 (delta 24), reused 0 (delta 0)

-----> Fetching custom git buildpack... done
-----> Go app detected
/tmp/buildpack_4667910b-50c3-4633-9e28-94b21107bd7e/bin/compile: line 85: test: /app/tmp/cache/go1.1.1: binary operator expected
-----> Installing go1.1.1 (appengine-1.8.3)...tar: go1.1.1: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: (appengine-1.8.3).linux-amd64.tar.gz: Not found in archive
tar: Exiting with failure status due to previous errors

Go 1.4.2 released!

Can we upgrade this build pack to 1.4.2 please!

https://golang.org/doc/devel/release.html

go1.4.2 (released 2015/02/17) includes bug fixes to the go command, the compiler and linker, and the runtime, syscall, reflect, and math/big packages. See the Go 1.4.2 milestone on our issue tracker for details.

should verify Godeps and Godeps.json file format prior to parsing by jq

I asked this question for help from stackoverflow about following error message reported from buildpack:

-----> Downloaded app package (556K)
Cloning into '/tmp/buildpacks/buildpack-go'...
Submodule 'compile-extensions' (https://github.com/cloudfoundry-incubator/compile-extensions.git) registered for path 'compile-extensions'
Cloning into 'compile-extensions'...
Submodule path 'compile-extensions': checked out 'f752ecf4b27d2f31bb082dfe7a47c76fefc769d7'
-------> Buildpack version 1.4.0
parse error: Expected separator between values at line 32, column 3
Staging failed: Buildpack compilation step failed

root cause

It costs me some time to locate this parse error because it doesn't provide any information about context. Although I figured it out that it was caused by a missing comma from Godeps/Godeps.json during code merge. since I can not reproduce this locally since all dependencies in _workspace is ready and I can not discover this json file format until running command godep update.

expectation

it should verify Godeps or Godeps.json file format during compiling although it just reads ImportPath and GoVersion in bin/compile.

Deploy error: GOPATH not defined

I'm getting the following error on the application deployment:
2015-03-30T17:48:22.667772+00:00 heroku[web.1]: Starting process with commandmyapp -port=180792015-03-30T17:48:23.992476+00:00 app[web.1]: 2015/03/30 17:48:23 GOPATH not defined, please define it 2015-03-30T17:48:24.758054+00:00 heroku[web.1]: State changed from starting to crashed

Question: Does the app name has to be same as the heroku's app name?

Should recognize valid code.google.com certificate

As part of building, I see the following:

-----> Running: godep go get -tags heroku ./...
warning: code.google.com certificate with fingerprint 76:9a:5d:41:30:bd:48:c6:93:56:16:1d:e7:c3:89:ff:62:60:ca:f3 not verified (check hostfingerprints or web.cacerts config setting)
-----> Discovering process types

This does not happen locally, so presumably the cert is legit:

maciek@gamera:~/code/aux/go/src/code.google.com/p/go.crypto$ hg pull
pulling from https://code.google.com/p/go.crypto
searching for changes
adding changesets
adding manifests
adding file changes
added 16 changesets with 50 changes to 30 files
(run 'hg update' to get a working copy)
maciek@gamera:~/code/aux/go/src/code.google.com/p/go.crypto$

Cannot fetch dependencies using bzr

Similar to #33, but opening another issue because this seems to be slightly different (if not, apologies for the redundancy).

Here's the relevant portion of the error I get:

Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 876 bytes | 0 bytes/s, done.
Total 8 (delta 5), reused 0 (delta 0)

-----> Fetching custom git buildpack... done
-----> Go app detected
-----> Using go1.1.2
-----> Running: go get -tags heroku ./...
# cd .; bzr branch https://launchpad.net/mgo/v2 /tmp/build_c43062fc-8c32-437f-9bfd-4ccc909fde22/.heroku/g/src/labix.org/v2/mgo
package github.com/gorilla/pat
        imports github.com/gorilla/context
        imports github.com/gorilla/mux
        imports github.com/gorilla/sessions
        imports github.com/gorilla/securecookie
        imports github.com/jteeuwen/go-pkg-rss
        imports github.com/jteeuwen/go-pkg-xmlx
        imports labix.org/v2/mgo: fork/exec /app/tmp/cache/venv/bin/bzr: no such file or directory
package github.com/gorilla/pat
        imports github.com/gorilla/context
        imports github.com/gorilla/mux
        imports github.com/gorilla/sessions
        imports github.com/gorilla/securecookie
        imports github.com/jteeuwen/go-pkg-rss
        imports github.com/jteeuwen/go-pkg-xmlx
        imports labix.org/v2/mgo/bson
        imports labix.org/v2/mgo/bson
        imports labix.org/v2/mgo/bson: cannot find package "labix.org/v2/mgo/bson" in any of:
        /app/tmp/cache/go1.1.2/go/src/pkg/labix.org/v2/mgo/bson (from $GOROOT)
        /tmp/build_c43062fc-8c32-437f-9bfd-4ccc909fde22/.heroku/g/src/labix.org/v2/mgo/bson (from $GOPATH)

 !     Push rejected, failed to compile Go app

Support for Nut

It would be great if this buildpack supported Nut, a pretty popular dependency manager for Go. I'm working on this on a fork, but I'm curious if anyone else is interested in having this added to the buildpack.

godep failing to install dependencies

I've been receiving an error today when performing a git push heroku master:

-----> Running: godep go install -tags heroku ./...
# cd /tmp/godep/repo/code.google.com/p/go.net; hg init
godep: create repo: fork/exec /app/tmp/cache/venv/bin/hg: no such file or directory

Nothing has changed on my app in terms of the Godeps file, and I've tried debugging this with more output from my own fork of the buildpack, but I've gotten nowhere.

Is this a known issue at this time? Any advice? FWIW, my last successful push was on 2013/11/14

Thanks!

Tag releases?

I know this isn't quite the go way, but would be useful indicators of library growth etc..

Compile failing

Heroku shows a message like this:

/tmp/buildpack_3522ef9c-5f57-4fc6-9ec0-57759c5e142d/bin/compile: line 85: test: too many arguments
mkdir: invalid option -- '0'

GO_GIT_DESCRIBE_SYMBOL=main.version seems to break the build.

Adding GO_GIT_DESCRIBE_SYMBOL as described at https://github.com/kr/heroku-buildpack-go#setting-the-version-at-build-time seems to cause the build to fail.

-----> Fetching custom git buildpack... done
-----> Go app detected
-----> Using go1.2
fatal: Not a git repository (or any parent up to mount point /app)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

 !     Push rejected, failed to compile Go app

screenshot 2015-01-14 11 39 05

Repo is https://github.com/jelder/beacon/

Support cgo flags

I tried to compile a Go app that depends on a package with C dependencies, and I had to use CGO_CFLAGS to point it to the right (app-vendored) directory for header files. I initially tried to add support to the buildpack for all the CGO_* env vars by using the new buildpack app env access feature, but, e.g., I realized that CFLAGS like -I want an absolute path, which is not that useful since the build does not take place in a stable, well-known directory.

I ended up doing a hack to just hard-code CGO_CFLAGS in a fork of the buildpack, but I wonder if there's a sensible way we could support CGO_* flags somehow. Any thoughts on that?

Heroku removes '.git' dir before build

I attempted to set GO_GIT_DESCRIBE_SYMBOL but kept encountering the following error:

-----> Fetching custom git buildpack... done
-----> Go app detected
-----> Installing go1.3.1... done
fatal: Not a git repository: '.'

 !     Push rejected, failed to compile Go app

To [email protected]:foobar

After unsetting GO_GIT_DESCRIBE_SYMBOL everything worked. Looking around online it appears that Heroku strips the .git directory before the buildpack is executed.

Failed to compile the sample project (bin/compile error)

-----> Go app detected
/tmp/buildpack-70756fc3-344a-46dd-8c9d-5c1971343683/bin/compile: line 68: test: too many arguments
----> Installing go version go1.1.2 darwin/amd64...
! Push rejected, failed to compile Go app

It does not matter what the .go file is. The same error happens even with the simplest go program.
Seems related to the recent change of /bin/compile
EDIT: the reason is there're spaces in version variable in Godeps file. "go version go 1.1.2 darwin/amd64"

BTW: I don't know why it installs the darwin/amd64 since Heroku apparently uses Linux.

Importing local packages fails (unrecognized import path)

I'm trying to deploy a project with that uses a local package but it fails. It builds on my computer with no issues.

Part of the deploy log:

imports github.com/lib/pq
imports code.google.com/p/go.crypto/blowfish
imports myproject/api/session: unrecognized import path "myproject/api/session"

Do this buildpack assume that all packages can be downloaded with go get? Can it not use packages that are bundled with the app?

Would be great if someone could shed some light on this :)

Using Godep doesn't install binaries from other libraries

Not really sure if this this is a buildpack issue, a godep issue, or even an issue at all, but if I have a dependency that is expected to create a binary to use, godep go get doesn't move artifacts from bin in the sandbox path it uses for each dependency. Perhaps that's intended, but I'm not sure. This is what I have as a custom workaround: https://gist.github.com/shaunduncan/6904322

Again, I'm just curious if this is intended or not :)

Thanks!

Set PGSSLMODE env variable

Getting the connection string right for postgres on Heroku can be a bit trial-and-error due to a requirement of sslmode=require. I suspect many folks miss it and the log message isn’t very helpful.

Heroku’s DATABASE_URL doesn’t include this param, unfortunately. The pq library has been updated to help a bit, though it doesn’t address the SSL issue specifically.

I believe that Heroku will respect the PGSSLMODE environment variable. How about adding this to bin/release?

Here’s an example of the syntax.

std lib only webapps

Hi,

Yesterday I tried to upload a very simle app and it was a bit ridiculous.

My app is very simple, it's just serving a static index.html and a Json route, it's only std lib and very few lines.

First try : error, "you need .godir/Godeps thing".

Second try: I go get Godeps but it complains my app is not in GOPATH (whice I have no need to).

Third try: echo "myapp" > .godir, it works but I have now extra things to install.

I understand most apps needs at least one extra lib, like a router, but shouldn't be a way to install std only apps?

My understanding of the buildpack is you need a source of app name but can't we have an alternative like parsing the Procfile or a .godir-like without extra installs?

Trouble installing binaries from a 3rd party project

We have a Heroku app (repo A) used mainly for scheduling. I'd like to load another Go project (repo B) and its binaries as a dependency when repo A builds.

I got it working by adding both all of repo B's dependencies as Godeps, and then also adding repo B as a Git submodule, but this seems like a duplication of work. If I remove the Git submodule, I get warning: "./..." matched no packages. I could fork the buildpack and explicitly write godep go install github.com/repoB but this also seems bad.

Is there a better way?

buildpack compile succeeds even without Procfile

this should fail, right?

$ git push heroku master
Counting objects: 29, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (28/28), done.
Writing objects: 100% (29/29), 6.17 KiB, done.
Total 29 (delta 10), reused 0 (delta 0)
-----> Fetching custom git buildpack... done
-----> Go app detected
-----> Installing Go 1.0.3... done
       Installing Virtualenv... done
       Installing Mercurial... done
       Installing Bazaar... done
-----> Running: go get -tags heroku ./...
-----> Discovering process types
       Procfile declares types -> (none)
-----> Compiled slug size: 1.4MB
-----> Launching... done, v5
       http://my-go-app.herokuapp.com deployed to Heroku

Go 1.4.1 not supported?

From the error message when trying to push to Heroku it appears that version 1.4.1 might not be supported by the buildpack:

screen shot 2015-02-02 at 11 14 56 am

Fails to compile basic go app

remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Go app detected
remote: -----> Checking Godeps/Godeps.json file.
remote: /app/tmp/buildpacks/go/bin/compile: line 113: test: /app/tmp/cache/go1.5: binary operator expected
remote: -----> Installing go1.5 darwin/amd64... tar (child): go1.5: Cannot open: No such file or directory
remote: tar (child): Error is not recoverable: exiting now
remote: tar: Child returned status 2
remote: tar: Error is not recoverable: exiting now
remote:
remote:  !     Push rejected, failed to compile Go app
remote:
remote: Verifying deploy....

Fetching dependencies fails with Python exception

When pushing a new version of my Go app to Heroku, the process fails with:

cd .; hg clone -U https://code.google.com/p/go-uuid /tmp/build_3bf11f97-2087-47a6-a45f-119ef80e1247/.heroku/g/src/code.google.com/p/go-uuid
Traceback (most recent call last):
File "/app/tmp/cache/venv/bin/hg", line 36, in
mercurial.util.setbinary(fp)
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 102, in getattribute
self._load()
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 74, in _load
mod = _hgextimport(_import, head, globals, locals, None, level)
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 43, in _hgextimport
return importfunc(name, globals, _args)
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/util.py", line 16, in
from i18n import _
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 130, in _demandimport
mod = _hgextimport(_origimport, name, globals, locals)
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 43, in _hgextimport
return importfunc(name, globals, *args)
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/i18n.py", line 23, in
t = gettext.translation('hg', localedir, fallback=True)
File "/usr/local/lib/python2.7/gettext.py", line 465, in translation
mofiles = find(domain, localedir, languages, all=1)
File "/usr/local/lib/python2.7/gettext.py", line 437, in find
for nelang in _expand_lang(lang):
File "/usr/local/lib/python2.7/gettext.py", line 131, in _expand_lang
from locale import normalize
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 111, in _demandimport
return _hgextimport(_import, name, globals, locals, fromlist, level)
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 43, in _hgextimport
return importfunc(name, globals, *args)
File "/app/tmp/cache/venv/lib/python2.7/locale.py", line 182, in
percent_re = re.compile(r'%(?:((?P.?)))?'
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 102, in getattribute
self._load()
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 74, in _load
mod = _hgextimport(_import, head, globals, locals, None, level)
File "/app/tmp/cache/venv/lib/python2.7/site-packages/mercurial/demandimport.py", line 43, in _hgextimport
return importfunc(name, globals, *args)
File "/app/tmp/cache/venv/lib/python2.7/re.py", line 222, in
_pattern_type = type(sre_compile.compile("", 0))
File "/app/tmp/cache/venv/lib/python2.7/sre_compile.py", line 502, in compile
code = _code(p, flags)
File "/app/tmp/cache/venv/lib/python2.7/sre_compile.py", line 484, in _code
_compile_info(code, p, flags)
File "/app/tmp/cache/venv/lib/python2.7/sre_compile.py", line 363, in _compile_info
lo, hi = pattern.getwidth()
File "/app/tmp/cache/venv/lib/python2.7/sre_parse.py", line 174, in getwidth
self.width = min(lo, MAXREPEAT - 1), min(hi, MAXREPEAT)
TypeError: unsupported operand type(s) for -: '_demandmod' and 'int'

Seems like an incompatible Python version?

use wildcard for patch-level versioning

Given I'm a Goalng app developer,
When I push my app to a cloud platform with "GoVersion": "1.4.*",
Then the golang buildpack should select the latest stable 1.4.x of golang,
And successfully stage the app.

This is reference to the discussion on godeps with @freeformz .

godep restore

Looks like the compile script assumes that Godeps/_workspace is included in the source code, is this by design? is there a change we could execute godep restore only if Godeps exists but Godeps/_workspace doesn't?

I can send a PR for this.

Retrieval of dependencies hosted in private GitHub repos

Is there explanation somewhere about jq tool's syntax. I am thinking to submit a patch but I need to understand, first, how jq works.

For instance, does it allow to iterate Deps vector in Godeps.json?
Basically I need something like this:

$ jq ... magic that selects only github imports ...
{"ImportPath": "github.com/...", "Rev": "e0ef2b43f0d1c074f7fdf649f72ddc0c5705fbae"}
{"ImportPath": "github.com/...", "Rev": "4d62057ae3c92030cab94d074b6874f2ff9aaebf"}

Is it this jq?

Problem installing dependencies from Github

Followed the guide, getting cannot find package for all of my Github-hosted dependencies. Pretty new to Go, so not sure if this is my fault or an actual bug.

Counting objects: 30, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (30/30), 5.24 KiB | 0 bytes/s, done.
Total 30 (delta 9), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Fetching custom git buildpack... done
remote: -----> Go app detected
remote: -----> Installing go1.2... done
remote: -----> Running: godep go install -tags heroku ./...
remote: beacon.go:7:2: cannot find package "github.com/dchest/uniuri" in any of:
remote:     /app/tmp/cache/go1.2/go/src/pkg/github.com/dchest/uniuri (from $GOROOT)
remote:     /tmp/build_0a32b34caa3cfe94f2dd00603ef45127/.heroku/g/src/github.com/jelder/beacon/Godeps/_workspace/src/github.com/dchest/uniuri (from $GOPATH)
remote:     /tmp/build_0a32b34caa3cfe94f2dd00603ef45127/.heroku/g/src/github.com/dchest/uniuri
remote: beacon.go:8:2: cannot find package "github.com/garyburd/redigo/redis" in any of:
remote:     /app/tmp/cache/go1.2/go/src/pkg/github.com/garyburd/redigo/redis (from $GOROOT)
remote:     /tmp/build_0a32b34caa3cfe94f2dd00603ef45127/.heroku/g/src/github.com/jelder/beacon/Godeps/_workspace/src/github.com/garyburd/redigo/redis (from $GOPATH)
remote:     /tmp/build_0a32b34caa3cfe94f2dd00603ef45127/.heroku/g/src/github.com/garyburd/redigo/redis
remote: godep: go exit status 1
remote:
remote:  !     Push rejected, failed to compile Go app
remote:
remote: Verifying deploy...
remote:
remote: !   Push rejected to beacon.
remote:
To https://git.heroku.com/beacon.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/beacon.git'

My Godeps/Godeps.json:

{
    "ImportPath": "github.com/jelder/beacon",
    "GoVersion": "go1.2",
    "Deps": [
        {
            "ImportPath": "github.com/dchest/uniuri",
            "Rev": "dc985c3409977cc7670dc2043f31d60bea764a51"
        },
        {
            "ImportPath": "github.com/garyburd/redigo/internal",
            "Rev": "61e2910408efd40dafb3c7d856a4cf8aeb5fb1c6"
        },
        {
            "ImportPath": "github.com/garyburd/redigo/redis",
            "Rev": "61e2910408efd40dafb3c7d856a4cf8aeb5fb1c6"
        }
    ]
}

App repo: https://github.com/jelder/beacon/

Error fetching custom buildback

Here's what happens:

[ issactrotts ~/go_workspace/src/example.com/server ] heroku create -s cedar --buildpack [email protected]:kr/heroku-buildpack-go.git
Creating immense-depths-6065... done, stack is cedar
BUILDPACK_URL=[email protected]:kr/heroku-buildpack-go.git
http://immense-depths-6065.herokuapp.com/ | [email protected]:immense-depths-6065.git
Git remote heroku added
[ issactrotts ~/go_workspace/src/example.com/server ] git push heroku master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 539 bytes, done.
Total 5 (delta 0), reused 0 (delta 0)

-----> Heroku receiving push
-----> Fetching custom buildpack... failed
! Heroku push rejected, error fetching custom buildpack

To [email protected]:immense-depths-6065.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:immense-depths-6065.git'

Installing Mercurial fail

Hi, when I do git push heroku master, it always fail,

-----> Fetching custom git buildpack... done
-----> Go app detected
-----> Installing Go 1.0.3... done
Installing Virtualenv... done
Installing Mercurial...

! Heroku push rejected, failed to compile Go app

Thanks,
Wang Yun

Error on push heroku master

Getting build error after upgrading to go 1.3 =>

Fetching repository, done.
Counting objects: 154, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (100/100), done.
Writing objects: 100% (117/117), 714.94 KiB | 52.00 KiB/s, done.
Total 117 (delta 27), reused 0 (delta 0)
-----> Fetching custom git buildpack... done
-----> Go app detected
/tmp/buildpack_0b82538c-7f3f-4e94-8679-2d2c4b01ff3c/bin/compile: line 85:
test: /app/tmp/cache/go1.3: binary operator expected
-----> Installing go1.3 darwin/amd64...tar: go1.3: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: darwin/amd64.linux-amd64.tar.gz: Not found in archive
tar: Exiting with failure status due to previous errors

Any idea what is causing this build error?

buildpack tests

The buildpack includes some test code but the status of this code isn't clear:

$ git rev-parse HEAD
635de31e5fad532a0a7b23d1760ff32ce91f059c

$ roundup -v
roundup version 0.0.5

$ roundup
compile
  it_compiles_go:                                  [FAIL]
    + '[' -n '' ']'
    + rm -rf cache
    + mkdir cache
    + test -f cache/src/go/release.r59/bin/gofmt
    + compile
    + : === Compiling
    + sh bin/compile build cache
    -----> ERROR: Please create .godir
    -----> See https://gist.github.com/299535bbf56bf3016cba for instructions
  it_skips_go_compile_if_exists:                   [FAIL]
    + test -f cache/src/go/release.r59/bin/gofmt
  it_compiles_app:                                 [FAIL]
    + compile
    + : === Compiling
    + sh bin/compile build cache
    -----> ERROR: Please create .godir
    -----> See https://gist.github.com/299535bbf56bf3016cba for instructions
  it_deletes_cache:                                [PASS]
detect
  it_is_go_if_go_files_under_src:                  [PASS]
  it_is_not_go_without_all_sh_or_go_files:         [PASS]
=========================================================
Tests:    6 | Passed:   3 | Failed:   3

It would be great if the readme provided instructions that you could copy-paste into a terminal to get the tests working.

Go get fails for private repos

The go get ./... stage obviously fails for private repos. Any idea how I could use a private repo with the buildpack?

Issue with my go version perhaps?

-----> Go app detected
/tmp/buildpack_fa8dcb8b-abd8-4b79-81ca-3ceb0ada8e00/bin/compile: line 85: test: too many arguments
-----> Installing devel +65bf677ab8d8 Mon Nov 25 13:36:16 2013 +1100...tar: devel: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: +65bf677ab8d8: Not found in archive
tar: Mon: Not found in archive
tar: Nov: Not found in archive
tar: 25: Not found in archive
tar: 13\:36\:16: Not found in archive
tar: 2013: Not found in archive
tar: +1100.linux-amd64.tar.gz: Not found in archive
tar: Exiting with failure status due to previous errors

My go version is:

go version devel +65bf677ab8d8 Mon Nov 25 13:36:16 2013 +1100 darwin/amd64

I can see that it's trying to install or untar every single argument in the version. Do I need to have a release candidate go version?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.