Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass run arguments in app.yaml for Go?

According to Docs:

entrypoint
Optional. Overrides the default startup behavior by executing the entrypoint command when your app starts. For your app to receive HTTP requests, the entrypoint element should contain a command which starts a web server that listens on port 8080.

How would I configure this? there are no details found anywhere. Can I do this?

entrypoint: go run main.go fooArg --bar-flag=1

I don't have cloud build file, only app.yaml. so what does entrypoint really do? when app engine reaches entrypoint part is the program already compiled?

Thank you

like image 438
Arximede Avatar asked Jun 04 '21 20:06

Arximede


People also ask

What is the purpose of the app YAML file?

The app.yaml file defines your configuration settings for your Go runtime as well as general app, network, and other resource settings. For more information and an example, see Defining Runtime Settings .

Do not add app YAML to gcloudignore?

Do not add app.yaml to the .gcloudignore file. app.yaml might be required for deployment, and adding it to .gcloudignore will cause the deployment to fail. The syntax of the app.yaml file is the YAML format .

How do I pass arguments in go?

Passing arguments in your application can be especially useful when you’re creating tools which can do different things, or the same thing in a different way. In go, you can do with by declaring your arguments as flags. In our example we’re using an argument to determine whether we should run task A or task B.

How do I pass arguments to a DotNet application?

To pass arguments to your application, you need to pass a -- argument, and then the arguments to your application. As per the .NET Core CLI documentation, -- delimits arguments to dotnet run from arguments for the application being run.


1 Answers

I tried this just now with my own GCP AppEngine project and using entrypoint (eg. entrypoint: go run ./cmd/web prod) did not work for me. When I tried it, I am getting this cryptic error message:

Error type: UNKNOWN
Error message: no Go files in /layers/google.go.appengine_gomod/srv

I'm using Google Cloud SDK 344.0.0.

I'm in a similar situation like you though where I'm simply trying to pass in args into my golang main. Following the docs, I changed over to using env_variables instead which worked.

My app.yaml looks like:

runtime: go115
main: ./cmd/web
env_variables:
  APP_ENV: "prod"

and then in my code, I simply use os.Getenv("APP_ENV") anywhere to access.

like image 170
r002 Avatar answered Oct 04 '22 18:10

r002