NoSQL Writer
This guide shows you how to work with Google Cloud Run and Firestore locally using the Firebase Emulator Suite and Python. This lab demonstrates how to create a containerized service that registers patients in Firestore.
Prerequisites
Section titled “Prerequisites”- Docker installed and running.
- Dev Containers extension installed (optional).
- Without Dev Container, you also need:
- Python 3.12+.
- Node.js.
- Java JDK.
- Google Cloud CLI.
- Minikube.
- Firebase CLI (
npm install -g firebase-tools).
How to execute
Section titled “How to execute”-
Setup Environment:
Open VS Code in the project folder and execute this command in the Command Palette:
Terminal window > Dev Containers: Reopen in ContainerInstall dependencies:
Terminal window uv sync -
Start Firebase Emulators:
Terminal window firebase emulators:start -
Run the Service:
Open a new terminal and build and run the service container:
Terminal window docker build -t patient-service ./appdocker run --rm -p 8080:8080 --net=host -e FIRESTORE_EMULATOR_HOST=localhost:8081 patient-service- Open the Cloud Code panel in the VS Code activity bar.
- Expand Cloud Run.
- Click Run on Cloud Run Emulator (play icon).
First run downloads and sets up Minikube — this takes 10–15 minutes.
-
Run the Example:
Terminal window python main.pyTerminal window curl -v -X POST http://localhost:8080 \-H "Content-Type: application/json" \-d '{"name": "Test", "surname": "User", "dni": "12345678X"}'
Validate results
Section titled “Validate results”Open the Firebase Emulator UI and navigate to Firestore to verify the registered patient documents:
http://localhost:4000Clean Up
Section titled “Clean Up”docker stop patient-servicepkill -f firebaseClick the Stop (red square) button in VS Code, or run:
minikube stoppkill -f firebaseTroubleshooting
Section titled “Troubleshooting”| Issue | Solution |
|---|---|
| Connection Refused (Firestore) | Ensure firebase emulators:start is running. On Linux with Minikube, change FIRESTORE_EMULATOR_HOST to host.minikube.internal:8081 in .vscode/launch.json. |
| Persistent Google Cloud login prompts | Ensure .vscode/settings.json includes "cloudcode.useGcloudAuthSkaffold": false and select No/Cancel when prompted. |
| Firebase Emulator fails to start | Ensure Node.js and Java JDK are installed. Check ports 8081 and 4000 are available. |