|
1 | 1 | # S3 Bucket Configuration |
| 2 | + |
| 3 | +This guide covers two options for S3 storage configuration: |
| 4 | +- **[Option 1: AWS S3 (Production)](#aws-s3-production)** - For production environments |
| 5 | +- **[Option 2: MinIO (Local Development)](#minio-local-development)** - Recommended for local development |
| 6 | + |
| 7 | +## AWS S3 (Production) |
| 8 | + |
| 9 | +For production environments, use AWS S3: |
| 10 | + |
2 | 11 | 1. [Create an S3 bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html), with any name. |
3 | 12 | 2. Navigate to the S3 bucket permissions and add the following CORS policy. This is for development only, as it allows CORS from any origin. |
4 | 13 | ``` |
@@ -63,3 +72,94 @@ name, you can also set it using this variable. I.e.: |
63 | 72 | `S3_BUCKET_URL_BASE=https://files.mydomain.com` |
64 | 73 |
|
65 | 74 | For more information on using a custom domain, see [this documentation link](http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html#VirtualHostingCustomURLs). |
| 75 | + |
| 76 | + |
| 77 | +## MinIO (Local Development) |
| 78 | + |
| 79 | +MinIO is an S3-compatible object storage server that can run locally, making it ideal for development without needing to setup AWS account or incurring cloud storage costs. |
| 80 | + |
| 81 | +### Installation |
| 82 | + |
| 83 | +Install `minio-client` from a package manager then, choose one of the following installation methods: |
| 84 | + |
| 85 | +#### Option A: AUR (Arch Linux) |
| 86 | +```bash |
| 87 | +yay -S minio |
| 88 | +``` |
| 89 | + |
| 90 | +#### Option B: Download Binary (Linux) |
| 91 | +```bash |
| 92 | +wget https://dl.min.io/server/minio/release/linux-amd64/minio |
| 93 | +chmod +x minio |
| 94 | +sudo mv minio /usr/local/bin/ |
| 95 | +``` |
| 96 | + |
| 97 | +Visit [https://www.min.io/download](https://www.min.io/download) for other installation options. |
| 98 | + |
| 99 | +### Setup |
| 100 | + |
| 101 | +1. **Start MinIO server:** |
| 102 | +```bash |
| 103 | +minio server minio/ --console-address ":9090" |
| 104 | +``` |
| 105 | + |
| 106 | +This will start MinIO and create the folder if it doesn't exist and outputs the following information: |
| 107 | +- API endpoint (typically `http://127.0.0.1:9000`) |
| 108 | +- WebUI (typically `http://127.0.0.1:9090`) |
| 109 | +- Root credentials (default: `minioadmin` / `minioadmin`) |
| 110 | + |
| 111 | +2. **Access the MinIO Web Console:** |
| 112 | + - Open your browser and navigate to `http://127.0.0.1:9090` |
| 113 | + - Login (default): |
| 114 | + - Username: `minioadmin` |
| 115 | + - Password: `minioadmin` |
| 116 | + |
| 117 | +3. **Create a bucket:** |
| 118 | + - In the left panel, click "Create Bucket" |
| 119 | + - Enter bucket name: `p5js-editor` |
| 120 | + - Click "Create Bucket" |
| 121 | + |
| 122 | +4. **Configure bucket access (Public Access):** |
| 123 | + - In your prefered terminal, configure the bucket to allow anonymous viewing `mcli anonymous set public local/p5js-editor` |
| 124 | + |
| 125 | +5. **Update your `.env` file:** |
| 126 | +```bash |
| 127 | +# MinIO Configuration |
| 128 | +AWS_ACCESS_KEY=minioadmin |
| 129 | +AWS_SECRET_KEY=minioadmin |
| 130 | +AWS_REGION=us-east-1 |
| 131 | +AWS_S3_ENDPOINT=http://127.0.0.1:9000 |
| 132 | +AWS_S3_SIGNATURE_VERSION=v4 |
| 133 | +S3_BUCKET=p5js-editor |
| 134 | +S3_BUCKET_URL_BASE=http://127.0.0.1:9000/p5js-editor/ |
| 135 | +``` |
| 136 | + |
| 137 | +6. **Update S3 client configuration in code:** |
| 138 | + |
| 139 | +The following files need to be updated to use MinIO locally: |
| 140 | + |
| 141 | +**server/controllers/aws.controller.js:** |
| 142 | +```javascript |
| 143 | +const s3Client = new S3Client({ |
| 144 | + endpoint: process.env.AWS_S3_ENDPOINT || 'http://127.0.0.1:9000', |
| 145 | + credentials: { |
| 146 | + accessKeyId: process.env.AWS_ACCESS_KEY, |
| 147 | + secretAccessKey: process.env.AWS_SECRET_KEY |
| 148 | + }, |
| 149 | + region: process.env.AWS_REGION, |
| 150 | + forcePathStyle: true |
| 151 | +}); |
| 152 | +``` |
| 153 | + |
| 154 | +**server/migrations/s3UnderUser.js:** |
| 155 | +```javascript |
| 156 | +const s3Client = new S3Client({ |
| 157 | + endpoint: process.env.AWS_S3_ENDPOINT || 'http://127.0.0.1:9000', |
| 158 | + credentials: { |
| 159 | + accessKeyId: process.env.AWS_ACCESS_KEY, |
| 160 | + secretAccessKey: process.env.AWS_SECRET_KEY |
| 161 | + }, |
| 162 | + region: process.env.AWS_REGION, |
| 163 | + forcePathStyle: true |
| 164 | +}); |
| 165 | +``` |
0 commit comments