Below are the definitions of Local and Remote Setups
1. Local Setup :- Laptop + connecting to Cloud SQL instance (public IP). No need of cloud sql auth proxy since it is public IP
2. Remote Setup:- Cloud Run service + connecting to Cloud SQL instance (Private IP is used in this case which is the recommended setup). Also uses Cloud SQL Auth Proxy
My question is related to the one single codebase principle of 12-factor apps.
As it is evident from above setups I need to have separate codebase (mainly DB connection string) to connect to cloud sql public Ip AND cloud sql private IP. How do i handle this to ensure i can use a single codebase which works for my local and deployment to Google Cloud? Do i need to setup any ENV vars in Cloud Run and check if i am running in local or remote and accordingly set the DB connection string?
Hi @dheerajpanyam,
Welcome to Google Cloud Community!
I would suggest using Cloud Source Repositories so that you can manage and collaborate your code in a fully featured, scalable, private Git repository. It comes with code-search functionality across all repositories. You can also connect to other Google Cloud products such as Cloud Build, App Engine, Cloud Logging, and Pub/Sub.
You could check the following links for more information on twelve-factor app development for Google Cloud:
Hope this helps.
Thanks @robertcarlos for your reply. We are already using GH. The question was more on how do you use the same codebase to work on both local and Cloud Run. I am looking for that specific code snippet. Another issue i see they differ is in authentication. When you develop on local / outside GCP you would use a service account key file to access GCP services but within GCP it is not needed. Maybe local dev specific configuration should be setup as local environment variables?