1Prerequisites
What you need for Cloud Run deployment:
- Google Cloud account ($300 free credits provided)
- Google Cloud CLI (gcloud) installed
- Docker (optional - for local testing)
2Write the Dockerfile
Create a Dockerfile in your backend folder:
Dockerfile
FROM python:3.11-slim
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application
COPY . .
# Cloud Run uses the PORT environment variable
ENV PORT=8080
EXPOSE 8080
# Start server
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]3Deploy
Terminal
# Log in to Google Cloud
gcloud auth login
# Set project (replace YOUR_PROJECT_ID with your project ID)
gcloud config set project YOUR_PROJECT_ID
# Deploy to Cloud Run
gcloud run deploy my-admin-api \
--source . \
--region asia-northeast3 \
--allow-unauthenticated
Once deployment is complete, a URL in the format https://my-admin-api-xxxxx.run.app will be generated.
4Connect Frontend
Set the backend URL as an environment variable in Cloudflare Pages:
Variable name
VITE_API_URL
Value
https://my-admin-api-xxxxx.run.app
Pricing Info
Cloud Run costs nothing when there are no requests (scale to zero). The free tier covers up to 2 million requests per month. Detailed pricing policy →