147 lines
3.3 KiB
Markdown
147 lines
3.3 KiB
Markdown
# Docker Build Sorunu - Çözüm Özeti
|
||
|
||
## ❌ Problem
|
||
|
||
```
|
||
Error: CGO_ENABLED=0 build failed
|
||
github.com/chai2010/webp@v1.4.0/webp.go:22:9: undefined: webpGetInfo
|
||
```
|
||
|
||
WebP kütüphanesi CGO gerektiriyor ancak Dockerfile'da `CGO_ENABLED=0` olarak ayarlanmış.
|
||
|
||
## ✅ Çözüm
|
||
|
||
WebP kütüphanesini kaldırıp standart Go image kütüphanelerini (JPEG/PNG) kullanmaya geçtik.
|
||
|
||
### Yapılan Değişiklikler:
|
||
|
||
#### 1. `pkg/utils/image_processor.go`
|
||
```go
|
||
// ❌ ÖNCE
|
||
import (
|
||
"github.com/chai2010/webp"
|
||
"github.com/disintegration/imaging"
|
||
)
|
||
|
||
// ✅ SONRA
|
||
import (
|
||
"github.com/disintegration/imaging"
|
||
)
|
||
|
||
// Varsayılan format değişti
|
||
// webp → jpg
|
||
```
|
||
|
||
#### 2. Avatar Format
|
||
- **Önceden:** WebP (CGO gerektirir)
|
||
- **Şimdi:** JPEG (CGO gerektirmez, optimize edilmiş)
|
||
- **Alternatif:** PNG (lossless)
|
||
|
||
#### 3. Build Testi
|
||
```bash
|
||
✅ CGO_ENABLED=0 GOOS=linux go build -o main .
|
||
✅ docker build -t authcentral .
|
||
✅ docker-compose -f docker-compose.prod.yml build
|
||
```
|
||
|
||
## 📋 Desteklenen Format'lar
|
||
|
||
| Format | Kalite | CGO Gerekli | Durum |
|
||
|--------|--------|-------------|-------|
|
||
| JPEG | Ayarlanabilir (1-100) | ❌ Hayır | ✅ Varsayılan |
|
||
| PNG | Lossless | ❌ Hayır | ✅ Destekleniyor |
|
||
| WebP | Ayarlanabilir | ✅ Evet | ❌ Kaldırıldı |
|
||
|
||
## 🚀 Dokploy Deployment
|
||
|
||
### Adımlar:
|
||
|
||
1. **Repository'yi Push Edin**
|
||
```bash
|
||
git add .
|
||
git commit -m "Fix: Remove WebP dependency for Docker build"
|
||
git push origin main
|
||
```
|
||
|
||
2. **Dokploy'da Yeni Proje**
|
||
- Source: GitHub
|
||
- Branch: main
|
||
- Build type: Docker Compose
|
||
- File: `docker-compose.prod.yml`
|
||
|
||
3. **Environment Variables**
|
||
- `.env.production.example` dosyasındaki tüm değişkenleri ekleyin
|
||
- Özellikle:
|
||
- `JWT_SECRET`
|
||
- `DB_PASSWORD`
|
||
- `REDIS_PASSWORD`
|
||
- OAuth credentials
|
||
- Email SMTP credentials
|
||
|
||
4. **Deploy**
|
||
- "Deploy" butonuna tıklayın
|
||
- Build loglarını izleyin
|
||
- ✅ Build başarılı!
|
||
|
||
## 📁 Yeni Dosyalar
|
||
|
||
1. ✅ `docker-compose.prod.yml` - Tamamlandı
|
||
2. ✅ `.env.production.example` - Environment variables template
|
||
3. ✅ `DOKPLOY_DEPLOYMENT.md` - Detaylı deployment guide
|
||
4. ✅ `.dockerignore` - Docker build optimization
|
||
|
||
## 🔧 Teknik Detaylar
|
||
|
||
### Dockerfile
|
||
```dockerfile
|
||
# CGO disabled - no C dependencies
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
|
||
```
|
||
|
||
### Image Processor
|
||
```go
|
||
// JPEG encoding (no CGO)
|
||
jpeg.Encode(outFile, img, &jpeg.Options{Quality: 90})
|
||
|
||
// PNG encoding (no CGO)
|
||
png.Encode(outFile, img)
|
||
```
|
||
|
||
## ✅ Test Sonuçları
|
||
|
||
```bash
|
||
# Local build
|
||
✅ go build -o main .
|
||
|
||
# Docker build
|
||
✅ docker build -t authcentral .
|
||
|
||
# Docker Compose build
|
||
✅ docker-compose -f docker-compose.prod.yml build
|
||
|
||
# CGO disabled build
|
||
✅ CGO_ENABLED=0 GOOS=linux go build -o main .
|
||
```
|
||
|
||
## 🎯 Sonuç
|
||
|
||
**Dokploy'a deploy için hazır!** 🚀
|
||
|
||
- ✅ WebP dependency kaldırıldı
|
||
- ✅ CGO_ENABLED=0 build çalışıyor
|
||
- ✅ Docker build başarılı
|
||
- ✅ Docker Compose build başarılı
|
||
- ✅ Production environment variables hazır
|
||
- ✅ Deployment guide hazır
|
||
|
||
**Avatar özellikleri korundu:**
|
||
- ✅ Otomatik resize
|
||
- ✅ Quality ayarı
|
||
- ✅ Cover/Contain/Resize modları
|
||
- ✅ JPEG ve PNG desteği
|
||
|
||
**Performans:**
|
||
- JPEG dosya boyutu WebP'den ~%10-20 daha büyük olabilir
|
||
- Ancak build problemi yok, production'a deploy edilebilir
|
||
- İsteğe bağlı gelecekte CDN ile optimize edilebilir
|