gcloud app deploy says: exec: "git": executable file not found in $PATH - go

I am struggling to deploy a simple Go app to Google App Engine flexible environment. (This is a very cut-down version of a larger app.) When I run gcloud app deploy --project=<projectID> it terminates with an error, and has this in its output:
...
Step #0: Status: Downloaded newer image for gcr.io/gcp-runtimes/go1-builder#sha256:68b86e4c97438df4c9e36c55ad724079b453398a0a44c29748fb5685eef73895
Step #0: gcr.io/gcp-runtimes/go1-builder#sha256:68b86e4c97438df4c9e36c55ad724079b453398a0a44c29748fb5685eef73895
Step #0: go: github.com/go-stack/stack#v1.8.0: git init --bare in /workspace/_gopath/pkg/mod/cache/vcs/6963ea18be763686e7a9697733dd92bfcc0d45b687afce82da04992523d91cd1: exec: "git": executable file not found in $PATH
Step #0: go: github.com/inconshreveable/log15#v0.0.0-20200109203555-b30bc20e4fd1: git init --bare in /workspace/_gopath/pkg/mod/cache/vcs/fe2a07d0f4107d9daa39043733e909094a5b926cca44d0f7269e7a2185dbef15: exec: "git": executable file not found in $PATH
Step #0: go: github.com/mattn/go-colorable#v0.1.6: git init --bare in /workspace/_gopath/pkg/mod/cache/vcs/f7e99db597f4d2fe3e4509a9af308dace72a13292b505deb909cd0df29c1468a: exec: "git": executable file not found in $PATH
Step #0: go: error loading module requirements
Finished Step #0
It does work if I delete go.mod, but (I think) I need go.mod to compile and test it locally. It does work if I don't import the external package, but of course I need external packages in my larger app. It does work if I choose the standard environment, but I need the flexible environment for my larger app.
How can I deploy this app successfully to a flexible environment?
My local Go is 1.13, and I have the latest version (292.0.0) of gcloud. Apart from go.sum, the contents of my directory is...
app.yaml:
runtime: go1.12
env: flex
go.mod:
module mymodulename
go 1.13
require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/inconshreveable/log15 v0.0.0-20200109203555-b30bc20e4fd1
github.com/mattn/go-colorable v0.1.6 // indirect
)
main.go:
package main
import (
"fmt"
"net/http"
"os"
"github.com/inconshreveable/log15"
)
func main() {
log := log15.New()
http.HandleFunc("/", helloHandler)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Info("Using default port", "port", port)
}
log.Info("Listening", "port", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Crit("ListenAndServe", "error", err)
os.Exit(1)
}
}
func helloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, there")
}
Thank you.

IIUC Flexible doesn't support modules (Standard does, go figure!).
You can:
either use a custom runtime;
or, delete the go.mod|go.sum and try again.
I copied your app.yaml and main.go and it worked for me.
One change to your app.yaml:
runtime: go
env: flex
Then:
go get github.com/inconshreveable/log15
go run main.go
INFO[05-15|09:33:26] Using default port port=8080
INFO[05-15|09:33:26] Listening port=8080
and:
curl --silent http://localhost:8080
Hello, there
and:
gcloud app deploy --project=${PROJECT}
curl --silent $(\
gcloud app describe \
--project=${PROJECT} \
--format="value(defaultHostname)")
Hello, there

Related

How do you install subcommands?

