0

I have created a web-app in Go and I would like to make it possible to run it on a server or on app-engine in the smoothest way I can.

Basically I created a single .exe (I am developing on Windows) and a set of folders wih static files. In addition there is a folder with N configuration files.

These config files include all the configurations needed to setup the db, the folders/paths to write logs into, and so on.

At "time 0" when I double click the .exe on my local machine the installation process starts. It looks at the config files (and if they do not exist they are even created) and updates them as per the answers I give on the console. In addition the app generates log files on the filesystem.

My question: can I "upload" my go code on app engine "as-is" and just include some configurations specific to appengine on the yaml file, or am I forced to amend MY Go code so that: 1) the main() must look for the config files elsewhere on app-engine and 2) the logs are read/written from/to specific paths on app-engine

In other words, I wonder whether I can achieve a sort of "write once and run/deploy everywhere" version of my web app.

It's my first question on the community so I hope I folowed all instructions. Thanks.

Romano
  • 29
  • 5
  • 1
    For the fewest restrictions use Go1.11: [Go 1.11 is now available on App Engine](https://cloud.google.com/blog/products/application-development/go-1-11-is-now-available-on-app-engine). – peterSO Oct 17 '18 at 15:23
  • 2
    @peterSO oh man, been waiting for this for three years now! Thanks for the link – RayfenWindspear Oct 17 '18 at 17:07
  • With the new Go 1.11 support on App Engine (linked by PeterSO above), it is now possible to write applications that run inside and outside the App Engine standard environment. There are restrictions on what the application can do in App Engine environment. One of the restrictions is that an application cannot write files. There may be others that apply to your application. – Charlie Tumahai Oct 17 '18 at 17:18
  • @ThunderCat Depending on the platform as defined by config/environment variables in App Engine for 1.11, you could switch to using Cloud Storage based on if it's deployed to App Engine. Of course, OP wants to do as little code modifications as possible, but it won't work as-is because, like you said, you can't write files normally when deployed on App Engine. – RayfenWindspear Oct 17 '18 at 17:33
  • @RayfenWindspear So, I looked at the 1.11 docs and I see that there is a "2nd gen" environment for golang with much less restrictions than before, but unfortunately the one about writing files is still there as you all said... So, you are suggesting me to modify a bit my code where (for example) I need to look at the presence of the config file at setup stage or in case of modifications and make sure that my app uses the appropriate func to store and retrieve the config either from the filesystem or from the Storage. I'll give it a try... I hope I do not have to rethink the way my app works... – Romano Oct 18 '18 at 08:18
  • It could possibly be as easy as that, depending on how it's coded, of course. The rest of the app should theoretically function as-is, unless you make use of the C std lib. App Engine specifically disallows this. As an alternative, you could function with zero changes whatsoever if you used a compute engine, but that is no different than running any other sort of VM. – RayfenWindspear Oct 18 '18 at 08:39

1 Answers1

0

The answer to the question "May I deploy without modifying my code", is no, this is not possible because of the way you have designed your application.

Appengine creates on demand server instances to respond to requests, and then shuts down that instance when there are no web requests occurring. Appengine applications must be designed in a way that they are not dependent upon living on a single server with a configuration file.

You can choose to design an app that is dependent on a single configuration file living on a single server, but then its not a good fit for google appengine.

Jay
  • 19,649
  • 38
  • 121
  • 184