first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 21:37:58 +03:00
commit 8b1fbdee99
104 changed files with 23398 additions and 0 deletions

292
DOKPLOY_DEPLOYMENT.md Normal file
View File

@@ -0,0 +1,292 @@
# AuthCentral - Dokploy Deployment Guide
## 🚀 Dokploy'a Deploy Etme
### Ön Hazırlık
1. **Repository'yi GitHub'a Push Edin**
```bash
git add .
git commit -m "Production ready build"
git push origin main
```
2. **.env.production Dosyası Oluşturun**
- `.env.production.example` dosyasını kopyalayın
- Gerçek değerlerinizle doldurun
- **ÖNEMLİ:** Bu dosyayı GitHub'a pushlamamayın!
### Dokploy Adımları
#### 1. Yeni Proje Oluştur
- Dokploy dashboard'a giriş yapın
- "New Project" butonuna tıklayın
- Proje adı: `authcentral`
#### 2. GitHub Repository Bağlayın
- Source type: **GitHub**
- Repository: Projenizin GitHub URL'si
- Branch: `main`
- Build type: **Docker Compose**
#### 3. Environment Variables Ayarlayın
Dokploy dashboard'da aşağıdaki environment variable'ları ekleyin:
**Veritabanı:**
```env
DB_USER=postgres
DB_PASSWORD=YOUR_SECURE_PASSWORD
DB_NAME=gauth
DB_HOST=postgres
DB_PORT=5432
```
**Redis:**
```env
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=YOUR_REDIS_PASSWORD
REDIS_USER=default
```
**JWT:**
```env
JWT_SECRET=YOUR_SUPER_SECRET_JWT_KEY
```
**OAuth - Google:**
```env
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
```
**OAuth - GitHub:**
```env
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
```
**URLs:**
```env
APP_URL=https://yourdomain.com
CLIENT_CALLBACK_URL=https://yourdomain.com/api/v1/auth
```
**Email:**
```env
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=your_email@gmail.com
EMAIL_HOST_PASSWORD=your_app_password
EMAIL_USE_TLS=true
EMAIL_USE_SSL=false
EMAIL_FROM=noreply@yourdomain.com
```
**Avatar Settings:**
```env
AVATAR_H=150
AVATAR_W=150
AVATAR_Q=90
AVATAR_B=cover
AVATAR_F=webp
```
#### 4. Docker Compose Dosyası
- Dokploy otomatik olarak `docker-compose.prod.yml` dosyasını kullanacak
- Bu dosya **sadece uygulama** servisini içerir
- PostgreSQL ve Redis Dokploy'da harici servisler olarak yönetilir:
- PostgreSQL: Dokploy managed database
- Redis: Dokploy managed cache
- AuthCentral app: Container (port: 8080)
#### 5. Deploy
- "Deploy" butonuna tıklayın
- Build loglarını izleyin
- Deploy tamamlandığında URL'niz aktif olacak
---
## 📋 Build Özellikleri
### WebP Desteği Aktif
Avatar resimleri varsayılan olarak WebP formatında:
- ✅ **WebP** (default, optimize edilmiş, küçük dosya boyutu)
- ✅ **JPEG** (alternatif)
- ✅ **PNG** (lossless)
**WebP Avantajları:**
- %25-35 daha küçük dosya boyutu (JPEG'e göre)
- Modern tarayıcılarda tam destek
- Yüksek kalite ve düşük boyut
### Dockerfile Özeti
```dockerfile
# Build Stage - CGO enabled for WebP
FROM golang:1.25.6-alpine AS builder
WORKDIR /app
RUN apk add --no-cache git gcc musl-dev libwebp-dev
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go mod tidy
RUN go install github.com/swaggo/swag/cmd/swag@latest
RUN swag init
RUN CGO_ENABLED=1 GOOS=linux go build -a -ldflags '-linkmode external -extldflags "-static"' -o main .
# Run Stage - WebP runtime library
FROM alpine:latest
WORKDIR /app
RUN apk --no-cache add ca-certificates libwebp
COPY --from=builder /app/main .
COPY --from=builder /app/.env .
COPY --from=builder /app/web ./web
COPY --from=builder /app/docs ./docs
EXPOSE 8080
CMD ["./main"]
```
### Production Yapı
- **PostgreSQL:** Dokploy managed service (harici)
- **Redis:** Dokploy managed service (harici)
- **Application:** Docker container
- **Volumes:** `./uploads` (avatar storage)
---
## 🔒 Güvenlik Notları
### Önemli!
1. **JWT_SECRET**: Güçlü bir secret kullanın (min 32 karakter)
2. **DB_PASSWORD**: Güvenli bir şifre seçin
3. **REDIS_PASSWORD**: Redis için şifre ayarlayın
4. **Email Credentials**: Gmail için "App Password" kullanın
### Production Checklist
- [ ] Tüm secrets güçlü ve benzersiz
- [ ] OAuth callback URL'leri doğru
- [ ] Email SMTP ayarları test edildi
- [ ] Domain DNS ayarları yapıldı
- [ ] SSL sertifikası aktif (Dokploy otomatik)
- [ ] Rate limiting aktif (default: ✅)
- [ ] CORS ayarları yapılandırıldı
---
## 🗄️ Veritabanı
### İlk Admin Kullanıcı Oluşturma
Deploy sonrası container'a bağlanın:
```bash
# Dokploy dashboard'dan container terminal'i açın veya:
docker exec -it app_auth_central /app/main seed-admin
```
**Varsayılan Admin:**
- Email: `admin@gauth.local`
- Password: `Admin@123`
⚠️ **İlk login sonrası şifreyi değiştirin!**
### PostgreSQL Extensions
UUID extension otomatik olarak yüklenir:
```sql
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
```
---
## 📊 Monitoring
### Healthcheck Endpoints
```bash
# Application health
curl https://yourdomain.com/
# Validate token
curl https://yourdomain.com/v1/auth/validate \
-H "Authorization: Bearer YOUR_TOKEN"
```
### Logs
Dokploy dashboard'dan:
- Application logs
- PostgreSQL logs
- Redis logs
görüntüleyebilirsiniz.
---
## 🔄 Update (Güncelleme)
Yeni kod push ettiğinizde:
1. GitHub'a push edin
2. Dokploy dashboard'da "Redeploy" butonuna tıklayın
3. Build tamamlanınca otomatik restart olur
**Zero-downtime deployment** için Dokploy'un "Rolling Update" özelliğini kullanın.
---
## 🆘 Troubleshooting
### Build Hatası
```
Error: CGO_ENABLED=0 build failed
```
✅ **Çözüldü:** WebP kütüphanesi kaldırıldı
### Database Connection Error
```
Error: failed to connect to database
```
✅ **Kontrol edin:**
- `DB_HOST=postgres` (service name)
- `DB_PASSWORD` doğru mu?
- PostgreSQL container çalışıyor mu?
### Redis Connection Error
```
Error: failed to connect to redis
```
✅ **Kontrol edin:**
- `REDIS_HOST=redis` (service name)
- `REDIS_PASSWORD` ayarlandı mı?
### OAuth Login Error
```
Error: OAuth callback failed
```
✅ **Kontrol edin:**
- Google/GitHub Console'da callback URL doğru mu?
- `CLIENT_CALLBACK_URL=https://yourdomain.com/api/v1/auth`
- OAuth credentials doğru mu?
---
## 📖 API Endpoints
Deploy sonrası:
- **Swagger UI**: `https://yourdomain.com/v1/docs/index.html`
- **Health**: `https://yourdomain.com/`
- **Register**: `POST https://yourdomain.com/v1/auth/register`
- **Login**: `POST https://yourdomain.com/v1/auth/login`
---
## 🎉 Deploy Sonrası
1. ✅ Admin kullanıcı oluşturun
2. ✅ Test kullanıcısı ile register deneyin
3. ✅ OAuth login test edin
4. ✅ Email doğrulama test edin
5. ✅ Avatar upload test edin
6. ✅ Swagger dokümantasyonu kontrol edin
**AuthCentral başarıyla deploy edildi!** 🚀