I am getting the following error message in Go v. 1.15.8 darwin/amd64
main.go:8:2: cannot find package "github.com/google/subcommands" in any of:
/usr/local/go/src/github.com/google/subcommands (from $GOROOT)
/Users/user1/go/src/github.com/google/subcommands (from $GOPATH)
The code in main.go looks like:
package main
import (
"flag"
"context"
"os"
"github.com/google/subcommands"
)
I know subcommands is located here: https://github.com/google/subcommands
with the git repo here: https://github.com/google/subcommands.git
But how do I install it?
When I do:
go get github.com/google/subcommands
I get the following error message:
# cd .; git clone -- https://github.com/google/subcommands /Users/user1/go/src/github.com/google/subcommands
Cloning into '/Users/user1/go/src/github.com/google/subcommands'...
fatal: unable to access 'https://github.com/google/subcommands/': Could not resolve host: github.com
package github.com/google/subcommands: exit status 128
When I open my web browser and go to: https://github.com/google/subcommands/ I can see the web page with no problems. So why is the "go get" command having trouble with this?
What am I doing wrong?
In addition of git config, you can also check your environment variable for HTTP_PROXY/HTTPS_PROXY
But more importantly, check if adding GOPROXY=https://proxy.golang.org could help (there are other Go module proxies as well)
This could help getting modules from any provider, GitHub or others.

Install go scenery - cannot use &SceneryDefinition

I've got go installed. However, when I do this:
go get -u github.com/dmlittle/scenery
I get:
# github.com/dmlittle/scenery/pkg/parser
go/src/github.com/dmlittle/scenery/pkg/parser/parser.go:98:20: cannot use &SceneryDefinition literal (type *SceneryDefinition) as type lexer.Definition in argument to participle.Lexer:
*SceneryDefinition does not implement lexer.Definition (wrong type for Lex method)
have Lex(io.Reader) (lexer.Lexer, error)
want Lex(string, io.Reader) (lexer.Lexer, error)
go/src/github.com/dmlittle/scenery/pkg/parser/parser.go:116:21: not enough arguments in call to p.ParseString
have (string, *Plan)
want (string, string, interface {}, ...participle.ParseOption)
go/src/github.com/dmlittle/scenery/pkg/parser/scanner.go:39:10: undefined: lexer.Errorf
go/src/github.com/dmlittle/scenery/pkg/parser/scanner.go:82:26: undefined: lexer.Errorf
Any suggestions?
Same issue, seems the prj use dep. I've fixed cloning the repo, then configuring the go module that find the right project dependencies. Then run go get again and the build success:
~/go/src/github.com/dmlittle/scenery (master ✔) ᐅ go run main.go
# github.com/dmlittle/scenery/pkg/parser
pkg/parser/parser.go:98:20: cannot use &SceneryDefinition literal (type *SceneryDefinition) as type lexer.Definition in argument to participle.Lexer:
*SceneryDefinition does not implement lexer.Definition (wrong type for Lex method)
have Lex(io.Reader) (lexer.Lexer, error)
want Lex(string, io.Reader) (lexer.Lexer, error)
pkg/parser/parser.go:116:21: not enough arguments in call to p.ParseString
have (string, *Plan)
want (string, string, interface {}, ...participle.ParseOption)
pkg/parser/scanner.go:39:10: undefined: lexer.Errorf
pkg/parser/scanner.go:82:26: undefined: lexer.Errorf
Init go mod:
~/go/src/github.com/dmlittle/scenery (master ✔) ᐅ go mod init
go: creating new go.mod: module github.com/dmlittle/scenery
go: copying requirements from Gopkg.lock
Check dependencies:
go mod tidy
go: downloading github.com/spf13/cobra v0.0.3
go: downloading github.com/fatih/color v1.7.0
....
Install package:
go get -u github.com/dmlittle/scenery
Works as expected :
~/go/src/github.com/dmlittle/scenery (master ✘)✭ ᐅ ./scenery
Usage:
scenery [flags]
Examples:
terraform plan | scenery
Flags:
-h, --help help for scenery
-n, --no-color Print output without color
--version version for scenery

Unable to build the app in golang with oracle db

