GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com β€” GitHub - msmenzyk/gcloud-pubsub-example: Minimal event-driven audio-analysis pipeline on Google Cloud (GCS to Pub/Sub to Cloud Run).

BranchesTags
Open more actions menu

Latest commit

 

History

10 Commits
10 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
demo
demo
 
 
.gitignore
.gitignore
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
main.py
main.py
 
 
requirements.txt
requirements.txt
 
 

Repository files navigation

🎧 Sample Audio Worker with Cloud Run + Pub/Sub + Firestore Example

This project demonstrates a minimal event-driven pipeline for analyzing audio files in Google Cloud.
When a file is uploaded to a Google Cloud Storage bucket, an event is sent via Pub/Sub to a Cloud Run service.
That service then processes metadata and stores it in Firestore for further use (e.g., fingerprinting, BPM detection, etc.).


🧩 1. Architecture Overview

[Client / System] β†’ [GCS Bucket]
          β”‚
          β–Ό
   GCS Notification β†’ Pub/Sub Topic `audio.ingest`
          β”‚
          β–Ό
 [Cloud Run Service: audio-worker]
          β”‚
          β–Ό
 [Firestore: tracks/{file_id}]

🧱 2. Components

Component Description
Cloud Storage (GCS) Stores uploaded audio files. Triggers Pub/Sub events.
Pub/Sub Messaging bus for asynchronous event delivery.
Cloud Run Stateless container service that receives Pub/Sub push messages and processes them.
Firestore NoSQL database that stores metadata about processed audio files.

☁️ 3. Google Cloud Setup

πŸ”Ή Set active project

gcloud config set project mtl-gcloud-pubsub-example

πŸ”Ή Enable required APIs

gcloud services enable run.googleapis.com   artifactregistry.googleapis.com   cloudbuild.googleapis.com   pubsub.googleapis.com   firestore.googleapis.com   storage.googleapis.com

🧰 4. Build & Deploy

Create Artifact Registry

gcloud artifacts repositories create mtl-repo   --repository-format=docker   --location=europe-central2   --description="Sample Audio Worker with Cloud Run + Pub/Sub + Firestore Example"

Build image and push to Artifact Registry

gcloud builds submit   --tag europe-central2-docker.pkg.dev/mtl-gcloud-pubsub-example/mtl-repo/audio-worker

Deploy to Cloud Run

gcloud run deploy audio-worker   --image europe-central2-docker.pkg.dev/mtl-gcloud-pubsub-example/mtl-repo/audio-worker   --platform managed   --region europe-central2   --allow-unauthenticated

After deployment, note the URL:

https://audio-worker-xyz-uc.a.run.app

This is your Pub/Sub push endpoint β†’ append /pubsub to it.


πŸ”” 5. Pub/Sub Setup

5.1 Create a topic

gcloud pubsub topics create audio.ingest

5.2 Create a push subscription

gcloud pubsub subscriptions create audio.ingest-sub   --topic=audio.ingest   --push-endpoint=https://audio-worker-307014563925.europe-central2.run.app/pubsub   --push-auth-service-account=$(gcloud projects describe mtl-gcloud-pubsub-example --format='value(projectNumber)')[email protected]

πŸ§ͺ 6. Test the Pipeline

6.1 Create Cloud Storage Bucket

gsutil mb -l europe-central2 gs://mtl-gcloud-pubsub-example-audio-uploads

6.2 Grant viewer role

gcloud projects add-iam-policy-binding mtl-gcloud-pubsub-example \
  --member="serviceAccount:$(gcloud projects describe mtl-gcloud-pubsub-example --format='value(projectNumber)')[email protected]" \
  --role="roles/storage.objectViewer"

6.3 Upload test track

gsutil cp demo/test_track.mp3 gs://mtl-gcloud-pubsub-example-audio-uploads/

6.4 Publish a test message

gcloud pubsub topics publish audio.ingest  --message='{"bucket":"mtl-gcloud-pubsub-example-audio-uploads","name":"test_track.mp3"}'

6.5 Check logs

gcloud run services logs read audio-worker --region=europe-central2

Expected output:

πŸ“¦ Processing file: gs://mtl-gcloud-pubsub-example-audio-uploads/test_track.mp3
βœ… Saved metadata to Firestore.

6.6 Verify in Firestore

Go to:
πŸ‘‰ Firestore Console

You should see a document under:

tracks / test_track.mp3

6.7 Screenshots

GCS Bucket upload

Firestore document


βš™οΈ 7. (Optional) Trigger from GCS Uploads

To automatically trigger Pub/Sub events when a file is uploaded:

gsutil notification create -t audio.ingest -f json gs://mtl-gcloud-pubsub-example-audio-uploads

Now every upload (OBJECT_FINALIZE) will trigger the audio-worker pipeline automatically.


🧠 8. Next Steps

You can extend this base pipeline by adding:

  • 🎡 Audio analysis (e.g., fingerprinting, BPM, duration)
  • πŸ” Additional Pub/Sub stages (audio.processed, audio.failed)
  • πŸ’Ύ Metadata enrichment (read tags, artist, ISRC, etc.)
  • πŸ“Š Dashboard reading Firestore data in Streamlit or BigQuery

πŸ“œ 9. License

MIT License β€” see LICENSE for details.


Mariusz SmenΕΌyk - Rockstars Developers dedicated to the Music Industry
Website | LinkedIn | Let's talk
Crafted by mtl.dev

About

Minimal event-driven audio-analysis pipeline on Google Cloud (GCS to Pub/Sub to Cloud Run).

Topics

cloud-runevent-drivengoogle-cloudpubsubpython

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 β€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800Γ—600. No cookies required.