Files
karaoke-gen/infrastructure/modules/storage.py
T
Andrew Beveridge ☄️ d445861aea fix(infra): allow GET/HEAD CORS on storage bucket for vocals waveform (#932)
Allow GET/HEAD CORS on the storage bucket so the vocals waveform's cross-origin fetch()+decodeAudioData can read the stem. Applied locally via pulumi up (update 830); CI re-applies as no-op.
2026-08-23 01:45:42 -04:00

66 lines
2.3 KiB
Python

"""
Cloud Storage resources.
Manages the GCS bucket for uploads, outputs, and temporary files.
"""
import pulumi
import pulumi_gcp as gcp
from pulumi_gcp import storage
from config import PROJECT_ID
def create_bucket() -> storage.Bucket:
"""
Create the main GCS bucket with lifecycle rules.
Returns:
storage.Bucket: The created bucket resource.
"""
bucket = storage.Bucket(
"karaoke-storage",
name=f"karaoke-gen-storage-{PROJECT_ID}",
location="US-CENTRAL1",
force_destroy=False, # Prevent accidental deletion
uniform_bucket_level_access=True,
cors=[
storage.BucketCorArgs(
origins=[
"https://gen.nomadkaraoke.com",
"https://vocalstar.nomadkaraoke.com",
"https://singa.nomadkaraoke.com",
"http://localhost:3000",
],
# PUT: direct-to-GCS uploads. GET/HEAD: the lyrics-review vocals
# waveform fetch()es the signed stem URL and reads its bytes via
# decodeAudioData — unlike <audio> playback, that's a cross-origin
# read and needs CORS. Without GET the browser blocks it with
# "Access-Control-Allow-Origin missing".
methods=["GET", "HEAD", "PUT"],
response_headers=["Content-Type"],
max_age_seconds=3600,
),
],
versioning=storage.BucketVersioningArgs(enabled=True),
soft_delete_policy=storage.BucketSoftDeletePolicyArgs(retention_duration_seconds=604800),
lifecycle_rules=[
storage.BucketLifecycleRuleArgs(
action=storage.BucketLifecycleRuleActionArgs(type="Delete"),
condition=storage.BucketLifecycleRuleConditionArgs(
age=7,
matches_prefixes=["temp/", "uploads/"]
),
),
storage.BucketLifecycleRuleArgs(
action=storage.BucketLifecycleRuleActionArgs(type="Delete"),
condition=storage.BucketLifecycleRuleConditionArgs(
num_newer_versions=1,
days_since_noncurrent_time=30,
),
),
],
)
return bucket