I am a beginner in go lang development and I try to connect the cloud oracle DB from go server(using 'github.com/godror/godror' package).
I install the Oracle instant client and set the environment path also.
Go server is running and able to establish the connection and queries. But when I am building a production app got these errors.
Command: env GOOS=linux GOARCH=amd64 go build -o odb db_main.go
../github.com/godror/godror/orahlp.go:452:53: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:461:53: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:479:19: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:480:19: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:481:30: undefined: ObjectType
../github.com/godror/godror/orahlp.go:482:31: undefined: Event
../github.com/godror/godror/orahlp.go:482:42: undefined: SubscriptionOption
../github.com/godror/godror/orahlp.go:482:64: undefined: Subscription
../github.com/godror/godror/orahlp.go:483:10: undefined: StartupMode
../github.com/godror/godror/orahlp.go:484:11: undefined: ShutdownMode
../github.com/godror/godror/orahlp.go:484:11: too many errors```
My server code(db_main.go)
```package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
"net/http"
"time"
_ "github.com/godror/godror"
)
// VersionInfo,ObjectType,Event,SubscriptionOption,Subscription,StartupMode,ShutdownMode
var db *sql.DB
func main() {
var err error
db, err = sql.Open("godror", "xyz/abc#13.43.11.8:1521/sampledb")
if err != nil {
log.Println("Error")
fmt.Println(err)
return
}
defer db.Close()
port := ":8000"
http.HandleFunc("/insert", InsertData)
http.HandleFunc("/list", GetList)
log.Println("Tranzo-Shahi Oracle DB running in ", port)
httpErr := http.ListenAndServe(port, nil)
if httpErr != nil {
log.Println("Tranzo-Shahi Oracle DB Error: ", httpErr.Error())
}
}
Run env GOOS=linux GOARCH=amd64 go build -o odb and don't specify any file. If you do specify one, like db_main.go then you need to specify all the files it the package that must be included in the build.
Unfortunately original question has no mentioning of where the build run. It's important to know.
godror documentation points to possible problems when you try cross-compile your code. It's in their documentation: Cgo is required, so cross-compilation is hard, and you cannot set CGO_ENABLED=0!
I would suggest to run your build on Linux machine. (Verify it has gcc installed.)
Run your build as env CGO_ENABLED=1 go build -o odb

Error when instantiate chaincode

Please help me this issue, error happened when I instantiate my chaincode:
Currently, I guess the issue related to shim package, because I remove it in my utils package, instantiate successfully.
MyChainCode:
import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/protos/msp"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/myproj/models"
"github.com/myproj/packages/utils"
)
APIstub shim.ChaincodeStubInterface
...
username, _ = utils.GetCurrentUser(APIstub)
...
My packages
package utils
import (
"github.com/hyperledger/fabric/core/chaincode/shim"
"golang.org/x/crypto/bcrypt"
)
func GetCurrentUser(stub shim.ChaincodeStubInterface) (string, error) {
cert, err := GetCreatorCert(stub)
return cert.Subject.CommonName, err
}
Issue:
Error: Error endorsing chaincode: rpc error: code = Unknown desc =
error starting container: Failed to generate platform-specific docker
build: Error returned from build: 2 "#
~vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive
~vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:364:5:
hdr.Format undefined (type *tar.Header has no field or method Format)
~vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:364:15:
undefined: tar.FormatPAX
~/vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:1166:7:
hdr.Format undefined (type *tar.Header has no field or method Format)
~/vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:1166:17:
undefined: tar.FormatPAX
Fabric ver 1.1.0
Go ver 1.9.2
I faced the same problem after upgrading fabric to 1.2.0. Fabric 1.2.0 requires go 1.10.x. So I upgraded go lang to 1.10.3 and it worked like a charm.
That can be because you have old version in some files inside your hyperledger/fabric folder.
If you are following the chaincode tutorial, you can just remove your hyperledger/fabric folder.
Regards
I had the same issue by following the documentation.
Switching to branch 'release-1.1' solves the issue.
After cloning the repository proceed with:
hyperleger$ cd fabric
hyperledger/fabric$ git fetch
hyperledger/fabric$ git checkout release-1.1

