Deploying a simple http server to both goapp serve & docker?

50 views
Skip to first unread message

Philip Mather

unread,
Mar 7, 2019, 2:55:42 PM3/7/19
to Google App Engine
Hello all,
I have a question that might turn out to be a misunderstanding about how a typical development process works but it's probably a chance to learn anyway so...

I started plugging away at various Google Code labs to bring myself up to speed with golang, in particular https://codelabs.developers.google.com/codelabs/nyc-subway-station-locator/index.html which uses a basic import net/http, init() to register a handler(), write hello world type pattern found at https://codelabs.developers.google.com/codelabs/nyc-subway-station-locator/index.html#2 along with a suitable app.yaml to facilitate the end of goal of running you app with "goapp serve". They extend it from there and eventually "gcloud app deploy" it.

Very nice. I changed it to do the London underground and played around with the JS a bit, blah blah.

I then decided to containerize this and deploy it to GKE via docker so that I could fix a static IP to it and call remote APIs that need to white-list you (hence the static IP). I wrote a docker file, https://github.com/philipmather/scry.philipmather.dev/blob/master/Dockerfile.scry and got that going via "docker build -f Dockerfile.scry -t scry ." and then say "docker run --rm -p 8080:8080 scry" etc, etc...

In moving from GAE to GKE obviously I lose whatever "scaffolding" ("google.golang.org/appengine" ?) it is that GAE provides and replaced init() with a main() that constructs a ditty little web server. This all works great and the build time isn't a total killer but I miss being able to tweak the files with "goapp serve" running and see the result "live" as it were, especially as a large chunk of the app is Javascript working against the Maps API.

So... Is it possible to construct something that can do both? Instead of porting the contents of init() to a main() should I have simply kept something like https://godoc.org/google.golang.org/appengine#Main, imported "google.golang.org/appengine" and continued my app in it's own package (instead of main?)?

I'm aware I can use cloud builder and triggers to add more automagic to my process but nothing seems to have the immediacy of "goapp serve"? I feel like I've missed something somewhere? Searched high and low and can't find anyone doing what I'm aiming for? Any pointers appreciated!

Regards,
   Phil

Harmit Rishi (Cloud Platform Support)

unread,
Apr 8, 2019, 11:12:59 PM4/8/19
to google-a...@googlegroups.com

Firstly, App Engine standard environment does not provide the API libraries present in the App Engine SDK. Therefore, you may have to first migrate to App Engine flexible and then follow the instructions to move to Kubernetes. You can follow the migration steps for this here[1]. 

With that being said, running an App Engine application on Kubernetes without changing the app code is doable. You can follow the steps to achieve this here[2]. 

The entry point for the application is the main function in the main package [3][4]. Though you may have to initialize some parameters for your code by using the init() function found here[5].

As for the “goapp serve” inquiry, this is included with the original App Engine SDK for Go which can be found here[6]. You may choose to create a dockerfile using the “google/cloud-SDK” bundle here[7]. 

Additionally, if you require any further technical answers, you may ask your question on the following StackOverflow posting here[8].

I hope this helps!


[1] https://cloud.google.com/appengine/docs/flexible/java/migrating  

[2] https://cloud.google.com/appengine/docs/flexible/python/run-flex-app-on-kubernetes    

[3] https://golang.org/doc/code.html   

[4] https://godoc.org/google.golang.org/appengine#Main   

[5] https://golang.org/doc/effective_go.html#init

[6] https://cloud.google.com/appengine/docs/standard/go/tools/using-local-server#running_the_local_development_server   

[7] https://hub.docker.com/r/google/cloud-sdk/   

[8]https://stackoverflow.com/questions/tagged/google-app-engine  

Reply all
Reply to author
Forward
0 new messages