Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Dependencies
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# Next.js
.next
out
build

# Testing
coverage
.nyc_output

# Environment files
.env*
!.env.example

# Database files (will be mounted as volume)
data/*.db
data/*.db-journal
data/*.db-wal

# User configuration (will be mounted as volume)
config.user*
config.json

# Git
.git
.gitignore
.github

# IDE
.vscode
.idea
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Documentation
*.md
!README.md
docs

# Docker
Dockerfile*
docker-compose*
.dockerignore

# Tests
tests
*.test.ts
*.test.js
jest.config.js

# Misc
.vercel
.claude
*.log
*.tsbuildinfo
50 changes: 50 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Docker Build and Test

on:
push:
branches: [ main, dev, feature/docker-setup-v2 ]
pull_request:
branches: [ main, dev ]

jobs:
docker-build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: aster-lick-hunter:test
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Test Docker image
run: |
docker run --rm -d --name test-container \
-e NEXTAUTH_SECRET=test-secret \
-e NEXT_PUBLIC_WS_HOST=localhost \
aster-lick-hunter:test

# Wait for container to start
sleep 10

# Check if container is running
docker ps | grep test-container

# Check health endpoint
docker exec test-container curl -f http://localhost:3000/api/health || exit 1

# Stop container
docker stop test-container

- name: Check Docker Compose
run: |
docker-compose config
276 changes: 276 additions & 0 deletions DOCKER_SETUP_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
# Docker Setup Summary

## πŸŽ‰ Complete Docker Implementation

This document summarizes the comprehensive Docker setup that has been implemented for the Aster Lick Hunter Node project.

## πŸ“¦ Files Created

### Core Docker Files

1. **Dockerfile**
- Multi-stage build for optimal image size
- Base stage: Node.js 20 Alpine
- Deps stage: Install dependencies
- Builder stage: Build Next.js application
- Runner stage: Production runtime with non-root user
- Includes health checks and proper permissions

2. **docker-compose.yml**
- Production-ready compose configuration
- Port mappings for dashboard (3000) and WebSocket (8080)
- Volume mounts for data persistence
- Environment variable configuration
- Health checks and logging configuration

3. **docker-compose.dev.yml**
- Development mode configuration
- Hot reload support with volume mounts
- Development environment variables

4. **.dockerignore**
- Optimized build context
- Excludes node_modules, .next, tests, docs, etc.
- Reduces image size and build time

### Scripts and Automation

5. **docker-entrypoint.sh**
- Container initialization script
- Creates necessary directories
- Sets up .env.local if missing
- Handles first-time setup
- Executable permissions set

6. **docker-start.sh**
- Interactive setup script for users
- Menu-driven interface
- Options for build, start, stop, logs, rebuild
- Checks for Docker installation
- Executable permissions set

7. **Makefile**
- Convenient command shortcuts
- Commands: build, up, down, logs, shell, backup, restore, health
- Production and development modes
- Resource monitoring
- Update automation

### Documentation

8. **docs/DOCKER.md**
- Comprehensive Docker deployment guide
- Quick start instructions
- Configuration options
- Production deployment best practices
- Security recommendations
- Troubleshooting guide
- Backup and restore procedures
- Advanced configurations

9. **.env.example**
- Template for environment variables
- NEXTAUTH_SECRET
- NEXT_PUBLIC_WS_HOST
- Port configurations

### API Endpoints

10. **src/app/api/health/route.ts**
- Health check endpoint at /api/health
- Returns status, timestamp, uptime, environment
- Used by Docker health checks

### CI/CD

11. **.github/workflows/docker-build.yml**
- GitHub Actions workflow
- Automated Docker builds on push/PR
- Tests Docker image functionality
- Validates docker-compose configuration

### Documentation Updates

12. **README.md** (Updated)
- Added Docker as recommended installation method
- Docker prerequisites section
- Docker installation instructions
- Docker commands reference
- Links to detailed Docker documentation

## πŸš€ Quick Start Commands

### Using Makefile (Recommended)
```bash
make build # Build Docker image
make up # Start containers
make logs # View logs
make down # Stop containers
make backup # Backup database
make health # Check health
```

### Using Docker Compose
```bash
docker-compose build # Build image
docker-compose up -d # Start detached
docker-compose logs -f # Follow logs
docker-compose down # Stop containers
docker-compose ps # Check status
```

### Using Interactive Script
```bash
./docker-start.sh # Interactive menu
```

## πŸ”§ Configuration

### Environment Variables
- `NEXTAUTH_SECRET`: Session encryption secret (required)
- `NEXT_PUBLIC_WS_HOST`: WebSocket host (default: localhost)
- `DASHBOARD_PORT`: Dashboard port (default: 3000)
- `WEBSOCKET_PORT`: WebSocket port (default: 8080)

### Volume Mounts
- `./data:/app/data` - Database and application data
- `./config.user.json:/app/config.user.json` - User configuration
- `./.env.local:/app/.env.local` - Environment variables

### Ports
- **3000**: Web dashboard
- **8080**: WebSocket server

## πŸ—οΈ Architecture

### Multi-Stage Build
1. **base**: Node.js 20 Alpine base image
2. **deps**: Install all dependencies
3. **builder**: Build Next.js application
4. **runner**: Minimal production runtime

### Security Features
- Non-root user (nextjs:nodejs, UID/GID 1001)
- Read-only config mounts
- Isolated network
- Health checks
- Resource limits (configurable)

### Data Persistence
- Database files in `./data` directory
- Survives container restarts
- Easy backup and restore

## πŸ“Š Monitoring

### Health Checks
- Built-in Docker health check
- HTTP endpoint: `http://localhost:3000/api/health`
- Interval: 30s, Timeout: 10s, Retries: 3

### Logging
- JSON file driver
- Max size: 10MB
- Max files: 3
- Accessible via `docker-compose logs`

## πŸ”’ Production Ready

### Security Best Practices
- βœ… Non-root user
- βœ… Environment variable secrets
- βœ… Read-only mounts
- βœ… Network isolation
- βœ… Health monitoring
- βœ… Resource limits

### Deployment Features
- βœ… Automatic restarts
- βœ… Data persistence
- βœ… Easy backups
- βœ… Rolling updates
- βœ… Log rotation
- βœ… Health checks

## πŸ§ͺ Testing

### GitHub Actions
- Automated builds on push/PR
- Docker image testing
- Health check validation
- Compose configuration validation

### Manual Testing
```bash
# Build and test
make build
make up
make health

# Check logs
make logs

# Access shell
make shell
```

## πŸ“ˆ Benefits

### For Users
- **Easier Setup**: No Node.js installation required
- **Isolated Environment**: No conflicts with system
- **Consistent**: Same environment everywhere
- **Portable**: Run anywhere Docker runs
- **Safe**: Easy rollback and recovery

### For Developers
- **Reproducible**: Same environment for all
- **Fast Deployment**: One command to deploy
- **Easy Testing**: Spin up/down quickly
- **CI/CD Ready**: Automated builds and tests
- **Scalable**: Easy to add more services

## 🎯 Next Steps

### For Users
1. Install Docker Desktop
2. Clone repository
3. Run `./docker-start.sh`
4. Configure via web UI
5. Start trading!

### For Developers
1. Use `docker-compose.dev.yml` for development
2. Hot reload enabled
3. Debug with `make shell`
4. Test with `make health`
5. Deploy with `make prod`

## πŸ“š Documentation

- **Quick Start**: README.md
- **Detailed Guide**: docs/DOCKER.md
- **Commands**: `make help`
- **Interactive**: `./docker-start.sh`

## πŸŽ‰ Summary

The Docker implementation provides:
- βœ… Production-ready containerization
- βœ… Development environment support
- βœ… Comprehensive documentation
- βœ… Easy-to-use commands
- βœ… Automated testing
- βœ… Security best practices
- βœ… Data persistence
- βœ… Health monitoring
- βœ… Backup/restore tools
- βœ… CI/CD integration

All files have been committed and pushed to the `feature/docker-setup-v2` branch.

---

**Branch**: `feature/docker-setup-v2`
**Commit**: Added comprehensive Docker support with multi-stage builds
**Status**: βœ… Ready for testing and merge
Loading
Loading