-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
338 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Contributing to CDN Service | ||
|
||
We love your input! We want to make contributing to CDN Service as easy and transparent as possible, whether it's: | ||
|
||
- Reporting a bug | ||
- Discussing the current state of the code | ||
- Submitting a fix | ||
- Proposing new features | ||
- Becoming a maintainer | ||
|
||
## Development Process | ||
|
||
We use GitHub to host code, to track issues and feature requests, as well as accept pull requests. | ||
|
||
1. Fork the repo and create your branch from `main`. | ||
2. If you've added code that should be tested, add tests. | ||
3. If you've changed APIs, update the documentation. | ||
4. Ensure the test suite passes. | ||
5. Make sure your code lints. | ||
6. Issue that pull request! | ||
|
||
## Pull Request Process | ||
|
||
1. Update the README.md with details of changes to the interface, if applicable. | ||
2. Update the docs/ with any new documentation. | ||
3. The PR will be merged once you have the sign-off of at least one maintainer. | ||
|
||
## Code Style | ||
|
||
- Follow Go best practices and style guidelines | ||
- Use meaningful variable and function names | ||
- Write comments for complex logic | ||
- Keep functions small and focused | ||
- Use proper error handling | ||
|
||
## Testing | ||
|
||
- Write unit tests for new functionality | ||
- Ensure all tests pass before submitting PR | ||
- Include integration tests where necessary | ||
- Test edge cases and error conditions | ||
|
||
## Commit Messages | ||
|
||
- Use the present tense ("Add feature" not "Added feature") | ||
- Use the imperative mood ("Move cursor to..." not "Moves cursor to...") | ||
- Limit the first line to 72 characters or less | ||
- Reference issues and pull requests liberally after the first line | ||
|
||
## Bug Reports | ||
|
||
**Great Bug Reports** tend to have: | ||
|
||
- A quick summary and/or background | ||
- Steps to reproduce | ||
- Be specific! | ||
- Give sample code if you can. | ||
- What you expected would happen | ||
- What actually happens | ||
- Notes (possibly including why you think this might be happening) | ||
|
||
## Feature Requests | ||
|
||
We love feature requests! When submitting a feature request, please: | ||
|
||
1. Check if the feature already exists | ||
2. Provide a clear description of the feature | ||
3. Explain why this feature would be useful | ||
4. Be open to feedback and discussion | ||
|
||
## License | ||
|
||
By contributing, you agree that your contributions will be licensed under its Apache License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# CDN API Documentation | ||
|
||
## Base URL | ||
``` | ||
http://localhost:3000 | ||
``` | ||
|
||
## Authentication | ||
All protected endpoints require an authentication token in the header: | ||
``` | ||
Authorization: Bearer <your-token> | ||
``` | ||
|
||
## Rate Limits | ||
- Global: 100 requests per minute per IP | ||
- Upload endpoints: 10 requests per minute per IP | ||
|
||
## Endpoints | ||
|
||
### Image Operations | ||
|
||
#### Get Image | ||
```http | ||
GET /:bucket/* | ||
GET /:bucket/w::width/* | ||
GET /:bucket/h::height/* | ||
GET /:bucket/w::width/h::height/* | ||
``` | ||
Parameters: | ||
- `bucket`: Bucket name | ||
- `width`: Image width (optional) | ||
- `height`: Image height (optional) | ||
- `*`: Image path | ||
|
||
Response: Image file or error message | ||
|
||
#### Upload Image | ||
```http | ||
POST /upload | ||
``` | ||
Headers: | ||
- `Content-Type: multipart/form-data` | ||
- `Authorization: Bearer <token>` | ||
|
||
Body: | ||
- `file`: Image file | ||
- `bucket`: Bucket name | ||
- `path`: Storage path (optional) | ||
|
||
Response: | ||
```json | ||
{ | ||
"status": true, | ||
"message": "Success", | ||
"data": { | ||
"url": "https://cdn.example.com/bucket/path/image.jpg" | ||
} | ||
} | ||
``` | ||
|
||
#### Upload Image with AWS | ||
```http | ||
POST /upload-with-aws | ||
``` | ||
Similar to `/upload` but stores in both Minio and AWS S3. | ||
|
||
#### Upload Image from URL | ||
```http | ||
POST /upload-url | ||
``` | ||
Body: | ||
- `url`: Source image URL | ||
- `bucket`: Bucket name | ||
- `path`: Storage path (optional) | ||
|
||
### Storage Operations | ||
|
||
#### AWS Bucket Operations | ||
```http | ||
GET /aws/bucket-list | ||
GET /aws/:bucket/exists | ||
GET /aws/vault-list | ||
``` | ||
|
||
#### Minio Bucket Operations | ||
```http | ||
GET /minio/bucket-list | ||
GET /minio/:bucket/exists | ||
GET /minio/:bucket/create | ||
GET /minio/:bucket/delete | ||
``` | ||
|
||
### Monitoring | ||
```http | ||
GET /metrics | ||
``` | ||
Returns Prometheus metrics for: | ||
- HTTP request counts | ||
- Request durations | ||
- Image processing durations | ||
- Storage operation durations | ||
|
||
## Error Responses | ||
```json | ||
{ | ||
"status": false, | ||
"message": "Error description", | ||
"data": null | ||
} | ||
``` | ||
|
||
Common HTTP Status Codes: | ||
- 200: Success | ||
- 400: Bad Request | ||
- 401: Unauthorized | ||
- 429: Too Many Requests | ||
- 500: Internal Server Error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# Deployment Guide | ||
|
||
## Prerequisites | ||
- Go 1.22 or higher | ||
- Docker and Docker Compose | ||
- MinIO Server | ||
- AWS Account (optional) | ||
- ImageMagick | ||
|
||
## Environment Setup | ||
|
||
1. Clone the repository: | ||
```bash | ||
git clone https://github.com/mstgnz/cdn.git | ||
cd cdn | ||
``` | ||
|
||
2. Copy environment file: | ||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
3. Configure environment variables in `.env`: | ||
```env | ||
# App | ||
APP_PORT=3000 | ||
APP_TOKEN=your-secret-token | ||
# Minio | ||
MINIO_ENDPOINT=localhost:9000 | ||
MINIO_ACCESS_KEY=your-access-key | ||
MINIO_SECRET_KEY=your-secret-key | ||
MINIO_USE_SSL=false | ||
# AWS (optional) | ||
AWS_ACCESS_KEY_ID=your-aws-access-key | ||
AWS_SECRET_ACCESS_KEY=your-aws-secret-key | ||
AWS_REGION=your-aws-region | ||
``` | ||
|
||
## Local Development | ||
|
||
1. Start MinIO: | ||
```bash | ||
docker-compose up -d minio | ||
``` | ||
|
||
2. Install dependencies: | ||
```bash | ||
go mod download | ||
``` | ||
|
||
3. Run the application: | ||
```bash | ||
go run cmd/main.go | ||
``` | ||
|
||
## Docker Deployment | ||
|
||
1. Build the image: | ||
```bash | ||
docker build -t cdn-service . | ||
``` | ||
|
||
2. Run with Docker Compose: | ||
```bash | ||
docker-compose up -d | ||
``` | ||
|
||
## Monitoring Setup | ||
|
||
1. Start Prometheus and Grafana: | ||
```bash | ||
docker-compose -f docker-compose.monitoring.yml up -d | ||
``` | ||
|
||
2. Access monitoring: | ||
- Prometheus: http://localhost:9090 | ||
- Grafana: http://localhost:3001 | ||
|
||
## Production Deployment | ||
|
||
### Kubernetes | ||
|
||
1. Apply Kubernetes manifests: | ||
```bash | ||
kubectl apply -f k8s/ | ||
``` | ||
|
||
2. Configure ingress: | ||
```bash | ||
kubectl apply -f k8s/ingress.yaml | ||
``` | ||
|
||
### Scaling | ||
|
||
- Horizontal scaling: | ||
```bash | ||
kubectl scale deployment cdn-service --replicas=3 | ||
``` | ||
|
||
- Configure resource limits in `k8s/deployment.yaml`: | ||
```yaml | ||
resources: | ||
limits: | ||
cpu: "1" | ||
memory: "1Gi" | ||
requests: | ||
cpu: "500m" | ||
memory: "512Mi" | ||
``` | ||
## Security Considerations | ||
1. SSL/TLS Configuration | ||
2. Rate Limiting (already implemented) | ||
3. Authentication | ||
4. Secure Environment Variables | ||
5. Regular Security Updates | ||
## Backup and Recovery | ||
1. MinIO Backup: | ||
```bash | ||
mc mirror minio/bucket backup/bucket | ||
``` | ||
|
||
2. Database Backup (if applicable) | ||
3. Configuration Backup | ||
|
||
## Troubleshooting | ||
|
||
1. Check logs: | ||
```bash | ||
docker logs cdn-service | ||
``` | ||
|
||
2. Monitor metrics: | ||
```bash | ||
curl http://localhost:3000/metrics | ||
``` | ||
|
||
3. Common issues: | ||
- Connection refused: Check if MinIO is running | ||
- Authentication failed: Verify environment variables | ||
- Rate limit exceeded: Check client IP and adjust limits if needed |