Why is this Go build failing on Heroku? It builds locally with no issue - go

Is anyone able to tell me why this build has failed on heroku?
I've tried finding substitute packages and tidying the mod file, even deleting it and redoing it.
here is my build log
Overview Resources Deploy Metrics Activity Access Settings
Activity Feed Build LogID f8e9d5ce-0d8f-4e8e-8b2a-661c4d1f68f7
-----> Building on the Heroku-20 stack
-----> Go app detected
-----> Fetching stdlib.sh.v8... done
----->
Detected go modules via go.mod
----->
Detected Module Name: github.com/xxxxxx/xxxxxx-xxxxxx
----->
!! The go.mod file for this project does not specify a Go version
!!
!! Defaulting to go1.12.17
!!
!! For more details see: https://devcenter.heroku.com/articles/go-apps-with-modules#build-configuration
!!
-----> Using go1.12.17
-----> Determining packages to install
Detected the following main packages to install:
github.com/xxxxxx/xxxxxx-xxxxxx
-----> Running: go install -v -tags heroku github.com/xxxxxx/xxxxxx-companion
github.com/vektah/gqlparser/v2/ast
github.com/agnivade/levenshtein
github.com/mitchellh/mapstructure
github.com/vektah/gqlparser/v2/gqlerror
github.com/99designs/gqlgen/graphql
# github.com/99designs/gqlgen/graphql
../codon/tmp/cache/go-path/pkg/mod/github.com/99designs/gqlgen#v0.13.0/graphql/error.go:21:5: undefined: errors.As
github.com/99designs/gqlgen/graphql/errcode
github.com/vektah/gqlparser/v2/lexer
github.com/hashicorp/golang-lru/simplelru
github.com/vektah/gqlparser/v2/parser
github.com/hashicorp/golang-lru
github.com/gorilla/websocket
github.com/vektah/gqlparser/v2/validator
github.com/99designs/gqlgen/graphql/playground
github.com/xxxxxx/xxxxxx-xxxxxx/graph/model
github.com/xxxxxx/xxxxxx-xxxxxx/database
github.com/99designs/gqlgen/graphql/introspection
github.com/vektah/gqlparser/v2/validator/rules
github.com/go-sql-driver/mysql
github.com/vektah/gqlparser/v2
! Push rejected, failed to compile Go app.
! Push failed
Here is my go.mod file:
module github.com/xxxxxx/xxxxxx-xxxxxx
go 1.15
require (
github.com/99designs/gqlgen v0.13.0
github.com/go-sql-driver/mysql v1.5.0
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238 // indirect
github.com/stretchr/testify v1.5.1 // indirect
github.com/vektah/gqlparser/v2 v2.1.0
gopkg.in/yaml.v2 v2.2.8 // indirect
)
I'm at a complete loss, I suspect it has to do with an incorrect version, but the build log doesn't give me much to go on. How can I diagnose this kind of issue in the future?
Thank you.

You could add a directive // +heroku goVersion go1.15 in your go.mod file.
module somemodule
// +heroku goVersion go1.15
go 1.15
require (
// ...
)
Then it should look like this.
remote: Detected go modules via go.mod
remote: ----->
remote: Detected Module Name: somemodule
remote: ----->
remote: -----> New Go Version, clearing old cache
remote: -----> Installing go1.15
Documentation: https://github.com/heroku/heroku-buildpack-go#go-module-specifics
Go Module Specifics
You can specify specific package spec(s) via the go.mod file's // +heroku install directive (see below).
// +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].

Coming back to mark this one complete, I figured out that by specifying in the go mod file
// +heroku goVersion go1.15
Go buildback supports arbitrary comments specifiying versioning before build.
https://github.com/heroku/heroku-buildpack-go#go-module-specifics
Thank you as well to user #JimB for pointing me in the right direction.

Related

Deploying Go app on Google Cloud 'missing go.sum entry'

