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

757 views Asked by At

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

1

There are 1 answers

0
Robert Lin On BEST ANSWER

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.