etsy-finance-tracker/DOCKER_DEPLOYMENT.md
dlawler489 b2da6c69ed Add Nginx reverse proxy for production deployment
Architecture Updates:
- Nginx serves static React files for optimal performance
- Nginx proxies API requests to Node.js backend (port 8080)
- Separation of concerns: static files vs API handling
- Professional production setup with proper caching

Features Added:
- nginx.conf with optimized configuration:
  - Static file serving with long-term caching
  - API reverse proxy with rate limiting
  - Security headers and GZIP compression
  - Health check proxying and SPA routing support
- Updated docker-compose.yml for multi-container setup
- build-deploy.sh script for automated deployment
- Updated environment configuration for container networking

Security & Performance:
- Rate limiting on API and auth endpoints
- Security headers (XSS, CSRF, clickjacking protection)
- GZIP compression for static assets
- Proper cache control headers
- Container-to-container communication

Deployment:
- Single command deployment with ./build-deploy.sh
- Nginx on port 80 (exposed as 3000) serving React app
- API server on internal port 8080 (not exposed)
- Persistent data volume mounting for business files
2026-04-21 06:30:44 +10:00

180 lines
No EOL
4 KiB
Markdown

# Docker Deployment Guide for Mac Mini
This guide will help you deploy the Etsy Finance Tracker on your Mac Mini using Docker with Nginx.
## Architecture
The application uses a multi-container setup:
- **Nginx**: Serves static React files and proxies API requests
- **Node.js API**: Handles backend logic and API endpoints
- **Persistent Data**: Your business data mounted as volumes
## Prerequisites
1. **Install Docker Desktop** on your Mac Mini:
```bash
# Option 1: Download from Docker website
# Go to https://docs.docker.com/desktop/mac/install/
# Option 2: Install with Homebrew (if available)
brew install --cask docker
```
2. **Install Git** (if not already installed):
```bash
brew install git
```
## Deployment Steps
### 1. Clone the Repository
```bash
git clone https://github.com/dlawler489/etsy-finance-tracker.git
cd etsy-finance-tracker
```
### 2. Prepare Your Data
```bash
# Create the data directory structure
mkdir -p data/{csv,pdf,spreadsheets}
# Copy your business files to the data directory
# Example:
# cp ~/Documents/BusinessData/*.csv data/csv/
# cp ~/Documents/BusinessData/*.pdf data/pdf/
# cp ~/Documents/BusinessData/*.xlsx data/spreadsheets/
```
### 3. Build and Deploy
```bash
# Option 1: Use the automated build script (recommended)
./build-deploy.sh
# Option 2: Manual deployment
cd client && npm install && npm run build && cd ..
docker-compose up --build -d
```
### 4. Access Your Application
- **Web Interface**: http://localhost:3000
- **API Health Check**: http://localhost:3000/health
- **Direct API**: http://localhost:3000/api/ (proxied through nginx)
## Management Commands
### Start/Stop the Application
```bash
# Start
docker-compose up -d
# Stop
docker-compose down
# Restart
docker-compose restart
```
### View Logs
```bash
# All services
docker-compose logs -f
# Specific service
docker-compose logs -f etsy-tracker
```
### Update the Application
```bash
# Pull latest code
git pull origin main
# Rebuild and restart
docker-compose down
docker-compose up --build -d
```
### Backup Your Data
```bash
# Your business data in the data/ directory is automatically persisted
# To backup:
tar -czf etsy-tracker-backup-$(date +%Y%m%d).tar.gz data/
```
## Troubleshooting
### Check Application Health
```bash
# Test the health endpoint
curl http://localhost:3000/health
# Check container logs
docker-compose logs etsy-tracker
```
### Common Issues
1. **Port Already in Use**:
```bash
# Change port in docker-compose.yml
ports:
- "3001:3000" # Change 3000 to 3001
```
2. **Permission Issues**:
```bash
# Fix data directory permissions
sudo chown -R $(whoami):$(whoami) data/
```
3. **Memory Issues**:
```bash
# Add memory limits to docker-compose.yml
deploy:
resources:
limits:
memory: 512M
```
## File Structure
Your deployment will look like this:
```
etsy-finance-tracker/
├── data/ # Your business data (persistent)
│ ├── csv/ # CSV files
│ ├── pdf/ # PDF documents
│ └── spreadsheets/ # Excel files
├── docker-compose.yml # Container orchestration
├── Dockerfile # Container configuration
└── ... (application code)
```
## Security Notes
- The `data/` directory contains your sensitive business files
- This directory is mounted as a volume and persists between container restarts
- Never commit the `data/` directory to git
- Change default passwords in `.env` file for production use
## Performance Optimization
For better performance on Mac Mini:
1. **Allocate more resources to Docker Desktop**:
- Open Docker Desktop preferences
- Go to Resources → Advanced
- Increase Memory to at least 4GB
- Increase CPU to at least 2 cores
2. **Enable BuildKit** for faster builds:
```bash
export DOCKER_BUILDKIT=1
```
## Support
If you encounter issues:
1. Check the logs: `docker-compose logs`
2. Verify Docker is running: `docker version`
3. Check port availability: `lsof -i :3000`
4. Review the troubleshooting section above