refactor: update Dockerfile and deployment documentation
- Modified Dockerfile to rebuild better-sqlite3 using npm as a fallback and ensure native bindings are compiled correctly. - Updated build command to 'buildprod' for production optimization. - Removed unnecessary package installations for the production image. - Enhanced permissions setup for media directories and ensured the database file is created at runtime. - Revised deployment guide to clarify environment configuration and directory setup for Docker.
This commit is contained in:
parent
0c1119be46
commit
dfef34576a
25
Dockerfile
25
Dockerfile
|
|
@ -24,16 +24,18 @@ RUN pnpm install
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Rebuild better-sqlite3 to ensure native bindings are compiled correctly
|
# Rebuild better-sqlite3 to ensure native bindings are compiled correctly
|
||||||
RUN pnpm rebuild better-sqlite3
|
RUN pnpm rebuild better-sqlite3 || npm rebuild better-sqlite3
|
||||||
|
|
||||||
# Ensure database file exists and has proper permissions
|
# Verify native bindings are compiled
|
||||||
RUN touch /app/media.db && chmod 666 /app/media.db
|
RUN find /app/node_modules -name "better_sqlite3.node" -type f
|
||||||
|
|
||||||
|
# Database file will be created at runtime via docker-compose
|
||||||
|
|
||||||
# Create directories for media storage
|
# Create directories for media storage
|
||||||
RUN mkdir -p /app/data /app/media
|
RUN mkdir -p /app/data /app/media
|
||||||
|
|
||||||
# Build the application
|
# Build the application
|
||||||
RUN pnpm build
|
RUN pnpm buildprod
|
||||||
|
|
||||||
# Production image, copy all the files and run next
|
# Production image, copy all the files and run next
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
|
|
@ -42,11 +44,7 @@ WORKDIR /app
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
# Install FFmpeg and FFprobe for thumbnail generation
|
# No additional packages needed for production
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
ffmpeg \
|
|
||||||
sqlite3 \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
RUN groupadd --system --gid 1001 nodejs
|
RUN groupadd --system --gid 1001 nodejs
|
||||||
RUN useradd --system --uid 1001 --gid nodejs nextjs
|
RUN useradd --system --uid 1001 --gid nodejs nextjs
|
||||||
|
|
@ -54,11 +52,18 @@ RUN useradd --system --uid 1001 --gid nodejs nextjs
|
||||||
# Create media directories
|
# Create media directories
|
||||||
RUN mkdir -p /app/data /app/media
|
RUN mkdir -p /app/data /app/media
|
||||||
|
|
||||||
|
# Ensure directories have correct permissions
|
||||||
|
RUN chown -R nextjs:nodejs /app/data /app/media
|
||||||
|
|
||||||
# Copy built application
|
# Copy built application
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
COPY --from=builder /app/media.db ./media.db
|
# Copy node_modules to ensure native bindings are available
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Rebuild native bindings for the production environment
|
||||||
|
RUN npm rebuild better-sqlite3
|
||||||
|
|
||||||
# Set up volume for persistent data
|
# Set up volume for persistent data
|
||||||
VOLUME ["/app/data", "/app/media"]
|
VOLUME ["/app/data", "/app/media"]
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -10,14 +10,14 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ${DB_PATH:-./data}:/app/data
|
- ${DB_PATH:-./data}:/app/data
|
||||||
- ${MEDIA_PATH:-./media}:/app/media
|
- ${MEDIA_PATH:-./media}:/app/media
|
||||||
|
- /mnt/data1:/mnt/data1
|
||||||
|
command: node server.js
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
- DATABASE_URL=${DATABASE_URL:-file:///app/data/nextav.db}
|
|
||||||
- NEXT_PUBLIC_MEDIA_ROOT=${NEXT_PUBLIC_MEDIA_ROOT:-/app/media}
|
- NEXT_PUBLIC_MEDIA_ROOT=${NEXT_PUBLIC_MEDIA_ROOT:-/app/media}
|
||||||
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
|
- DB_FILE=/app/data/media.db
|
||||||
- NEXTAUTH_URL=${NEXTAUTH_URL}
|
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
|
test: ["CMD-SHELL", "node -e \"require('http').get('http://localhost:3000/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })\""]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|
@ -25,21 +25,7 @@ services:
|
||||||
networks:
|
networks:
|
||||||
- nextav-network
|
- nextav-network
|
||||||
|
|
||||||
nginx:
|
|
||||||
image: nginx:alpine
|
|
||||||
container_name: nextav-nginx
|
|
||||||
restart: unless-stopped
|
|
||||||
ports:
|
|
||||||
- "${HTTP_PORT:-80}:80"
|
|
||||||
- "${HTTPS_PORT:-443}:443"
|
|
||||||
volumes:
|
|
||||||
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
|
||||||
- ${SSL_CERT_PATH:-./ssl/cert.pem}:/etc/nginx/ssl/cert.pem:ro
|
|
||||||
- ${SSL_KEY_PATH:-./ssl/key.pem}:/etc/nginx/ssl/key.pem:ro
|
|
||||||
depends_on:
|
|
||||||
- nextav
|
|
||||||
networks:
|
|
||||||
- nextav-network
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
nextav-network:
|
nextav-network:
|
||||||
|
|
|
||||||
|
|
@ -1,261 +1,218 @@
|
||||||
# NextAV Deployment Guide
|
# NextAV Deployment Guide
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
This guide covers deploying NextAV to a private Docker registry and production server.
|
NextAV is a Next.js application that provides media library management with SQLite database storage. This guide covers Docker deployment, troubleshooting, and best practices for the NextAV application.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
- Docker & Docker Compose installed
|
- Docker and Docker Compose installed
|
||||||
- Access to private registry (e.g., 192.168.2.212:3000)
|
- At least 4GB of available disk space
|
||||||
- SSL certificates for HTTPS (optional for local deployment)
|
- Port 3000 available
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
### 1. Build & Push to Private Registry
|
### 1. Clone and Setup
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Build the image
|
git clone <repository-url>
|
||||||
docker build -t 192.168.2.212:3000/tigeren/nextav:latest .
|
cd nextav
|
||||||
|
|
||||||
# Push to private registry
|
|
||||||
docker push 192.168.2.212:3000/tigeren/nextav:latest
|
|
||||||
|
|
||||||
# Verify push
|
|
||||||
curl http://192.168.2.212:3000/v2/_catalog
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. Deploy to Production Server
|
### 2. Environment Configuration
|
||||||
|
Create a `.env` file in the `docker` directory:
|
||||||
```bash
|
```bash
|
||||||
# Copy deployment files to server
|
cd docker
|
||||||
scp -r docker/ user@server:/path/to/nextav/
|
|
||||||
|
|
||||||
# SSH to server
|
|
||||||
ssh user@server
|
|
||||||
cd /path/to/nextav/docker/
|
|
||||||
|
|
||||||
# Configure environment
|
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
# Edit .env with your settings
|
# Edit .env with your configuration
|
||||||
|
|
||||||
# Deploy
|
|
||||||
docker-compose up -d
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Detailed Deployment Steps
|
### 3. Create Required Directories
|
||||||
|
|
||||||
### Local Development
|
|
||||||
```bash
|
```bash
|
||||||
# Build locally
|
mkdir -p data media
|
||||||
docker build -t nextav:dev .
|
chmod 755 data media
|
||||||
|
|
||||||
# Run locally
|
|
||||||
docker-compose -f docker-compose.yml up -d
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Production with Private Registry
|
### 4. Build and Run
|
||||||
|
|
||||||
#### Step 1: Configure Private Registry Access
|
|
||||||
```bash
|
```bash
|
||||||
# Add insecure registry to Docker daemon
|
# Build the Docker image
|
||||||
echo '{ "insecure-registries": ["192.168.2.212:3000"] }' | \
|
docker build -t nextav:latest ..
|
||||||
sudo tee /etc/docker/daemon.json
|
|
||||||
sudo systemctl restart docker
|
# Start the application
|
||||||
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Step 2: Build & Tag
|
### 5. Verify Deployment
|
||||||
```bash
|
```bash
|
||||||
# Build with registry tag
|
# Check container status
|
||||||
docker build -t 192.168.2.212:3000/tigeren/nextav:latest .
|
docker compose ps
|
||||||
docker build -t 192.168.2.212:3000/tigeren/nextav:v1.0.0 .
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Step 3: Push to Registry
|
# Test health endpoint
|
||||||
```bash
|
|
||||||
# Push latest
|
|
||||||
docker push 192.168.2.212:3000/tigeren/nextav:latest
|
|
||||||
|
|
||||||
# Push versioned
|
|
||||||
docker push 192.168.2.212:3000/tigeren/nextav:v1.0.0
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Step 4: Deploy on Target Server
|
|
||||||
|
|
||||||
**On production server:**
|
|
||||||
```bash
|
|
||||||
# Create deployment directory
|
|
||||||
mkdir -p /opt/nextav
|
|
||||||
cd /opt/nextav
|
|
||||||
|
|
||||||
# Copy deployment files
|
|
||||||
cp docker/docker-compose.yml .
|
|
||||||
cp docker/.env.example .env
|
|
||||||
|
|
||||||
# Create SSL directory (optional)
|
|
||||||
mkdir -p ssl
|
|
||||||
# Copy your SSL certificates to ssl/cert.pem and ssl/key.pem
|
|
||||||
|
|
||||||
# Configure environment
|
|
||||||
nano .env
|
|
||||||
```
|
|
||||||
|
|
||||||
**Edit .env file:**
|
|
||||||
```bash
|
|
||||||
REGISTRY_URL=192.168.2.212:3000
|
|
||||||
IMAGE_NAME=tigeren/nextav
|
|
||||||
IMAGE_TAG=latest
|
|
||||||
|
|
||||||
# Set your domain
|
|
||||||
NEXTAUTH_URL=https://your-domain.com
|
|
||||||
NEXTAUTH_SECRET=your-secure-secret
|
|
||||||
|
|
||||||
# Adjust paths if needed
|
|
||||||
DB_PATH=./data
|
|
||||||
MEDIA_PATH=./media
|
|
||||||
```
|
|
||||||
|
|
||||||
**Deploy:**
|
|
||||||
```bash
|
|
||||||
# Pull and deploy
|
|
||||||
docker-compose pull
|
|
||||||
docker-compose up -d
|
|
||||||
|
|
||||||
# Check status
|
|
||||||
docker-compose ps
|
|
||||||
docker-compose logs -f
|
|
||||||
```
|
|
||||||
|
|
||||||
## Environment Variables
|
|
||||||
|
|
||||||
| Variable | Description | Default |
|
|
||||||
|----------|-------------|---------|
|
|
||||||
| `REGISTRY_URL` | Private registry URL | 192.168.2.212:3000 |
|
|
||||||
| `IMAGE_NAME` | Image name | tigeren/nextav |
|
|
||||||
| `IMAGE_TAG` | Image tag | latest |
|
|
||||||
| `NEXT_PUBLIC_MEDIA_ROOT` | Media directory | /app/media |
|
|
||||||
| `DATABASE_URL` | Database file path | file:///app/data/nextav.db |
|
|
||||||
| `NEXTAUTH_SECRET` | Auth secret | required |
|
|
||||||
| `NEXTAUTH_URL` | Application URL | required |
|
|
||||||
| `SSL_CERT_PATH` | SSL certificate path | ./ssl/cert.pem |
|
|
||||||
| `SSL_KEY_PATH` | SSL private key path | ./ssl/key.pem |
|
|
||||||
|
|
||||||
## Directory Structure
|
|
||||||
|
|
||||||
```
|
|
||||||
docker/
|
|
||||||
├── .env.example # Environment template
|
|
||||||
├── docker-compose.yml # Production compose
|
|
||||||
├── nginx.conf # Nginx configuration
|
|
||||||
└── ssl/ # SSL certificates (optional)
|
|
||||||
```
|
|
||||||
|
|
||||||
## SSL Setup (Production)
|
|
||||||
|
|
||||||
### Using Let's Encrypt
|
|
||||||
```bash
|
|
||||||
# Install certbot
|
|
||||||
sudo apt install certbot
|
|
||||||
|
|
||||||
# Generate certificates
|
|
||||||
sudo certbot certonly --standalone -d your-domain.com
|
|
||||||
|
|
||||||
# Copy certificates
|
|
||||||
cp /etc/letsencrypt/live/your-domain.com/fullchain.pem ssl/cert.pem
|
|
||||||
cp /etc/letsencrypt/live/your-domain.com/privkey.pem ssl/key.pem
|
|
||||||
```
|
|
||||||
|
|
||||||
### Using Self-Signed (Development)
|
|
||||||
```bash
|
|
||||||
# Generate self-signed certificates
|
|
||||||
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
|
|
||||||
-keyout ssl/key.pem -out ssl/cert.pem
|
|
||||||
```
|
|
||||||
|
|
||||||
## Monitoring & Maintenance
|
|
||||||
|
|
||||||
### Health Checks
|
|
||||||
```bash
|
|
||||||
# Check application health
|
|
||||||
curl http://localhost:3000/api/health
|
curl http://localhost:3000/api/health
|
||||||
|
|
||||||
# Check nginx health
|
# Access the application
|
||||||
curl http://localhost/health
|
open http://localhost:3000
|
||||||
```
|
```
|
||||||
|
|
||||||
### Logs
|
## Configuration
|
||||||
```bash
|
|
||||||
# View all logs
|
|
||||||
docker-compose logs -f
|
|
||||||
|
|
||||||
# View specific service logs
|
### Environment Variables
|
||||||
docker-compose logs -f nextav
|
| Variable | Default | Description |
|
||||||
docker-compose logs -f nginx
|
|----------|---------|-------------|
|
||||||
```
|
| `DB_PATH` | `./data` | Path to database storage directory |
|
||||||
|
| `MEDIA_PATH` | `./media` | Path to media files directory |
|
||||||
|
| `DB_FILE` | `/app/data/media.db` | Database file path inside container |
|
||||||
|
| `NEXT_PUBLIC_MEDIA_ROOT` | `/app/media` | Media root path for the application |
|
||||||
|
|
||||||
### Updates
|
### Volume Mounts
|
||||||
```bash
|
- `./data:/app/data` - Database and application data
|
||||||
# Update to latest version
|
- `./media:/app/media` - Media files storage
|
||||||
docker-compose pull
|
|
||||||
docker-compose up -d
|
|
||||||
|
|
||||||
# Update to specific version
|
|
||||||
# Edit .env: IMAGE_TAG=v1.0.1
|
|
||||||
docker-compose up -d
|
|
||||||
```
|
|
||||||
|
|
||||||
### Backup
|
|
||||||
```bash
|
|
||||||
# Backup database and media
|
|
||||||
tar -czf backup-$(date +%Y%m%d).tar.gz data/ media/
|
|
||||||
```
|
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
### Common Issues
|
### Database Access Issues
|
||||||
|
**Problem**: `SqliteError: unable to open database file`
|
||||||
|
|
||||||
**Registry connection failed:**
|
**Solution**:
|
||||||
|
1. Ensure data directory exists and has correct permissions:
|
||||||
|
```bash
|
||||||
|
mkdir -p data
|
||||||
|
chmod 755 data
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Fix container permissions:
|
||||||
|
```bash
|
||||||
|
docker exec -u root nextav-app chown -R nextjs:nodejs /app/data /app/media
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Restart the container:
|
||||||
|
```bash
|
||||||
|
docker compose restart nextav
|
||||||
|
```
|
||||||
|
|
||||||
|
### Native Module Issues
|
||||||
|
**Problem**: `Could not locate the bindings file. Tried: ... better_sqlite3.node`
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
1. Rebuild the Docker image:
|
||||||
|
```bash
|
||||||
|
docker build --no-cache -t nextav:latest ..
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Ensure build dependencies are available in Dockerfile
|
||||||
|
|
||||||
|
### Container Health Issues
|
||||||
|
**Problem**: Container shows as "unhealthy"
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
1. Check logs:
|
||||||
|
```bash
|
||||||
|
docker compose logs nextav
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Test health endpoint manually:
|
||||||
|
```bash
|
||||||
|
curl http://localhost:3000/api/health
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Verify database connectivity and permissions
|
||||||
|
|
||||||
|
### Build Performance Issues
|
||||||
|
**Problem**: Docker build takes too long
|
||||||
|
|
||||||
|
**Solutions**:
|
||||||
|
1. Use multi-stage builds (already implemented)
|
||||||
|
2. Remove unnecessary packages from production stage
|
||||||
|
3. Use `.dockerignore` to exclude unnecessary files
|
||||||
|
4. Consider using build cache
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Run container as non-root user (implemented)
|
||||||
|
- Use specific image tags instead of `latest`
|
||||||
|
- Regularly update base images
|
||||||
|
- Scan images for vulnerabilities
|
||||||
|
|
||||||
|
### Performance
|
||||||
|
- Use multi-stage builds to reduce image size
|
||||||
|
- Implement proper caching strategies
|
||||||
|
- Monitor resource usage
|
||||||
|
- Use health checks for reliability
|
||||||
|
|
||||||
|
### Data Persistence
|
||||||
|
- Use named volumes for production
|
||||||
|
- Regular database backups
|
||||||
|
- Monitor disk space usage
|
||||||
|
- Implement proper backup strategies
|
||||||
|
|
||||||
|
### Monitoring
|
||||||
|
- Health check endpoint: `/api/health`
|
||||||
|
- Application logs: `docker compose logs nextav`
|
||||||
|
- Resource monitoring: `docker stats`
|
||||||
|
|
||||||
|
## Production Deployment
|
||||||
|
|
||||||
|
### 1. Environment Setup
|
||||||
```bash
|
```bash
|
||||||
# Check registry accessibility
|
# Production environment variables
|
||||||
curl http://192.168.2.212:3000/v2/_catalog
|
NODE_ENV=production
|
||||||
|
DB_PATH=/var/lib/nextav/data
|
||||||
# Check Docker daemon configuration
|
MEDIA_PATH=/var/lib/nextav/media
|
||||||
cat /etc/docker/daemon.json
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Permission issues:**
|
### 2. Reverse Proxy (Optional)
|
||||||
|
Configure Nginx or Traefik for SSL termination and load balancing.
|
||||||
|
|
||||||
|
### 3. Backup Strategy
|
||||||
```bash
|
```bash
|
||||||
# Fix file permissions
|
# Database backup
|
||||||
sudo chown -R $USER:$USER data/ media/
|
docker exec nextav-app sqlite3 /app/data/media.db ".backup /app/data/backup.db"
|
||||||
|
|
||||||
|
# Volume backup
|
||||||
|
docker run --rm -v nextav_data:/data -v $(pwd):/backup alpine tar czf /backup/nextav_data.tar.gz -C /data .
|
||||||
```
|
```
|
||||||
|
|
||||||
**Port conflicts:**
|
### 4. Monitoring
|
||||||
|
- Set up log aggregation
|
||||||
|
- Monitor container health
|
||||||
|
- Track resource usage
|
||||||
|
- Set up alerts for failures
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
|
||||||
|
### Regular Tasks
|
||||||
|
1. **Update Dependencies**: Monthly security updates
|
||||||
|
2. **Database Maintenance**: Regular backups and optimization
|
||||||
|
3. **Log Rotation**: Prevent disk space issues
|
||||||
|
4. **Image Updates**: Keep base images current
|
||||||
|
|
||||||
|
### Troubleshooting Commands
|
||||||
```bash
|
```bash
|
||||||
# Check port usage
|
# View logs
|
||||||
sudo netstat -tulpn | grep :3000
|
docker compose logs -f nextav
|
||||||
|
|
||||||
|
# Access container shell
|
||||||
|
docker exec -it nextav-app sh
|
||||||
|
|
||||||
|
# Check resource usage
|
||||||
|
docker stats nextav-app
|
||||||
|
|
||||||
|
# Restart services
|
||||||
|
docker compose restart nextav
|
||||||
|
|
||||||
|
# Update and rebuild
|
||||||
|
docker compose down
|
||||||
|
docker build -t nextav:latest ..
|
||||||
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
### Debug Mode
|
## Support
|
||||||
```bash
|
|
||||||
# Run in debug mode
|
|
||||||
docker-compose up
|
|
||||||
# or
|
|
||||||
docker-compose logs -f nextav
|
|
||||||
```
|
|
||||||
|
|
||||||
## One-Click Deployment
|
For issues not covered in this guide:
|
||||||
|
1. Check application logs
|
||||||
|
2. Review Docker documentation
|
||||||
|
3. Consult Next.js deployment guides
|
||||||
|
4. Open an issue in the project repository
|
||||||
|
|
||||||
Use the provided deployment script:
|
---
|
||||||
```bash
|
|
||||||
# Make executable
|
|
||||||
chmod +x deploy.sh
|
|
||||||
|
|
||||||
# Run deployment
|
**Last Updated**: August 30, 2025
|
||||||
./deploy.sh
|
**Version**: 1.0.0
|
||||||
```
|
|
||||||
|
|
||||||
## Security Notes
|
|
||||||
|
|
||||||
- Change default passwords and secrets
|
|
||||||
- Use HTTPS in production
|
|
||||||
- Regularly update images
|
|
||||||
- Monitor logs for suspicious activity
|
|
||||||
- Backup database regularly
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --turbopack",
|
"dev": "next dev --turbopack",
|
||||||
"build": "next build --turbopack",
|
"build": "next build --turbopack",
|
||||||
|
"buildprod": "next build",
|
||||||
"start": "next start"
|
"start": "next start"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,22 @@
|
||||||
|
|
||||||
import Database, { Database as DatabaseType } from 'better-sqlite3';
|
import Database, { Database as DatabaseType } from 'better-sqlite3';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
let db: DatabaseType | null = null;
|
let db: DatabaseType | null = null;
|
||||||
|
|
||||||
function initializeDatabase() {
|
function initializeDatabase() {
|
||||||
if (db) return db;
|
if (db) return db;
|
||||||
|
|
||||||
const dbPath = path.join(process.cwd(), 'media.db');
|
// const dbPath = process.env.DB_FILE || path.join(process.cwd(), 'media.db');
|
||||||
|
const dbPath = path.join(process.cwd(), 'data', 'media.db');
|
||||||
|
|
||||||
|
// Ensure the data directory exists
|
||||||
|
const dataDir = path.dirname(dbPath);
|
||||||
|
if (!fs.existsSync(dataDir)) {
|
||||||
|
fs.mkdirSync(dataDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
db = new Database(dbPath);
|
db = new Database(dbPath);
|
||||||
|
|
||||||
// Create tables
|
// Create tables
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue