Deploying FastAPI to Cloud Run without writing a Dockerfile

Deploying a service built with FastAPI (a Python web framework for building APIs) from source to Cloud Run takes only your Python project files: pyproject.toml, uv.lock, and main.py. You don't need a Dockerfile, a Procfile, or an exported requirements.txt file.

I'll walk you through initializing a FastAPI project with uv (a fast Python package and project manager), deploying it from source to Cloud Run, and turning on automatic OS and Python updates. From there, you'll inspect the Cloud Build logs to see how Google Cloud's Python buildpack resolves packages from uv.lock, detects the right startup command, and handles other Python frameworks.

Prerequisites

To follow along, you need curl, uv installed locally (to initialize the project and manage dependencies), an authenticated gcloud, and a Google Cloud project with billing enabled.

Set the environment variables GOOGLE_CLOUD_PROJECT and REGION in your shell. Replace YOUR_PROJECT_ID with your Google Cloud project ID and pick a Cloud Run region near you (I use europe-west1 in Belgium because it's close to where I live):

export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
export REGION="europe-west1"

With those variables set, enable the Cloud Run Admin API, the Cloud Build API, and the Artifact Registry API on your project so Cloud Run can build and store your container image:

gcloud services enable \
  run.googleapis.com \
  cloudbuild.googleapis.com \
  artifactregistry.googleapis.com \
  --project="$GOOGLE_CLOUD_PROJECT"
Operation "operations/acf.p2-123456789012-8fce0a1b-bf4a-421d-a4b8-0722579c1a07" finished successfully.

Initialize a FastAPI project with uv

Start by scaffolding a minimal FastAPI project with uv, adding FastAPI as a dependency, and replacing the starter main.py file. Initialize the directory fastapi-uv-demo and enter it:

uv init --no-package --python 3.14 fastapi-uv-demo && cd fastapi-uv-demo
Initialized project `fastapi-uv-demo` at `/path/to/fastapi-uv-demo`
  • --no-package creates a flat project with main.py at the root instead of a src/ layout with a default [project.scripts] entrypoint.
  • --python 3.14 sets requires-python = ">=3.14" in pyproject.toml and writes a .python-version file containing 3.14 to pin the interpreter version.

The uv init command also writes a root .gitignore file containing .venv, so gcloud run deploy --source skips your local virtual environment when uploading source files.

Add the package fastapi[standard] to the project. Running uv add updates your pyproject.toml file, creates a local .venv directory, and generates a uv.lock file to prevent unintended dependency updates and track version changes in git:

uv add "fastapi[standard]"
Using CPython 3.14.9 interpreter at: /usr/bin/python3.14
Creating virtual environment at: .venv
Resolved 62 packages in 21ms
Installed 59 packages in 90ms
...

Next, replace the starter main.py file with a FastAPI route handler. The root handler returns the running Python interpreter version and reads the K_REVISION environment variable (which Cloud Run populates with the identifier of the active deployment, known as a revision):

main.py
import os
import sys
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {
        "message": "Deployed from pyproject.toml with uv",
        "python": sys.version.split()[0],
        "revision": os.environ.get("K_REVISION", "local"),
    }

Deploy to Cloud Run without a Dockerfile

With pyproject.toml, uv.lock, and main.py in place, you can build and deploy the service fastapi-uv-demo from the current directory without adding a Dockerfile, a Procfile, or a requirements.txt file. When that's successful, you'll query the live endpoint with curl to verify the running Python version.

Run gcloud run deploy to deploy the service (if prompted to create the cloud-run-source-deploy Artifact Registry repository, press Y):

gcloud run deploy fastapi-uv-demo \
  --source=. \
  --no-invoker-iam-check \
  --region="$REGION" \
  --project="$GOOGLE_CLOUD_PROJECT"
Building using Buildpacks and deploying container to Cloud Run service [fastapi-uv-demo] in
project [YOUR_PROJECT_ID] region [europe-west1]
✓ Building and deploying new service... Done.
  ✓ Validating configuration...
  ✓ Creating Container Repository...
  ✓ Uploading sources...
  ✓ Building Container...
  ✓ Creating Revision...
  ✓ Routing traffic...
Done.
Service [fastapi-uv-demo] revision [fastapi-uv-demo-00001-kh2] has been deployed and is serving
100 percent of traffic.
Service URL: https://fastapi-uv-demo-123456789012.europe-west1.run.app
  • --source=. packages your project directory, uploads it to Cloud Storage, and builds a container image on a virtual machine (VM) in Cloud Build using Google Cloud's buildpacks.
  • --no-invoker-iam-check disables Cloud Run's IAM invoker check so you can query the public .run.app URL directly with curl.

Fetch the service URL and send a request with curl to verify the response:

SERVICE_URL=$(gcloud run services describe fastapi-uv-demo \
  --region="$REGION" \
  --project="$GOOGLE_CLOUD_PROJECT" \
  --format="value(status.url)")

curl -s "$SERVICE_URL" | python3 -m json.tool
{
    "message": "Deployed from pyproject.toml with uv",
    "python": "3.14.10",
    "revision": "fastapi-uv-demo-00001-kh2"
}

Without a Dockerfile or startup configuration file, the service is live, using Python 3.14 and FastAPI.

Enable automatic base image updates on Python 3.14

That initial deployment bundled Ubuntu and Python 3.14 directly into your container image in Artifact Registry. Because you used a source-based deployment without a Dockerfile, you can turn on automatic base image updates so Cloud Run replaces the underlying Google-managed base image with patched OS and Python releases without rebuilding or redeploying your code. To see how that works in detail, read How rebasing works on Cloud Run.

Redeploy the service fastapi-uv-demo with base image updates enabled:

gcloud run deploy fastapi-uv-demo \
  --source=. \
  --base-image=python314 \
  --automatic-updates \
  --no-invoker-iam-check \
  --region="$REGION" \
  --project="$GOOGLE_CLOUD_PROJECT"
Building using Buildpacks and deploying container to Cloud Run service [fastapi-uv-demo] in
project [YOUR_PROJECT_ID] region [europe-west1]
✓ Building and deploying... Done.
  ✓ Validating configuration...
  ✓ Uploading sources...
  ✓ Building Container...
  ✓ Creating Revision...
  ✓ Routing traffic...
Done.
Service [fastapi-uv-demo] revision [fastapi-uv-demo-00002-lcf] has been deployed and is serving
100 percent of traffic.
Service URL: https://fastapi-uv-demo-123456789012.europe-west1.run.app
  • --base-image=python314 selects the Python 3.14 base image on the Ubuntu 24.04 (google-24) stack from the supported Python base images.
  • --automatic-updates opts the service into base image updates so Cloud Run replaces the python314 base image underneath your service as Google publishes patches.

Cloud Run attaches the active base image version to every log entry emitted by your container (including the web server's startup messages on stderr). Query the container's stderr log stream for the label run.googleapis.com/base_image_versions (if it returns empty output right after deploying, wait a few seconds for Cloud Logging to index the startup logs and retry):

gcloud logging read 'resource.type="cloud_run_revision" '\
'AND resource.labels.service_name="fastapi-uv-demo" '\
'AND logName="projects/'"$GOOGLE_CLOUD_PROJECT"'/logs/run.googleapis.com%2Fstderr" '\
'AND labels."run.googleapis.com/base_image_versions":*' \
  --project="$GOOGLE_CLOUD_PROJECT" \
  --limit=1 \
  --format="value(labels.['run.googleapis.com/base_image_versions'])"
us-docker.pkg.dev/serverless-runtimes/google-24/runtimes/python314:python314_20261104_3_14_10_RC00

That image tag records the exact python314 snapshot (20261104, running Python 3.14.10) running underneath your service. Base image updates patch Ubuntu packages and the Python interpreter, while Python libraries installed into your .venv directory from uv.lock stay pinned until you update the lock file and redeploy.

Inside the Python buildpack

With the service running on Python 3.14 with locked dependencies and base image updates enabled, you can inspect what Cloud Build did during that deployment. When you run gcloud run deploy --source, Cloud Build runs Google Cloud Buildpacks to install Python, sync your packages with uv, and choose a startup command based on your dependencies.

Stream the log from your latest Cloud Build build to inspect each participating buildpack (the output below is trimmed for brevity, and resolved package counts and elapsed times will vary on your machine):

BUILD_ID=$(gcloud builds list \
  --region="$REGION" \
  --project="$GOOGLE_CLOUD_PROJECT" \
  --limit=1 \
  --format="value(id)")

gcloud builds log "$BUILD_ID" \
  --region="$REGION" \
  --project="$GOOGLE_CLOUD_PROJECT"
=== Running detector ===
5 of 6 buildpacks participating
google.python.runtime            0.9.1
google.python.uv                 0.1.0
google.python.missing-entrypoint 0.9.0
google.utils.label-image         0.0.2
google.python.link-runtime       0.0.1
=== Running builder ===
=== Python - Runtime Using Runner (google.python.runtime@0.9.1) ===
Using Python version from GOOGLE_RUNTIME_VERSION: 3.14.10
Installing Python v3.14.10.
...
=== Python - Uv Using Runner (google.python.uv@0.1.0) ===
Using existing uv.lock.
...
Running "uv sync --active --link-mode=copy --python 3.14.10
(VIRTUAL_ENV=/layers/google.python.uv/uv-dependencies/.venv)"
Resolved 62 packages in 2ms
...
Prepared 59 packages in 706ms
Installed 59 packages in 338ms
...
Running "uv pip check (VIRTUAL_ENV=/layers/google.python.uv/uv-dependencies/.venv)"
Checked 59 packages in 2ms
All installed packages are compatible
=== Python - Missing Entrypoint Using Runner (google.python.missing-entrypoint@0.9.0) ===
Using Python version from GOOGLE_RUNTIME_VERSION: 3.14.10
WARNING: Setting default entrypoint: "uvicorn main:app --port 8080 --host 0.0.0.0"

Each Python buildpack handles one piece of the container setup:

  • google.python.runtime installs Python 3.14.10 from --base-image=python314 (or from your .python-version file when you pin a specific Python version without --base-image).
  • google.python.uv installs your locked dependencies from uv.lock into an isolated .venv using uv sync and verifies them with uv pip check.
  • google.python.missing-entrypoint spots fastapi[standard] in pyproject.toml and configures Uvicorn (an asynchronous Python web server) as the startup command.
  • google.python.link-runtime links your build output to the python314 base image so Cloud Run can apply OS and Python patches automatically.

Beyond FastAPI, the buildpack detects startup commands for Gunicorn, Uvicorn, Gradio, Streamlit, and Agent Development Kit (ADK) when your entry module is named main.py or app.py (ADK requires neither). If you need a custom startup command, you can override framework detection with [project.scripts], a Procfile, or GOOGLE_ENTRYPOINT (see the Python buildpack entrypoint reference for exact commands and precedence rules).

Clean up

Delete the service fastapi-uv-demo when you're done testing:

gcloud run services delete fastapi-uv-demo \
  --region="$REGION" \
  --project="$GOOGLE_CLOUD_PROJECT" \
  --quiet
Deleting [fastapi-uv-demo]...done.
Deleted service [fastapi-uv-demo].

Deleting a Cloud Run service leaves the built container images in Artifact Registry and the uploaded source archives in Cloud Storage, so remove both to avoid ongoing storage charges:

gcloud artifacts packages delete fastapi-uv-demo \
  --repository=cloud-run-source-deploy \
  --location="$REGION" \
  --project="$GOOGLE_CLOUD_PROJECT" \
  --quiet

gcloud storage rm --recursive \
  "gs://run-sources-$GOOGLE_CLOUD_PROJECT-$REGION/services/fastapi-uv-demo/" \
  --project="$GOOGLE_CLOUD_PROJECT"