`gcloud app deploy` command picking the wrong GOPATH - google-app-engine

Trying to deploy my GO application with Cloud SQL using gcloud app deploy but build is failing every time with package not found error. Not sure where it is picking the GOPATH from. Is it possible to change the GOPATH in google cloud engine.
Step #0: main.go:9:2: cannot find package "github.com/gin-gonic/gin"
in any of: Step #0: /usr/local/go/src/github.com/gin-gonic/gin (from
$GOROOT) Step #0: /workspace/_gopath/src/github.com/gin-gonic/gin
(from $GOPATH) Step #0: main.go:10:2: cannot find package
"github.com/go-sql-driver/mysql" in any of: Step #0:
/usr/local/go/src/github.com/go-sql-driver/mysql (from $GOROOT) Step
#0: /workspace/_gopath/src/github.com/go-sql-driver/mysql (from $GOPATH) Step #0: main.go:8:2: cannot find package
"google.golang.org/appengine" in any of: Step #0:
/usr/local/go/src/google.golang.org/appengine (from $GOROOT) Step #0:
/workspace/_gopath/src/google.golang.org/appengine (from $GOPATH)
I have import statements to include the above libraries. My local GOPATH is set to /Users/amar.jain/go/ and it is trying to use /workplace/_gopath/
I'm also using the GO App Engine SDK.

As mentioned in here, the following line should be deleted from the app.yaml file when using Flexible environment:
api_version: go1
Compare an example of an app.yaml file when in Flexible and Standard.
These are the options available when configuring the Flexible environment.

Are you using the app engine standard environment?
The app engine standard environment is picky about GOPATH, it does try to upload all files required but it often helps to vendor the dependancies and make sure the app.yaml is at the top level.
https://cloud.google.com/appengine/docs/standard/go/building-app/creating-your-application#structuring_your_application_project
Ive had problems with the standard environment when using the standard go /cmd /pkg structure for example.

Related

Step #0: exec: "gcc": executable file not found in $PATH

I keep running into this error when trying to deploy a very simple website to App Engine (this code without the Dockerfile, as specified in this tutorial).
I am running on macOS Monterey 12.2.1, go 1.18, fresh install of the Google Cloud SDK. I'm not using any external packages either.
Every time that I try to deploy, I get the Step #0: exec: "gcc": executable file not found in $PATH error. Here's a larger snippet:
Step #0: go: finding golang.org/x/tools v0.0.0-20200904185747-39188db58858
Step #0: go: finding google.golang.org/grpc v1.31.1
Step #0: go: finding golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f
Step #0: # net
Step #0: exec: "gcc": executable file not found in $PATH
Finished Step #0
ERROR
ERROR: build step 0 "gcr.io/gcp-runtimes/go1-builder#sha256:408a098788ef4cdeec452821946b986ef82ce5ebceecbdf748ffecf329765bce" failed: step exited with non-zero status: 2
Any clues what is going wrong? I read some similar posts that it could be an error with the PATH, but I could not get anything to work for myself. Here is my path:
/usr/bin:/usr/local/go/bin:/Users/temporaryadmin/go/bin:/Users/temporaryadmin/google-cloud-sdk/bin:/Users/temporaryadmin/.pyenv/shims:/Users/temporaryadmin/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/usr/bin/python3:/usr/local/go/bin
Really struggling to understand what I can do to fix this so I can start uploading to App Engine. Thanks a lot!

exec: "gcc": executable file not found in $PATH

