I'm writing FastAPI services and deploying to Google Cloud Run.
I would like to run certain code on my laptop, certain code on cloud run, etc. I would like to customize the code based on the environment it is run in.
How can I know if I am in a container, google cloud run, my Mac laptop, vscode spaces, GitHub actions...How can I add that information to debug variable?
debug,cloud,laptop,vcode = Environment()
if debug:
app.mount("/public", StaticFiles(directory="/public"), name="static")
else:
app.mount("/public", StaticFiles(directory="/debitcard/debitcard/public/static"), name="static")
}
How can I know in python if the code is actually running on my laptop or the cloud run environment?
The answer is to simply set environment variables in all the environments the code will run.
On my laptop, I'll do this:
export DEBUG=True
export LAPTOP=True
export CLOUDRUN=False
export GITHUBACTIONS=False
and on Google Cloud Run, I'll set the environment vars aswell. aswell as on GitHub Actions....