Search code examples
phpgoogle-cloud-platformgoogle-cloud-storageapp-engine-flexiblegoogle-cloud-stackdriver

Google Cloud Platform : How to develop on my local environment with GCP resources


I'm using Google App Engine Flex to develop an angularjs/php-rest backend application. I've a successful port from regular servers to AppEngine, and I now want to integrate more with GCP services like : StackDriver, Cloud Storage and so on.

StackDriver to have logging & monitoring. Cloud Storage: to store export data files and zip them before sending it to browser.

My question is how do I develop locally on my laptop (which can be online & offline) ?

I didn't find in the documentation "the way" of local development :

  • Should stackDriver or Cloud Storage client be configured to write on disk instead of reaching GCP ?
  • Should I configure some proxy (like the cloud_sql_proxy) to be able to reach GCP ? Should I create a project for my local dev ? How does it work if I'm offline ?

Any hint appreciated :)


Solution

  • App Engine Flexible doesn't come with a development server or service emulators for use during development so you may use the services directly.

    • Stackdriver Logging: logs written to stdout and stderr are automatically sent to Stackdriver Logging for you, without needing to use Stackdriver Logging library for PHP. This may be enough for you to get logs locally but we recommend that you use the PSR-3 logger which automatically adds metadata to your logs so that your application logs are correlated to the request logs. You can set it up to run locally and log to your project by following the doc here.
    • Stackdriver Monitoring: Google App Engine includes built-in support for Monitoring in the flexible environment (when deployed) and doesn't require configuration. The monitoring agent cannot be installed on your local machine though, but it would be pointless to monitor it anyway.
    • Cloud Storage: an easy option is to create a dev bucket that you can use during development. You can create it in whichever project you wish and grant permissions to your development service account.

    One common practice is to create different GCP projects for prod, staging and dev purposes. This allows you to create specific resources for a given environment. Taking logging as example, you'll be able to see logs and troubleshoot any issue with it within the dev project, without polluting your prod project's logs. That'd be true with CloudSQL, Datastore, etc...

    You don't need to configure any proxy for those services. The cloud_sql_proxy is a convenient method to enforce secure connections and ease authentication with CloudSQL instances without the need to whitelist IP addresses.

    Regarding the offline situation now, of course those calls from your local app to those services will fail if you don't have internet connection at that time (intermittent disconnections may actually help you to test your retries and error handling mechanisms). If you expect to develop with no internet connection at all though, you'll need to write stub services to mimic the expected behavior locally.