I'm having an issue where an App Engine project will no longer build remotely (via gcloud app deploy)
This has started out of the blue, with no code changes at this end. Not sure if relevant, but it's a go 1.9 project deploying to the App Engine Flex environment.
I'm not sure how to test this in the same environment as the build, since the error is coming from Google's Container Registry
Here is the log from the Container Registry console
starting build "73f85b4d-7370-41bd-bbb2-bcf42fc38873"
FETCHSOURCE
Fetching storage object: gs://staging.[project].appspot.com/us.gcr.io/[project]/appengine/default.1ed3c690ead06f27aa651a30fab342611:latest#1531698266413753
Copying gs://staging.[project].appspot.com/us.gcr.io/[project]/appengine/default.1ed3c690ead49f731806f27aa630fab342611:latest#1531698266413753...
Operation completed over 1 objects/1.7 MiB.
BUILD
Starting Step #0
Step #0: Pulling image: gcr.io/gcp-runtimes/go1-builder#sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db
Step #0: sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db: Pulling from gcp-runtimes/go1-builder
Step #0: Digest: sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db
Step #0: Status: Downloaded newer image for gcr.io/gcp-runtimes/go1-builder#sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db
Step #0: exec: "gcc": executable file not found in $PATH Finished
Step #0 ERROR ERROR: build step 0 "gcr.io/gcp-runtimes/go1-builder#sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db" failed: exit status 2
It looks like you are using container gcr.io/gcp-runtimes/go1-builder as your build step. Looking at the source in GitHub, I see that there have been no updates since ~late June. I see in the Dockerfile that the base image in the FROM directive is gcr.io/google-appengine/debian9:latest, and a look at that image reveals no gcc installed. I see no step in the Dockerfile installing gcc, and looking at your build step image confirms that it isn't there:
~$ docker run --rm -t -i --entrypoint /bin/bash gcr.io/gcp-runtimes/go1-builder#sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db -- which gcc
Unable to find image 'gcr.io/gcp-runtimes/go1-builder#sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db' locally
sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db: Pulling from gcp-runtimes/go1-builder
e154cec6816f: Pull complete
<pulls elided>
Digest: sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db
Status: Downloaded newer image for gcr.io/gcp-runtimes/go1-builder#sha256:c62ac3fbec31ddec70601d6c5b44d07063bcff6a823bdcf5e0bbaa9d3799d1db
~$
Perhaps an earlier version of the base debian9 image had it installed, you could dig into history to look. But it looks like there is no recent change to the go1-builder image to remove gcc.
If you need gcc, you can always separate building your app from deploying it. Build with your own cloudbuild.yaml via gcloud container builds submit and then deploy the built container using gcloud app deploy --image-url=... With full control over the build, you can always based on the go-builder image and install additional tooling you need like gcc on top of that before using Docker to build your final app container.

Cannot find package when deploy to App Engine

I can not deploy my golang application (with echo framework) on App Engine.
I have some kind of error like:
...
Step #0: main.go:4:2: cannot find package "FBackend/router" in any of:
Step #0: /usr/local/go/src/FBackend/router (from $GOROOT)
Step #0: /workspace/_gopath/src/FBackend/router (from $GOPATH)
Finished
Step #0 ERROR
ERROR: build step 0 "..." failed: exit status 1
In project I have file three like this:
FBackend
...
|___router
| |____router.go
...
|
|___main.go
On localhost all works fine
Judging from the error message, you should set one of the paths to the "src" folder.
They should be able to find "FBackend/router" in "/usr/local/go/src/" since it's there.
I can understand how it can't find "FBackend/router" in "/usr/local/go/src/FBackend/router" cause you probably don't have "/usr/local/go/src/FBackend/router/FBackend/router" setup.

spring boot application to test with travis and deploy on Google Cloud

Recently I ran my Spring Boot code into the Google Cloud platform. Now I want to introduce TRAVIS CI to my source code but I cant deploy it on Google Cloud because I receive the following error:
Step #0: Pulling image: gcr.io/gcp-runtimes/java/runtime-builder#sha256:abe30c228acd8514d83430452b5a45eedea568b55d02d4ddaa2a374b1b086dd8
Step #0: sha256:abe30c228acd8514d83430452b5a45eedea568b55d02d4ddaa2a374b1b086dd8: Pulling from gcp-runtimes/java/runtime-builder
Step #0: Digest: sha256:abe30c228acd8514d83430452b5a45eedea568b55d02d4ddaa2a374b1b086dd8
Step #0: Status: Downloaded newer image for gcr.io/gcp-runtimes/java/runtime-builder#sha256:abe30c228acd8514d83430452b5a45eedea568b55d02d4ddaa2a374b1b086dd8
Step #0: Exception in thread "main" com.google.cloud.runtimes.builder.exception.ArtifactNotFoundException: No deployable artifacts were found. Unable to proceed.
Step #0: at com.google.cloud.runtimes.builder.buildsteps.PrebuiltRuntimeImageBuildStep.getArtifact(PrebuiltRuntimeImageBuildStep.java:77)
Step #0: at com.google.cloud.runtimes.builder.buildsteps.RuntimeImageBuildStep.run(RuntimeImageBuildStep.java:50)
Step #0: at com.google.cloud.runtimes.builder.BuildPipelineConfigurator.generateDockerResources(BuildPipelineConfigurator.java:104)
Step #0: at com.google.cloud.runtimes.builder.Application.main(Application.java:147)
I have configured files like:
web.xml for using jetty
appengine-web.xml for using the Google cloud
.travis.yml for using Travis
app.yaml for using Google cloud
Am I missing some files?