I'm trying to deploy a simple API on Google Cloud using Go 1.19
> go version
go version go1.19.2 windows/amd64
I'm following this documentation as a template to deploy my app. But the deploy fails.
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build xxx status: FAILURE
go: github.com/go-redis/redis/v9#v9.0.0-rc.1 requires
github.com/onsi/ginkgo#v1.16.5: missing go.sum entry; to add it:
go mod download github.com/onsi/ginkgo
Cloud build log:
Running "go build -o /layers/google.go.build/bin/main . (GOCACHE=/layers/google.go.build/gocache)"
go: github.com/go-redis/redis/v9#v9.0.0-rc.1 requires
github.com/onsi/ginkgo#v1.16.5: missing go.sum entry; to add it:
go mod download github.com/onsi/ginkgo
Done "go build -o /layers/google.go.build/bin/main . (GOCACHE=/lay..." (7.516802ms)
Failure: (ID: 721b15b4) go: github.com/go-redis/redis/v9#v9.0.0-rc.1 requires
github.com/onsi/ginkgo#v1.16.5: missing go.sum entry; to add it:
go mod download github.com/onsi/ginkgo
--------------------------------------------------------------------------------
Running "mv -f /builder/outputs/output-5577006791947779410 /builder/outputs/output"
Done "mv -f /builder/outputs/output-5577006791947779410 /builder/o..." (3.938721ms)
ERROR: failed to build: exit status 1
Running the suggested go mod download github.com/onsi/ginkgo does not solve anything.
Also tried go mod tidy as suggested in another posts but same results. Also tried with vendor folder, but nothing again.
This is my app.yaml
runtime: go116
go.mod
module notams/anac
go 1.19
require (
github.com/go-redis/redis/v9 v9.0.0-rc.1
github.com/gorilla/mux v1.8.0
github.com/joho/godotenv v1.4.0
golang.org/x/exp v0.0.0-20221019170559-20944726eadf
)
require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
)
go.sum
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/go-redis/redis/v9 v9.0.0-rc.1 h1:/+bS+yeUnanqAbuD3QwlejzQZ+4eqgfUtFTG4b+QnXs=
github.com/go-redis/redis/v9 v9.0.0-rc.1/go.mod h1:8et+z03j0l8N+DvsVnclzjf3Dl/pFHgRk+2Ct1qw66A=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.21.1 h1:OB/euWYIExnPBohllTicTHmGTrMaqJ67nIu80j0/uEM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
golang.org/x/exp v0.0.0-20221019170559-20944726eadf h1:nFVjjKDgNY37+ZSYCJmtYf7tOlfQswHqplG2eosjOMg=
golang.org/x/exp v0.0.0-20221019170559-20944726eadf/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
EDIT 1: Already tried to change runtime: go and to runtime: go119 but those are not supported and return "invalid go runtime".
To anyone who might have this problem, I just deployed the app on Cloud Run instead of App Engine and everything runs smoothly. I was not able to deploy it on App Engine and i think that the only way to do so is adapting the code and modules to the latest runtime version available for GCP (currently Go 1.16).

Why can't Heroku build my app with dependencies?

I have been working on a Go project and deploying it successfully with Heroku up until I added more packages. My Heroku app is set up to deploy the main branch of my github repo, but it fails to build the app each time I push. This is the build log:
-----> Using buildpack: heroku/go
-----> Go app detected
-----> Fetching stdlib.sh.v8... done
----->
Detected go modules via go.mod
----->
Detected Module Name: my-heroku-app
----->
-----> New Go Version, clearing old cache
-----> Installing go1.17.3
-----> Fetching go1.17.3.linux-amd64.tar.gz... done
-----> Determining packages to install
Detected the following main packages to install:
my-heroku-app
-----> Running: go install -v -tags heroku -mod=vendor my-heroku-app
webapp.go:6:2: cannot find package "." in:
/tmp/build_1bdd9ef1/vendor/github.com/go-sql-driver/mysql
webapp.go:7:2: cannot find package "." in:
/tmp/build_1bdd9ef1/vendor/github.com/gorilla/context
webapp.go:8:2: cannot find package "." in:
/tmp/build_1bdd9ef1/vendor/github.com/gorilla/sessions
webapp.go:9:2: cannot find package "." in:
/tmp/build_1bdd9ef1/vendor/golang.org/x/crypto/bcrypt
! Push rejected, failed to compile Go app.
! Push failed
Here is what my import statement looks like
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/gorilla/context"
"github.com/gorilla/sessions"
"golang.org/x/crypto/bcrypt"
"html/template"
"log"
"net/http"
"time"
"unicode"
)
I have tried reading through the guides and documentation about govendor both at Heroku and on their github page, and as far as I can tell, I have done my setup correctly. I am currently using govendor and I have a vendor folder containing a json file in my repo that has the info for the dependencies. Everything works when I run it locally
update: I made a fresh repo with minimal code but as soon as I add a dependency I got the same error. I also tried deploying on Digital Ocean as well but I think they use the open source Heroku buildpack so I got the same error
update 2: I got a pared down version of the app working. The repo has no vendor directory or vendor json whatsoever despite using an external package (build log shows successful install of external package)

Heroku, providing a deb dependency to Go project through APT buildpack does not work out

