gcp-hockey-results/motm_app/MINIO_LOGO_FIX.md

188 lines
5.3 KiB
Markdown

# MinIO Logo Display Fix
## Problem
Club logos were not displaying when deployed to Kubernetes because the application was generating AWS S3 URLs instead of MinIO URLs:
```
https://hockey-apps.s3.amazonaws.com/assets/logos/HKFC_crest.png
```
## Root Cause
The Helm chart values had `storageProvider: "aws"` configured, which caused the `s3_config.py` module's `_get_public_url()` method to generate AWS S3 URLs instead of MinIO URLs.
## Solution
Updated the Helm chart values files to use MinIO configuration:
### Changes Made
1. **`helm-chart/motm-app/values.yaml`** (default values):
- Changed `storageProvider: "aws"``"minio"`
- Set `endpoint: "http://minio.default.svc.cluster.local:9000"`
- Set `bucket: "hockey-apps"`
- Changed `useSignedUrls: true``false`
- Changed `useSSL: true``false`
2. **`helm-chart/motm-app/values-production.yaml`**:
- Changed `storageProvider: "aws"``"minio"`
- Set `endpoint: "http://minio.default.svc.cluster.local:9000"`
- Set `bucket: "hockey-apps"`
- Changed `useSignedUrls: true``false`
- Changed `useSSL: true``false`
3. **`helm-chart/motm-app/values-development.yaml`**:
- Already correctly configured with MinIO
## Deployment Instructions
### Option 1: Upgrade Existing Deployment
If you have an existing deployment, upgrade it with the new values:
```bash
cd /home/jonny/Projects/gcp-hockey-results/motm_app/helm-chart/motm-app
# For development
helm upgrade motm-app . -f values-development.yaml --namespace default
# For production
helm upgrade motm-app . -f values-production.yaml --namespace default
```
### Option 2: Redeploy from Scratch
```bash
cd /home/jonny/Projects/gcp-hockey-results/motm_app/helm-chart/motm-app
# Delete existing deployment
helm uninstall motm-app --namespace default
# Reinstall with correct configuration
helm install motm-app . -f values-production.yaml --namespace default
```
### Option 3: Override Values During Deployment
If you don't want to modify the files, you can override during deployment:
```bash
helm upgrade --install motm-app . \
--set s3.storageProvider=minio \
--set s3.endpoint="http://minio.default.svc.cluster.local:9000" \
--set s3.bucket=hockey-apps \
--set s3.useSignedUrls=false \
--set s3.useSSL=false \
--namespace default
```
## Important Considerations
### 1. MinIO Service Name
The endpoint `http://minio.default.svc.cluster.local:9000` assumes:
- MinIO service is named `minio`
- MinIO is deployed in the `default` namespace
- MinIO is running on port `9000`
If your MinIO service has a different name or is in a different namespace, update the endpoint accordingly:
```
http://<service-name>.<namespace>.svc.cluster.local:<port>
```
### 2. External MinIO Access
If you need to access MinIO from outside the cluster (e.g., for direct browser access or CDN), you can configure an external endpoint:
```yaml
s3:
storageProvider: "minio"
endpoint: "https://minio.yourdomain.com" # External endpoint
useSSL: true # Enable SSL for external access
useSignedUrls: true # Optional: use signed URLs for security
```
### 3. Bucket Configuration
Ensure the MinIO bucket `hockey-apps` exists and has the correct permissions:
```bash
# Using MinIO CLI (mc)
mc alias set myminio http://minio.default.svc.cluster.local:9000 <access-key> <secret-key>
mc mb myminio/hockey-apps
mc anonymous set download myminio/hockey-apps # Make bucket publicly readable
```
### 4. Upload Logos to MinIO
Ensure club logos are uploaded to the correct path in MinIO:
```
hockey-apps/assets/logos/HKFC_crest.png
hockey-apps/assets/logos/<other-club-logos>
```
## Verification
After deployment, verify the fix:
1. **Check Pod Environment Variables**:
```bash
kubectl exec -it <pod-name> -- env | grep S3
```
You should see:
```
S3_ENABLED=true
S3_STORAGE_PROVIDER=minio
S3_ENDPOINT=http://minio.default.svc.cluster.local:9000
S3_BUCKET=hockey-apps
S3_USE_SIGNED_URLS=false
S3_USE_SSL=false
```
2. **Check Logo URLs**:
- Visit the application in a browser
- Inspect a club logo image
- Verify the URL now points to MinIO, e.g.:
```
http://minio.default.svc.cluster.local:9000/hockey-apps/assets/logos/HKFC_crest.png
```
3. **Test Logo Loading**:
- Open the application
- Navigate to pages displaying club logos
- Confirm logos are now displaying correctly
## Rollback
If you need to rollback to AWS S3:
```bash
helm upgrade motm-app . \
--set s3.storageProvider=aws \
--set s3.endpoint="" \
--set s3.bucket=motm-assets \
--set s3.useSignedUrls=true \
--set s3.useSSL=true \
--namespace default
```
## Related Files
- `s3_config.py` - S3/MinIO configuration and URL generation
- `helm-chart/motm-app/templates/deployment.yaml` - Environment variable injection
- `helm-chart/motm-app/values.yaml` - Default configuration
- `helm-chart/motm-app/values-production.yaml` - Production configuration
- `helm-chart/motm-app/values-development.yaml` - Development configuration
## Technical Details
The `s3_config.py` module's `_get_public_url()` method (lines 285-303) generates URLs based on the storage provider:
- **AWS S3**: `https://{bucket}.s3.{region}.amazonaws.com/{key}`
- **MinIO**: `{protocol}://{endpoint}/{bucket}/{key}`
When `storageProvider: "minio"`, the code correctly generates MinIO URLs with the configured endpoint.