diff --git a/addon/.dockerignore b/addon/.dockerignore index 5538a38..b643016 100644 --- a/addon/.dockerignore +++ b/addon/.dockerignore @@ -1,3 +1,10 @@ **/node_modules **/npm-debug.log -**/.env \ No newline at end of file +**/.env +**/.env.local +.git +.gitignore +README.md +docker-compose.yml +justfile +Dockerfile.dev \ No newline at end of file diff --git a/addon/.env.example b/addon/.env.example new file mode 100644 index 0000000..429a692 --- /dev/null +++ b/addon/.env.example @@ -0,0 +1,17 @@ +# Application Configuration +NODE_ENV=development +PORT=7000 + +# Database Configuration +DATABASE_URI=postgres://torrentio:torrentio@localhost:5432/torrentio +MONGODB_URI=mongodb://localhost:27017/torrentio-cache + +# Metrics Authentication +METRICS_USER=admin +METRICS_PASSWORD=admin + +# Cache Configuration +CACHE_MAX_AGE=3600 + +# Optional: Add any additional environment variables here +# that might be needed for specific features or integrations \ No newline at end of file diff --git a/addon/Dockerfile.dev b/addon/Dockerfile.dev new file mode 100644 index 0000000..ab444f0 --- /dev/null +++ b/addon/Dockerfile.dev @@ -0,0 +1,21 @@ +FROM node:21-alpine + +RUN apk update && apk upgrade && \ + apk add --no-cache git + +WORKDIR /home/node/app + +# Install dependencies +COPY package*.json ./ +RUN npm ci + +# Copy source code +COPY . . + +# Create non-root user +RUN chown -R node:node /home/node/app +USER node + +EXPOSE 7000 + +CMD [ "node", "--insecure-http-parser", "index.js" ] \ No newline at end of file diff --git a/addon/README.dev.md b/addon/README.dev.md new file mode 100644 index 0000000..a2e2f55 --- /dev/null +++ b/addon/README.dev.md @@ -0,0 +1,67 @@ +# Torrentio Addon - Local Development Setup + +## Quick Start + +1. **Prerequisites**: + - Docker and Docker Compose + - [Just](https://github.com/casey/just) command runner (optional but recommended) + +2. **Clone and setup**: + ```bash + git clone + cd torrentio-scraper/addon + cp .env.example .env # Edit .env as needed + ``` + +3. **Start development environment**: + ```bash + # With just (recommended) + just dev + + # Or with docker-compose directly + docker-compose up --build + ``` + +4. **Access the application**: + - Addon: http://localhost:7000 + - Metrics: http://localhost:7000/swagger-stats/ (admin/admin) + - PostgreSQL: localhost:5432 (torrentio/torrentio) + - MongoDB: localhost:27017 + +## Development Commands + +If you have `just` installed: + +```bash +just # List all available commands +just dev # Start development environment +just dev-detached # Start in background +just down # Stop services +just clean # Stop and remove volumes +just logs # View all logs +just logs-addon # View addon logs only +just db-connect # Connect to PostgreSQL +just mongo-connect # Connect to MongoDB +just rebuild # Rebuild and restart +``` + +Without `just`, use `docker-compose` commands directly: + +```bash +docker-compose up --build # Start development +docker-compose down # Stop services +docker-compose logs -f addon # View addon logs +docker-compose exec addon bash # Shell into addon container +``` + +## Database Access + +- **PostgreSQL**: `postgres://torrentio:torrentio@localhost:5432/torrentio` +- **MongoDB**: `mongodb://localhost:27017/torrentio-cache` + +## Development Notes + +- The addon container uses file watching for automatic restarts +- Volumes are configured to persist database data +- Environment variables are set for local development +- Both databases include health checks for reliable startup \ No newline at end of file diff --git a/addon/docker-compose.yml b/addon/docker-compose.yml new file mode 100644 index 0000000..2cc114d --- /dev/null +++ b/addon/docker-compose.yml @@ -0,0 +1,55 @@ +version: '3.8' + +services: + addon: + build: . + ports: + - "7001:7000" + environment: + - NODE_ENV=development + - PORT=7000 + - DATABASE_URI=postgres://torrentio:torrentio@postgres:5432/torrentio + - MONGODB_URI=mongodb://mongo:27017/torrentio-cache + - METRICS_USER=admin + - METRICS_PASSWORD=admin + depends_on: + postgres: + condition: service_healthy + mongo: + condition: service_healthy + volumes: + - .:/home/node/app + - /home/node/app/node_modules + command: npm run dev + + postgres: + image: postgres:15-alpine + environment: + POSTGRES_DB: torrentio + POSTGRES_USER: torrentio + POSTGRES_PASSWORD: torrentio + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U torrentio -d torrentio"] + interval: 10s + timeout: 5s + retries: 5 + + mongo: + image: mongo:7 + ports: + - "27017:27017" + volumes: + - mongo_data:/data/db + healthcheck: + test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"] + interval: 10s + timeout: 5s + retries: 5 + +volumes: + postgres_data: + mongo_data: \ No newline at end of file diff --git a/addon/justfile b/addon/justfile new file mode 100644 index 0000000..1975819 --- /dev/null +++ b/addon/justfile @@ -0,0 +1,83 @@ +# Load environment variables from .env file +set dotenv-load + +# Default recipe (list all available commands) +default: + @just --list + +# Start the development environment +dev: + docker-compose up --build + +# Start development environment in background +dev-detached: + docker-compose up --build -d + +# Stop the development environment +down: + docker-compose down + +# Stop and remove all containers, networks, and volumes +clean: + docker-compose down -v --remove-orphans + +# View logs from all services +logs: + docker-compose logs -f + +# View logs from addon service only +logs-addon: + docker-compose logs -f addon + +# View logs from postgres service only +logs-postgres: + docker-compose logs -f postgres + +# View logs from mongo service only +logs-mongo: + docker-compose logs -f mongo + +# Execute a command in the running addon container +exec command="bash": + docker-compose exec addon {{command}} + +# Install dependencies +install: + docker-compose exec addon npm install + +# Run the addon in production mode locally +start: + docker-compose exec addon npm start + +# Connect to postgres database +db-connect: + docker-compose exec postgres psql -U torrentio -d torrentio + +# Connect to mongo database +mongo-connect: + docker-compose exec mongo mongosh torrentio-cache + +# Rebuild and restart services +rebuild: + docker-compose down + docker-compose build --no-cache + docker-compose up + +# Show status of all services +status: + docker-compose ps + +# View database connection info +db-info: + @echo "PostgreSQL: postgres://torrentio:torrentio@localhost:5432/torrentio" + @echo "MongoDB: mongodb://localhost:27017/torrentio-cache" + +# Reset databases (removes all data) +db-reset: + docker-compose down -v + docker-compose up -d postgres mongo + @echo "Databases reset. Run 'just dev' to start the full stack." + +# Run a one-off command without starting the full stack +run command: + docker-compose run --rm addon {{command}} \ No newline at end of file diff --git a/addon/package.json b/addon/package.json index d075e9b..9bf363e 100644 --- a/addon/package.json +++ b/addon/package.json @@ -4,7 +4,8 @@ "exports": "./index.js", "type": "module", "scripts": { - "start": "node index.js" + "start": "node index.js", + "dev": "node --insecure-http-parser --watch index.js" }, "author": "TheBeastLT ", "license": "MIT",