bad import "syscall" for cloud storage APIs

I am following the instructions on https://cloud.google.com/appengine/docs/go/googlecloudstorageclient/download to begin migrating some code from the, now deprecated, Files API to the new Cloud Storage API without success.
The steps I'm following are ...
I'm running appengine v1.9.23 which is later than the required appengine v1.8.1.
My $GOPATH is set, so I skip step #1.
I proceed to step #2:
goapp get -u golang.org/x/oauth2
goapp get -u google.golang.org/cloud/storage
I am not developing on a managed VM, so I skip step #3.
Now when I run the application, I get:
go-app-builder: Failed parsing input: parser: bad import "syscall" in goapp/src/golang.org/x/net/internal/nettest/error_posix.go
What am I doing wrong?
Steps to reproduce
Download an install the Google Appengine runtime, version 1.9.23 from https://console.cloud.google.com/storage/browser/appengine-sdks/featured/ . Follow the installation instructions documented on https://cloud.google.com/appengine/downloads?hl=en
Create an appengine project directory:
% mkdir $HOME/myapp
Create a new app.yaml file as ~/myapp/app.yaml. Read the directions on the Google website for details: https://cloud.google.com/appengine/docs/go/config/appconfig
I use a version that does not have the static resources:
application: myapp
version: alpha-001
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
Create a location for the Go source files.
% mkdir $HOME/myapp/go
Set your GOPATH to the location of your sources
% export GOPATH=$HOME/myapp/go
Get the Go appengine example project: https://github.com/golang/example
% goapp get github.com/golang/example/appengine-hello
This command will download the example app to the first path entry in the GOPATH
Install the Google Cloud Storage client libraries as directed in https://cloud.google.com/appengine/docs/go/googlecloudstorageclient/download . Reference the steps at the top of this question for more details. Following the directions should result in you running 2 commands:
% go get -u golang.org/x/oauth2
% go get -u google.golang.org/cloud/storage
Attempt to run your go application
% goapp serve
You will see the following compilation error (no stack trace):
2015/12/23 10:37:07 go-app-builder: Failed parsing input: parser: bad import "syscall" in go/src/golang.org/x/net/ipv6/control_unix.go
This error is caused by either of two scenarios:
1) Implicitly importing syscall by importing another package that uses it, as referenced in this related question.
2) Having your package source files in your GOPATH located in a directory at or below the same level as your project's app.yaml (eg. app.yaml in ~/go, and packages sources in ~/go/gopath/src). If a package like x/net/internal/nettest exists in your GOPATH the syscall import will be parsed by goapp at compile time and throw the compilation error.
Avoiding these two scenarios should be sufficient to prevent any bad import "syscall" errors or related compilation errors.
Reproduced the initial steps above and got a similar error, even if not explicitly mentioning syscall. However, running “goapp serve” in the appengine-hello directory results in no error at all.
Adam’s explanation at point 2 applies here correctly: one needs to place the app.yaml file at the right level in the directory structure.
sirupsen/logrus references syscall.
They have an appengine tag specified, not to include syscall so it's usable in AppEngine, something like go build -tags appengine as per issue 310.
However I haven't yet succeeded including it in an AppEngine project so that this build param could be forwarded and specified somewhere so that it goes through. I'll come back to update if I manage.

Resources