13 changed files with 183 additions and 9 deletions
+4 -4
View File
@@ -1,10 +1,10 @@
API_PORT=3671 API_PORT=3671
MONGO_INITDB_ROOT_PASSWORD=pass# esegui 'openssl rand -hex 5' in un terminale e copia qui MONGO_INITDB_ROOT_PASSWORD=change-this-mongo-password
MONGODB_URI=mongodb://theplug:pass@localhost:27017/theplug?authSource=admin MONGODB_URI=mongodb://theplug:change-this-mongo-password@localhost:27017/theplug?authSource=admin
MONGODB_DB_NAME=theplug MONGODB_DB_NAME=theplug
REDIS_URL=redis://localhost:6379 REDIS_URL=redis://localhost:6379
JWT_SECRET_KEY= # esegui 'openssl rand -hex 20' in un terminale e copia qui JWT_SECRET_KEY=change-this-secret
JWT_ALGORITHM=HS256 JWT_ALGORITHM=HS256
JWT_EXPIRE_MINUTES=30 JWT_EXPIRE_MINUTES=30
AUTH_USERNAME=admin AUTH_USERNAME=admin
AUTH_PASSWORD= # esegui 'openssl rand -hex 20' in un terminale e copia qui AUTH_PASSWORD=change-this-password
+26
View File
@@ -0,0 +1,26 @@
FROM python:3.14-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app/app
WORKDIR /app
COPY pyproject.toml ./
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir \
"authlib>=1.6.0" \
"fastapi[standard]>=0.135.3" \
"motor>=3.7.1" \
"pwdlib[argon2,bcrypt]>=0.3.0" \
"pydantic>=2.12.5" \
"pydantic-settings>=2.13.1" \
"pyyaml>=6.0.3" \
"redis>=7.4.0"
COPY app ./app
EXPOSE 3671
CMD ["sh", "-c", "fastapi run /app/app/main.py --host 0.0.0.0 --port ${API_PORT:-3671}"]
View File
+14
View File
@@ -0,0 +1,14 @@
from fastapi import APIRouter, Depends, Request
from core.security import require_authenticated_user
router = APIRouter(
prefix="/services",
tags=["Services"],
dependencies=[Depends(require_authenticated_user)],
)
@router.get("")
async def get_services(request: Request):
return request.app.state.services
+2
View File
@@ -7,6 +7,7 @@ from fastapi import FastAPI
from api.auth.router import router as auth_router from api.auth.router import router as auth_router
from api.proxy.router import router as proxy_router from api.proxy.router import router as proxy_router
from api.services.router import router as services_router
from core.config import settings from core.config import settings
from core.mongodb import close_mongodb, init_mongodb from core.mongodb import close_mongodb, init_mongodb
from core.redis import close_redis, init_redis from core.redis import close_redis, init_redis
@@ -57,6 +58,7 @@ app = FastAPI(
app.include_router(auth_router) app.include_router(auth_router)
app.include_router(proxy_router) app.include_router(proxy_router)
app.include_router(services_router)
@app.get("/") @app.get("/")
+80
View File
@@ -0,0 +1,80 @@
services:
app:
build:
context: .
dockerfile: Dockerfile.test
container_name: theplug-app-test
restart: unless-stopped
env_file:
- .env
environment:
MONGODB_URI: mongodb://theplug:${MONGO_INITDB_ROOT_PASSWORD}@mongodb:27017/${MONGO_DB:-theplug}?authSource=admin
MONGODB_DB_NAME: ${MONGO_DB:-theplug}
REDIS_URL: redis://redis:6379
API_PORT: ${API_PORT:-3671}
DEBUG: "true"
depends_on:
mongodb:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "${API_PORT:-3671}:${API_PORT:-3671}"
volumes:
- ./example-http-one:/root/example-http-one:ro
- ./example-http-two:/root/example-http-two:ro
mongodb:
image: mongo:8.2
container_name: theplug-mongodb-test
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER:-theplug}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGO_INITDB_DATABASE: ${MONGO_DB:-theplug}
ports:
- "27017:27017"
volumes:
- mongodb_test_data:/data/db
healthcheck:
test: ["CMD-SHELL", "mongosh --quiet --username ${MONGO_USER:-theplug} --password ${MONGO_INITDB_ROOT_PASSWORD} --authenticationDatabase admin --eval \"db.adminCommand({ ping: 1 }).ok\" | grep 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
redis:
image: redis:8-alpine
container_name: theplug-redis-test
restart: unless-stopped
command: ["redis-server", "--appendonly", "yes"]
ports:
- "6379:6379"
volumes:
- redis_test_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
start_period: 5s
example-http-one:
build:
context: ./example-http-one
container_name: theplug-example-http-one
restart: unless-stopped
ports:
- "18081:8080"
example-http-two:
build:
context: ./example-http-two
container_name: theplug-example-http-two
restart: unless-stopped
ports:
- "18082:8080"
volumes:
mongodb_test_data:
redis_test_data:
+1 -1
View File
@@ -12,7 +12,7 @@ services:
volumes: volumes:
- mongodb_data:/data/db - mongodb_data:/data/db
healthcheck: healthcheck:
test: ["CMD-SHELL", "mongosh --quiet --username ${MONGO_USER:-theplug} --password ${MONGO_PASSWORD:-theplug_dev_password} --authenticationDatabase admin --eval \"db.adminCommand({ ping: 1 }).ok\" | grep 1"] test: ["CMD-SHELL", "mongosh --quiet --username ${MONGO_USER:-theplug} --password ${MONGO_INITDB_ROOT_PASSWORD} --authenticationDatabase admin --eval \"db.adminCommand({ ping: 1 }).ok\" | grep 1"]
interval: 10s interval: 10s
timeout: 5s timeout: 5s
retries: 5 retries: 5
+9
View File
@@ -0,0 +1,9 @@
FROM python:3.14-slim
WORKDIR /srv/www
COPY index.html ./
EXPOSE 8080
CMD ["python", "-m", "http.server", "8080", "--bind", "0.0.0.0", "--directory", "/srv/www"]
+6
View File
@@ -0,0 +1,6 @@
services:
web:
build: .
container_name: example-http-one
ports:
- "18081:8080"
+11
View File
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example HTTP One</title>
</head>
<body>
<h1>Example HTTP One</h1>
<p>This container serves a static page with Python's http.server.</p>
</body>
</html>
+9
View File
@@ -0,0 +1,9 @@
FROM python:3.14-slim
WORKDIR /srv/www
COPY index.html ./
EXPOSE 8080
CMD ["python", "-m", "http.server", "8080", "--bind", "0.0.0.0", "--directory", "/srv/www"]
+6
View File
@@ -0,0 +1,6 @@
services:
web:
build: .
container_name: example-http-two
ports:
- "18082:8080"
+11
View File
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example HTTP Two</title>
</head>
<body>
<h1>Example HTTP Two</h1>
<p>This container serves a static page with Python's http.server.</p>
</body>
</html>