Rails Deployment - von Entwicklung zu Production
Deine App auf den Server bringen ist essentiell.
Deployment-Optionen
Heroku (einfachster Weg)
heroku create myapp
git push heroku main
heroku run rails db:migrate
Heroku managed alles. Einfach für Anfänger.
Kosten: 7$ bis 50$ monatlich
DigitalOcean (Kontrolle bei guten Preisen)
# Droplet erstellen (Server)
# SSH verbinden
git clone https://github.com/user/myapp
cd myapp
bundle install
rails db:migrate
# Nginx/Puma konfigurieren
Mehr Kontrolle, etwas komplizierter.
Kosten: 5$ bis 40$ monatlich
AWS (professionell, komplex)
EC2 Instances, RDS für Datenbanken, S3 für Assets.
Sehr flexibel aber komplex.
Kosten: Variabel, 10$+ monatlich
Docker für Rails
Container-Ansatz für konsistente Umgebungen:
FROM ruby:3.2
WORKDIR /app
COPY . .
RUN bundle install
CMD ["rails", "server", "-b", "0.0.0.0"]
docker build -t myapp .
docker run -p 3000:3000 myapp
Production Checklist
- Database konfiguriert
- Environment-Variablen gesetzt
- Secrets sicher konfiguriert
- Logs aktiviert
- Error tracking (Sentry)
- SSL/TLS Zertifikat
- Monitoring active
- Backups configured
- CI/CD Pipeline
- Deployment-Process dokumentiert
CI/CD mit GitHub Actions
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: bundle install
- run: bundle exec rspec
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- run: |
git push heroku main
Caching für Performance
# config/environments/production.rb
config.cache_classes = true
config.cache_store = :redis_store, ENV['REDIS_URL']
Monitoring und Alerting
Mit New Relic oder DataDog:
gem 'newrelic_rpm'
Monitore:
- Response Times
- Error Rates
- Database Performance
- Memory Usage
Häufige Fehler
- ✗ Secrets in Code committen
- ✗ Development Umgebung in Production pushen
- ✗ Keine Backups
- ✗ Keine Monitoring
- ✗ Manual Deployment (Fehleranfällig)
Best Practices
- Automatisch: Alles Automated, nichts manuell
- Testiert: Alles bevor Deploy
- Backups: Regelmäßig
- Monitoring: Immer
- Dokumentation: Prozess dokumentieren
Ressourcen
- Heroku Rails Guide
- DigitalOcean App Platform
- "Deploying Ruby Applications"