Go worker app not starting in Cloud Foundry

I am trying to run a go worker app (no binding to a route) in Cloud Foundry. I can start the Go binary locally and it works fine.
When the app tries to start in Cloud Foundry I get the following error.
2015-10-08T12:23:50.49-0400 [STG/127] OUT -----> Downloaded app package (1.1M)
2015-10-08T12:23:53.48-0400 [STG/127] OUT -----> Downloaded app buildpack cache (75M)
2015-10-08T12:23:55.45-0400 [STG/0] ERR Cloning into '/tmp/buildpacks/go-buildpack'...
2015-10-08T12:23:57.48-0400 [STG/0] OUT Submodule 'compile-extensions' (https://github.com/cloudfoundry/compile-extensions.git) registered for path 'compile-extensions'
2015-10-08T12:23:57.53-0400 [STG/0] ERR Cloning into 'compile-extensions'...
2015-10-08T12:23:58.51-0400 [STG/0] OUT Submodule path 'compile-extensions': checked out 'b5e0cf7be729718d162d56709ec7f27d34e68c7c'
2015-10-08T12:23:58.58-0400 [STG/0] OUT -------> Buildpack version 1.6.2
2015-10-08T12:23:58.65-0400 [STG/0] OUT -----> Checking Godeps/Godeps.json file.
2015-10-08T12:23:58.69-0400 [STG/0] OUT -----> Using go1.5.1
2015-10-08T12:23:58.73-0400 [STG/0] OUT -----> Running: godep go install -tags cloudfoundry ./...
2015-10-08T12:24:01.01-0400 [STG/127] OUT -----> Uploading droplet (1.8M)
2015-10-08T12:24:23.98-0400 [DEA/127] OUT Starting app instance (index 0) with guid 8b427c83-67b7-463e-99cd-53a4ad4154ac
2015-10-08T12:24:37.04-0400 [API/1] OUT App instance exited with guid 8b427c83-67b7-463e-99cd-53a4ad4154ac payload: {"cc_partition"=>"default", "droplet"=>"8b427c83-67b7-463e-99cd-53a4ad4154ac", "version"=>"9f5da0a0-1b4c-4907-a92a-40b4ce6d5669", "instance"=>"73b999f6770949098d59bef51e81d31d", "index"=>0, "reason"=>"CRASHED", "exit_status"=>126, "exit_description"=>"failed to start", "crash_timestamp"=>1444321477}
2015-10-08T12:24:37.04-0400 [API/8] OUT App instance exited with guid 8b427c83-67b7-463e-99cd-53a4ad4154ac payload: {"cc_partition"=>"default", "droplet"=>"8b427c83-67b7-463e-99cd-53a4ad4154ac", "version"=>"9f5da0a0-1b4c-4907-a92a-40b4ce6d5669", "instance"=>"73b999f6770949098d59bef51e81d31d", "index"=>0, "reason"=>"CRASHED", "exit_status"=>126, "exit_description"=>"app instance exited", "crash_timestamp"=>1444321477}
Below is my Procfile.
worker: ./slack-disable-2fa
Below is my manifest.yml file.
applications:
- path: .
memory: 512MB
instances: 1
domain: mybluemix.net
name: myapp
host: myapp
no-route: true
disk_quota: 1024M
command: ./slack-disable-2fa
buildpack: https://github.com/cloudfoundry/go-buildpack.git
Snippet from the go app (slack-disable-2fa.go)
package main
import (
"fmt"
"time"
)
func main() {
for {
fmt.Printf("hello\n")
fmt.Printf("Running again in 24 hours...\n")
time.Sleep(time.Hour * 1)
}
}
Remove the './' prefix from the Procfile.
It should only contain the command name.
worker: slack-disable-2fa
Also Remove the './' prefix from the manifest.yml.
command: slack-disable-2fa

Resources