Build and Deploy to Google Cloud with Antigravity

1. Introduction

fca14bb9f4bb74f4.png

In this codelab, you will learn how to use Google Antigravity to design, build, and deploy a serverless application to Google Cloud. We will build a serverless and event-driven document pipeline that ingests files from Google Cloud Storage (GCS), processes them using Cloud Run and Gemini, and streams their metadata into BigQuery.

What you'll learn

  • How to use Antigravity for architectural planning and design.
  • Generate infrastructure as code (shell scripts) with an AI agent.
  • Build and deploy a Python based Cloud Run service.
  • Integrate Gemini on Vertex AI for multimodal document analysis.
  • Verify the end-to-end pipeline using Antigravity's Walkthrough artifact.

What you'll need

2. Overview of the app

Before we jump into architecting and implementing the application using Antigravity, let's first outline the application we want to build for ourselves.

We want to build a serverless and event-driven document pipeline that ingests files from Google Cloud Storage (GCS), processes them using Cloud Run and Gemini, and streams their metadata into BigQuery.

A high level architecture diagram for this application could look like this:

3bd519cfab38258d.png

This does not have to be precise. Antigravity can help us to figure out the architecture details as we go along. However, it helps to have an idea on what you want to build. The more detail you can provide, the better results you'll get from Antigravity in terms of architecture and code.

3. Plan the architecture

We are ready to get started planning the architecture details with Antigravity!

Antigravity excels at planning complex systems. Instead of writing code immediately, we can start by defining the high-level architecture and use one of the features to help Antigravity evaluate our request, ask us follow up questions and then proceed in its planning and implementation.

Assuming that you have launched Antigravity, we will be creating a new Project for this codelab.

Click on the new project icon next to the Projects lab and then New Project as shown below:

949cd615a1ce8dc3.png

This will bring up the Add Folder option as shown below:

ee8ff88b71c10e9f.png

Click on the Add Folder button to add a folder to your project. On my machine I created a google-cloud-serverless-app folder and added that to this project.

This opens up a conversation in the google-cloud-serverless-app workspace.

Click on the main settings icon ⚙️in the left bottom of the screen and go to Project specific settings. Set the Agent Settings / Security Preset to Default and Agent Behaviour / Artifact Review Policy to Always Ask, as shown below:

b28e175be64f4390.png

This will ensure that at every step, you will get to review, and approve the plan before the agent executes.

Prompt

Now, we're ready to provide our first prompt to Antigravity. We are going to be using a slash command /grill-me to evaluate our request.

Type /grill-me and then enter the following prompt and click submit button:

/grill-me 

I want to build a serverless event-driven document processing pipeline on Google Cloud.
Architecture:
- Ingestion: Users upload files to a Cloud Storage bucket.
- Trigger: File uploads trigger a Pub/Sub message.
- Processor: A Python-based Cloud Run service receives the message, processes the file (simulated OCR), and extracts metadata.
- Storage: Stream the metadata (filename, date, tags, word_count) into a BigQuery dataset. 

The /grill-me command asks a number of follow up questions that you can try to answer to the best of your knowledge. It also suggests Recommended Answers and you can go with that if you'd like.

A sample run of my /grill-me command is shown below:

How would you provision and manage the Google Cloud infrastructure resources (Cloud Storage buckets, Pub/Sub topics, BigQuery datasets, Cloud Run service)?
gcloud CLI Setup Script - Shell scripts running gcloud CLI commands to create resources step-by-step

How should the Cloud Storage upload events trigger and reach your Python Cloud Run service?
(Recommended) Native Cloud Storage Pub/Sub Notifications + Pub/Sub Push subscription to Cloud Run (direct, lightweight, standard event-driven approach)

Which Python web framework would you prefer for the Cloud Run processing service?
Flask (with Gunicorn) - Standard, lightweight, and very common for simple Cloud Run services

How should the OCR and metadata extraction logic be implemented in the Cloud Run service?
(Recommended) Full local simulation - If it's a .txt file, read the contents, count words, and extract tags. For other files, generate mock OCR metadata and simulated word count. No external API calls.

Which BigQuery insertion method should the Cloud Run service use to store metadata?
(Recommended) BigQuery table.insert_rows() (Legacy Streaming API) - Extremely simple to code, clean error handling, perfect for simulation and low-to-medium volumes.

How should security/authentication be configured for the Cloud Run service?
Unauthenticated Cloud Run - Allow public requests to the Cloud Run service URL (simpler setup, but insecure for production).


What schema would you like to define for the BigQuery metadata table?
(Recommended) Extended Schema - Include filename, bucket, size, content_type, word_count, tags (as a REPEATED STRING array), ocr_text_preview, and process_timestamp.

How should the Cloud Run service handle processing failures (e.g., file not found, BigQuery write error)?
(Recommended) Fail-Fast with Retry - Log error to standard output (Cloud Logging) and return HTTP 500 to Pub/Sub, so that Pub/Sub automatically retries the message delivery.

What testing tools should we generate to verify the pipeline's functionality?
(Recommended) Both - Include a local test script (sending mock Pub/Sub POST requests to the local Flask server) and a Cloud-integrated test script (uploading a real file to GCS and verifying BigQuery).

Notice that I went with asking Antigravity to go with:

  • A simple gcloud CLI script to provision resources
  • Native Cloud Storage Pub/Sub Notifications + Pub/Sub Push subscription to Cloud Run
  • Use Flask (with Gunicorn) for the framework
  • Just use local simulation with a text file for the data instead of live OCR data
  • Use BigQuery table.insert_rows() to insert rows into BigQuery
  • Unauthenticated Cloud Run deployment

and other recommended options.

Implementation Plan and Task List

Antigravity will now get to work and generate an Implementation Plan. It puts it up for your review by giving you a message similar to the one below:

2bf129fc14fa019e.png

You can click on the Auxiliary Pane toggle in the top right window and view the Artifacts generated, which at this point is just the Implementation Plan.

fc8d1f0f54d3e723.png

This plan outlines:

  • Infrastructure: GCS Bucket, Pub/Sub Topic, BigQuery Dataset.
  • Processor: Python/Flask app, Dockerfile, Requirements.
  • Integration: GCS Notifications → Pub/Sub → Cloud Run.

You should see something similar to the following. A partial listing of the implementation plan on our machine is shown below:

Event-Driven Document Processing Pipeline Implementation Plan
This implementation plan describes the components and setup scripts required to build a serverless event