I have a PDF conversion package in my Go project which relies upon "wkhtmltox" debian package. I install "wkhtmltopdf" (similar to "wkhtmltox") through APT buildpack before running a Go buildpack. The "wkhtmltopdf" has been tested locally, and in this case Go project builds perfectly. But when I do it in Heroku, it does not work out, and fails with the same error as would pop out in case no "wkhtmltox" nor "wkhtmltopdf" was installed. The successfully installed "wkhtmltopdf" :
remote: -----> Installing wkhtmltopdf_0.12.5-1build1_amd64.deb
The error :
remote: ../codon/tmp/cache/go-path/pkg/mod/github.com/adrg/go-wkhtmltopdf#v0.2.2/converter.go:7:10: fatal error: wkhtmltox/pdf.h: No such file or directory
remote: 7 | #include <wkhtmltox/pdf.h>
remote: | ^~~~~~~~~~~~~~~~~
remote: compilation terminated.
Is there someone with similar experience ? Is it possible that for Go the installed package is simply not available without some additional manipulations ?

go.mod has post-v2 module path at revision v2.0.0

I have a rest api I built in Go with gin that has been working for months now on my local machine running 1.12.1. I decided it was going to a docker deploy so I started building with 1.12.6 when I started see errors during module retrieval. I went back to my local machine, ran running 1.12.1 and ran go clean -modcache, now the error is there as well. I've tried regenerating multiple times even editing the go.sum file to different versions of gofight but I'm lost and run out of ideas.
The output w/error:
go: github.com/appleboy/gofight#v2.0.0+incompatible: go.mod has post-v2 module path "github.com/appleboy/gofight/v2" at revision v2.0.0
go: error loading module requirements
go.mod
module go-hybrid-alert
go 1.12
require (
cloud.google.com/go v0.37.0
firebase.google.com/go v3.6.0+incompatible
github.com/Luzifer/go-openssl v2.0.0+incompatible
github.com/PuerkitoBio/goquery v1.5.0
github.com/antchfx/htmlquery v1.0.0 // indirect
github.com/antchfx/xmlquery v1.0.0 // indirect
github.com/antchfx/xpath v0.0.0-20190129040759-c8489ed3251e // indirect
github.com/appleboy/gin-jwt v0.0.0-20190216100112-ca1084e5d5a2
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect
github.com/gin-gonic/gin v1.3.0
github.com/go-redis/redis v6.15.2+incompatible
github.com/gobwas/glob v0.2.3 // indirect
github.com/gocolly/colly v1.2.0
github.com/kennygrant/sanitize v1.2.4 // indirect
github.com/kisielk/godepgraph v0.0.0-20181003180210-9a9a3d47fba3 // indirect
github.com/levigross/grequests v0.0.0-20190130132859-37c80f76a0da // indirect
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/mitchellh/mapstructure v1.1.2
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
github.com/temoto/robotstxt v0.0.0-20180810133444-97ee4a9ee6ea // indirect
github.com/ugorji/go/codec v0.0.0-20190316083543-95c34d148dff // indirect
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a
golang.org/x/net v0.0.0-20190313220215-9f648a60d977
google.golang.org/api v0.2.0
gopkg.in/dgrijalva/jwt-go.v3 v3.2.0 // indirect
gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
)
go.sum (the line for the module in question, posting the whole thing exceeds SO post length)
github.com/appleboy/gofight v2.0.0+incompatible/go.mod h1:H/tvof1oZHnZdlBd+AeODZGkk1C+D2na0NXr0iXuZHA=
I've also tried adjusting the go 1.12 statement in go.mod for the specific subversions I'm attempting to build with but that had no effect.
What does this error mean? How can I fix it?
A number of packages were outdated, the main fix was to run the new install command for gin-jwt, go get github.com/appleboy/gin-jwt/v2
Ultimately though I just nuked my go.mod and go.sum and did a fresh sync in Goland IDE. Everything is working on 1.12+

Create-react-app build failing on heroku when using absolute paths

When using absolute paths in my CRA, the build step fails on heroku.
NODE_PATH=src/
Is in my .env.local file and also use this env var in my heroku settings.
I try to build my app on heroku using the "heroku-postbuild" script (which just runs "react-scripts build". I am using an express server to serve this build folder and to proxy requests to various API's.
this is the error I get:
remote: Running heroku-postbuild (yarn) remote: yarn run
v1.14.0 remote: $ react-scripts build remote: Creating
an optimized production build... remote: Failed to compile.
remote: remote: ./src/app/App.js remote: Cannot find
module: 'checklist/Checklist'. Make sure this package is installed.
remote: remote: You can install this package by running: yarn
add checklist/Checklist. remote: remote: remote: error Command failed
with exit code 1.
the Checklist.js file is located under: "src/checklist/Checklist.js"
Any idea what I need to do to make this work?
I had this issue and it seemed to be a result of my local file having a different casing than the one committed to git. i.e. if you have a file Checklist.js committed to git and are trying to import checklist from 'checlist/checklist.js', run git mv [...]/checklist.js [...]/Checklist.js.
See this issue comment for the original answer that got me here.
Just create a jsconfig.json file on the root of your project and paste this(if you use src as the starting point for your absolute imports
{
"compilerOptions": {
"baseUrl": "./src"
}
}

Resources