#!/bin/sh set -e # Creates the media bucket on the RustFS object storage, with versioning # enabled. Runs inside the backend container, which ships boto3. # Load secrets into environment source /abra-entrypoint.sh -e python - <<'PYEOF' import os import sys import time import boto3 from botocore.exceptions import ClientError, EndpointConnectionError bucket = os.environ.get("AWS_STORAGE_BUCKET_NAME", "drive-media-storage") s3 = boto3.client( "s3", endpoint_url=os.environ["AWS_S3_ENDPOINT_URL"], aws_access_key_id=os.environ["AWS_S3_ACCESS_KEY_ID"], aws_secret_access_key=os.environ["AWS_S3_SECRET_ACCESS_KEY"], region_name=os.environ.get("AWS_S3_REGION_NAME", "us-east-1"), ) # Wait for the object storage to be ready (up to 60 seconds) for i in range(60): try: s3.list_buckets() break except (ClientError, EndpointConnectionError): time.sleep(1) else: sys.exit("s3-initialize: timed out waiting for the object storage") # Idempotent: skip if bucket already exists try: s3.head_bucket(Bucket=bucket) print(f"s3-initialize: bucket '{bucket}' already exists, skipping") sys.exit(0) except ClientError: pass print(f"s3-initialize: creating bucket '{bucket}'...") s3.create_bucket(Bucket=bucket) s3.put_bucket_versioning( Bucket=bucket, VersioningConfiguration={"Status": "Enabled"} ) print("s3-initialize: done") PYEOF