mirror of
https://github.com/TheBeastLT/torrentio-scraper.git
synced 2026-05-19 03:31:42 +00:00
Merge pull request #1 from fosterdill/feat/dev-setup
feat: add easy dev setup - docker-compose + just
This commit is contained in:
commit
f0fed3f0c3
7 changed files with 253 additions and 2 deletions
|
|
@ -1,3 +1,10 @@
|
||||||
**/node_modules
|
**/node_modules
|
||||||
**/npm-debug.log
|
**/npm-debug.log
|
||||||
**/.env
|
**/.env
|
||||||
|
**/.env.local
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
README.md
|
||||||
|
docker-compose.yml
|
||||||
|
justfile
|
||||||
|
Dockerfile.dev
|
||||||
17
addon/.env.example
Normal file
17
addon/.env.example
Normal file
|
|
@ -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
|
||||||
21
addon/Dockerfile.dev
Normal file
21
addon/Dockerfile.dev
Normal file
|
|
@ -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" ]
|
||||||
67
addon/README.dev.md
Normal file
67
addon/README.dev.md
Normal file
|
|
@ -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 <repository-url>
|
||||||
|
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
|
||||||
55
addon/docker-compose.yml
Normal file
55
addon/docker-compose.yml
Normal file
|
|
@ -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:
|
||||||
83
addon/justfile
Normal file
83
addon/justfile
Normal file
|
|
@ -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}}
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
"exports": "./index.js",
|
"exports": "./index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js"
|
"start": "node index.js",
|
||||||
|
"dev": "node --insecure-http-parser --watch index.js"
|
||||||
},
|
},
|
||||||
"author": "TheBeastLT <pauliox@beyond.lt>",
|
"author": "TheBeastLT <pauliox@beyond.lt>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue