diff --git a/self-hosting/docker-compose/.env.example b/self-hosting/docker-compose/.env.example index 3f911224d..e144f29e5 100644 --- a/self-hosting/docker-compose/.env.example +++ b/self-hosting/docker-compose/.env.example @@ -32,13 +32,17 @@ CONTENT_FETCH_URL=http://content-fetch:8080/?token=some_token GCS_USE_LOCAL_HOST=true GCS_UPLOAD_BUCKET=omnivore AUTO_VERIFY=true +# S3 Storage Configuration +# For MinIO (local development): Use minio/miniominio credentials below +# For AWS S3 (production): Replace with real AWS credentials and bucket name +# The setup script will automatically configure CORS for AWS S3 using CLIENT_URL as allowed origin AWS_ACCESS_KEY_ID=minio # Used for Minio S3 Client AWS_SECRET_ACCESS_KEY=miniominio AWS_REGION=us-east-1 CONTENT_FETCH_QUEUE_ENABLED=true IMAGE_PROXY_URL=http://localhost:7070 # Need to change this for NGINX -CLIENT_URL=http://localhost:3000 # Need to change this when using NGINX +CLIENT_URL=http://localhost:3000 # Need to change this when using NGINX. Also used for S3 CORS configuration. LOCAL_MINIO_URL=http://localhost:1010 # Redis diff --git a/self-hosting/docker-compose/docker-compose.yml b/self-hosting/docker-compose/docker-compose.yml index 31617fe9e..8df9b1209 100644 --- a/self-hosting/docker-compose/docker-compose.yml +++ b/self-hosting/docker-compose/docker-compose.yml @@ -131,15 +131,15 @@ services: - BUCKET_NAME=omnivore - ENDPOINT=http://minio:9000 - AWS_S3_ENDPOINT_URL=http://minio:9000 + env_file: + - .env + volumes: + - ./setup-s3.sh:/setup-s3.sh:ro depends_on: - minio entrypoint: > /bin/bash -c " - sleep 5; - until (/usr/bin/mc alias set myminio http://minio:9000 minio miniominio) do echo '...waiting...' && sleep 1; done; - /usr/bin/mc mb myminio/omnivore; - /usr/bin/mc anonymous set public myminio/omnivore; - exit 0; + chmod +x /setup-s3.sh && /setup-s3.sh " mail-watch-server: image: "ghcr.io/omnivore-app/sh-local-mail-watcher:latest" diff --git a/self-hosting/docker-compose/setup-s3.sh b/self-hosting/docker-compose/setup-s3.sh new file mode 100644 index 000000000..090d93843 --- /dev/null +++ b/self-hosting/docker-compose/setup-s3.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +set -e + +echo "Starting S3/MinIO setup..." + +# Wait for MinIO to be ready if using MinIO +if [ "$AWS_ACCESS_KEY_ID" = "minio" ]; then + echo "Detected MinIO configuration" + echo "Waiting for MinIO to be ready..." + sleep 5 + + # Setup MinIO with bucket creation + until (/usr/bin/mc alias set myminio http://minio:9000 minio miniominio) do + echo '...waiting for MinIO...' + sleep 1 + done + + echo "Creating MinIO bucket: ${GCS_UPLOAD_BUCKET:-omnivore}" + /usr/bin/mc mb myminio/${GCS_UPLOAD_BUCKET:-omnivore} || true + /usr/bin/mc anonymous set public myminio/${GCS_UPLOAD_BUCKET:-omnivore} + echo "MinIO setup complete" + +else + echo "Detected AWS S3 configuration" + + # Install AWS CLI if not present + if ! command -v aws &> /dev/null; then + echo "Installing AWS CLI..." + apk add --no-cache aws-cli + fi + + BUCKET_NAME="${GCS_UPLOAD_BUCKET:-omnivore}" + CORS_ORIGIN="${CLIENT_URL:-https://localhost:3000}" + AWS_REGION="${AWS_REGION:-us-east-1}" + + echo "Configuring CORS for S3 bucket: $BUCKET_NAME" + echo "Allowed origin: $CORS_ORIGIN" + + # Create CORS configuration JSON + cat > /tmp/cors.json << EOF +{ + "CORSRules": [ + { + "AllowedHeaders": ["*"], + "AllowedMethods": ["GET", "PUT", "POST", "DELETE", "HEAD"], + "AllowedOrigins": ["$CORS_ORIGIN"], + "ExposeHeaders": [ + "ETag", + "x-amz-server-side-encryption", + "x-amz-request-id", + "x-amz-id-2" + ], + "MaxAgeSeconds": 3000 + } + ] +} +EOF + + # Apply CORS configuration + echo "Applying CORS configuration..." + aws s3api put-bucket-cors \ + --bucket "$BUCKET_NAME" \ + --region "$AWS_REGION" \ + --cors-configuration file:///tmp/cors.json + + echo "S3 CORS configuration complete for bucket: $BUCKET_NAME" + + # Verify CORS configuration + echo "Verifying CORS configuration..." + aws s3api get-bucket-cors --bucket "$BUCKET_NAME" --region "$AWS_REGION" || echo "CORS verification failed (this may be normal if bucket doesn't exist yet)" +fi + +echo "S3 setup completed successfully" \ No newline at end of file