Files

448 lines
8.6 KiB
Markdown
Raw Permalink Normal View History

2025-10-26 22:53:16 +01:00
# 🐳 Docker Deployment Guide
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
This guide covers deploying the **Awesome App** using Docker and Docker Compose.
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
## 📋 Table of Contents
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
- [Quick Start](#quick-start)
- [Compose Files](#compose-files)
- [Environment Variables](#environment-variables)
- [Production Deployment](#production-deployment)
- [Database Management](#database-management)
- [Traefik Integration](#traefik-integration)
- [Troubleshooting](#troubleshooting)
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
---
## 🚀 Quick Start
### Local Development
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Copy environment example
cp .env.example .env
# Edit .env with your configuration
nano .env
# Start the application
docker compose up -d
# View logs
docker compose logs -f awesome-app
# Stop the application
docker compose down
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
The app will be available at `http://localhost:3000`
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
---
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
## 📁 Compose Files
### `compose.yml` (Base Configuration)
The base compose file for local development and testing:
- Uses the pre-built Docker image from GitHub Container Registry
- Exposes port 3000 for local access
- Mounts a local volume for database persistence
- Includes health checks
### `compose.production.yml` (Production Override)
Production configuration that extends the base:
- Integrates with Traefik reverse proxy
- Removes exposed ports (handled by Traefik)
- Adds compression middleware
- Configures HTTPS/TLS
- Uses external `compose_network`
---
## 🔧 Environment Variables
### Required Variables
```env
# Project name
AWESOME_COMPOSE_PROJECT_NAME=awesome
# Docker image
AWESOME_IMAGE=ghcr.io/valknarness/awesome-app:latest
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### Optional Variables
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
```env
# Local port (development only)
AWESOME_PORT=3000
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Node environment
NODE_ENV=production
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Database path inside container
AWESOME_DB_PATH=/app/awesome.db
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Database volume (production)
AWESOME_DB_VOLUME=/var/lib/awesome/data
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Webhook secret for updates
AWESOME_WEBHOOK_SECRET=your-secret-here
# GitHub token (for higher API rate limits)
AWESOME_GITHUB_TOKEN=ghp_your_token_here
# Timezone
TIMEZONE=UTC
```
### Traefik Variables (Production)
```env
# Enable Traefik integration
AWESOME_TRAEFIK_ENABLED=true
# Your domain
AWESOME_TRAEFIK_HOST=awesome.example.com
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
---
## 🌐 Production Deployment
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
### Prerequisites
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
1. **Docker & Docker Compose** installed
2. **Traefik** reverse proxy running (with `compose_network`)
3. **Domain** pointed to your server
4. **Environment variables** configured
### Step 1: Prepare Environment
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Create production environment file
cp .env.example .env.production
# Edit production settings
nano .env.production
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
Required production settings:
```env
AWESOME_COMPOSE_PROJECT_NAME=awesome
AWESOME_IMAGE=ghcr.io/valknarness/awesome-app:latest
AWESOME_TRAEFIK_ENABLED=true
AWESOME_TRAEFIK_HOST=awesome.yourdomain.com
AWESOME_WEBHOOK_SECRET=generate-random-secret-here
AWESOME_DB_VOLUME=/var/lib/awesome/data
NODE_ENV=production
```
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
### Step 2: Create Data Directory
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
```bash
# Create directory for database
sudo mkdir -p /var/lib/awesome/data
sudo chown -R 1001:1001 /var/lib/awesome/data
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### Step 3: Deploy
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
```bash
# Pull latest image
docker compose -f compose.production.yml pull
# Start services
docker compose -f compose.production.yml up -d
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Check logs
docker compose -f compose.production.yml logs -f
```
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
### Step 4: Verify Deployment
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
```bash
# Check container status
docker compose -f compose.production.yml ps
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Check health
curl https://awesome.yourdomain.com/api/stats
```
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
---
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
## 💾 Database Management
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
### Using Pre-built Database
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
The easiest way is to use a pre-built database from GitHub Actions:
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Download database using GitHub CLI
gh run download --repo valknarness/awesome-app -n awesome-database
# Extract and place in data directory
sudo cp awesome.db /var/lib/awesome/data/
sudo chown 1001:1001 /var/lib/awesome/data/awesome.db
```
### Mounting External Database
You can mount a pre-existing database:
```yaml
# In compose.yml or compose.production.yml
volumes:
- /path/to/your/awesome.db:/app/awesome.db:ro
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### Database Updates
The app can receive webhook notifications for database updates:
1. Set `AWESOME_WEBHOOK_SECRET` in environment
2. Configure GitHub Actions webhook to POST to `https://your-domain.com/api/webhook`
3. The app will invalidate cache and notify clients
---
## 🔒 Traefik Integration
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
### Network Setup
Ensure Traefik's `compose_network` exists:
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
docker network create compose_network
```
### Traefik Configuration
The production compose file includes labels for:
- **HTTP to HTTPS redirect**
- **TLS/SSL certificates** (via Let's Encrypt)
- **Compression** middleware
- **Load balancing** configuration
Example Traefik labels:
```yaml
labels:
- 'traefik.enable=true'
- 'traefik.http.routers.awesome-web-secure.rule=Host(`awesome.example.com`)'
- 'traefik.http.routers.awesome-web-secure.tls.certresolver=resolver'
- 'traefik.http.routers.awesome-web-secure.entrypoints=web-secure'
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### SSL Certificates
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
Traefik automatically handles SSL certificates using Let's Encrypt when properly configured.
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
---
## 🛠️ Troubleshooting
### Container Won't Start
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Check logs
docker compose logs awesome-app
# Check container status
docker compose ps
# Restart container
docker compose restart awesome-app
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### Database Not Found
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Check if database exists
docker compose exec awesome-app ls -la /app/
# Check volume mounts
docker compose exec awesome-app df -h
# Verify permissions
docker compose exec awesome-app ls -la /app/data/
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### Traefik Not Routing
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Check Traefik logs
docker logs traefik
# Verify network
docker network inspect compose_network
# Check labels
docker inspect awesome_app | grep traefik
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### Performance Issues
```bash
# Check resource usage
docker stats awesome_app
# Check database size
docker compose exec awesome-app du -h /app/awesome.db
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Restart with fresh container
docker compose down
docker compose up -d
```
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
### Port Already in Use
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Change port in .env
AWESOME_PORT=3001
# Restart
docker compose up -d
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
---
## 🔄 Updates & Maintenance
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
### Update to Latest Version
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Pull latest image
docker compose pull
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Recreate container
docker compose up -d
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Or for production
docker compose -f compose.production.yml pull
docker compose -f compose.production.yml up -d
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### Backup Database
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
```bash
# Copy database from container
docker compose cp awesome-app:/app/awesome.db ./backup-awesome.db
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
# Or from volume
sudo cp /var/lib/awesome/data/awesome.db ~/backup-awesome-$(date +%Y%m%d).db
```
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
### View Logs
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Follow logs
docker compose logs -f awesome-app
# Last 100 lines
docker compose logs --tail=100 awesome-app
# Since specific time
docker compose logs --since 1h awesome-app
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
---
## 📊 Health Checks
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
The container includes health checks that ping `/api/stats`:
```yaml
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/api/stats"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
```
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
Check health status:
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
docker compose ps
# Should show "healthy" status
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
---
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
## 🎯 Best Practices
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
1. **Always use .env files** for configuration (never commit secrets)
2. **Use named volumes** for data persistence
3. **Monitor logs** regularly for errors
4. **Backup database** before major updates
5. **Use health checks** to ensure availability
6. **Keep images updated** for security patches
7. **Use Traefik** for SSL/TLS in production
8. **Set proper timezone** for accurate timestamps
---
## 🚀 Advanced Configuration
### Custom Build
Build from source instead of using pre-built image:
```yaml
# In compose.yml
services:
awesome-app:
build:
context: .
dockerfile: Dockerfile
args:
INCLUDE_DATABASE: false
NODE_ENV: production
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### Multiple Instances
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
Run multiple instances with different databases:
2025-10-26 02:05:34 +02:00
```bash
2025-10-26 22:53:16 +01:00
# Instance 1
AWESOME_COMPOSE_PROJECT_NAME=awesome1 \
AWESOME_PORT=3001 \
docker compose up -d
# Instance 2
AWESOME_COMPOSE_PROJECT_NAME=awesome2 \
AWESOME_PORT=3002 \
docker compose up -d
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
### Resource Limits
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
Add resource constraints:
```yaml
services:
awesome-app:
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '1'
memory: 1G
2025-10-26 02:05:34 +02:00
```
2025-10-26 22:53:16 +01:00
---
## 📚 Additional Resources
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
- [Docker Documentation](https://docs.docker.com/)
- [Docker Compose Documentation](https://docs.docker.com/compose/)
- [Traefik Documentation](https://doc.traefik.io/traefik/)
- [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry)
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
---
2025-10-26 02:05:34 +02:00
2025-10-26 22:53:16 +01:00
**Built with 💜💗💛 and maximum awesomeness!**