3.3 KiB
3.3 KiB
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
// ❌ Ö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
✅ 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:
-
Repository'yi Push Edin
git add . git commit -m "Fix: Remove WebP dependency for Docker build" git push origin main -
Dokploy'da Yeni Proje
- Source: GitHub
- Branch: main
- Build type: Docker Compose
- File:
docker-compose.prod.yml
-
Environment Variables
.env.production.exampledosyasındaki tüm değişkenleri ekleyin- Özellikle:
JWT_SECRETDB_PASSWORDREDIS_PASSWORD- OAuth credentials
- Email SMTP credentials
-
Deploy
- "Deploy" butonuna tıklayın
- Build loglarını izleyin
- ✅ Build başarılı!
📁 Yeni Dosyalar
- ✅
docker-compose.prod.yml- Tamamlandı - ✅
.env.production.example- Environment variables template - ✅
DOKPLOY_DEPLOYMENT.md- Detaylı deployment guide - ✅
.dockerignore- Docker build optimization
🔧 Teknik Detaylar
Dockerfile
# CGO disabled - no C dependencies
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
Image Processor
// JPEG encoding (no CGO)
jpeg.Encode(outFile, img, &jpeg.Options{Quality: 90})
// PNG encoding (no CGO)
png.Encode(outFile, img)
✅ Test Sonuçları
# 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