diff --git a/.env.example b/.env.example index 5520098..bee1ad4 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,10 @@ API_PORT=3671 -MONGO_INITDB_ROOT_PASSWORD=pass# esegui 'openssl rand -hex 5' in un terminale e copia qui -MONGODB_URI=mongodb://theplug:pass@localhost:27017/theplug?authSource=admin +MONGO_INITDB_ROOT_PASSWORD=change-this-mongo-password +MONGODB_URI=mongodb://theplug:change-this-mongo-password@localhost:27017/theplug?authSource=admin MONGODB_DB_NAME=theplug 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_EXPIRE_MINUTES=30 AUTH_USERNAME=admin -AUTH_PASSWORD= # esegui 'openssl rand -hex 20' in un terminale e copia qui \ No newline at end of file +AUTH_PASSWORD=change-this-password diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 0000000..79b80b8 --- /dev/null +++ b/Dockerfile.test @@ -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}"] diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..886dbb7 --- /dev/null +++ b/docker-compose.test.yml @@ -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: diff --git a/docker-compose.yml b/docker-compose.yml index 9ba7067..b3be061 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: volumes: - mongodb_data:/data/db 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 timeout: 5s retries: 5 diff --git a/example-http-one/Dockerfile b/example-http-one/Dockerfile new file mode 100644 index 0000000..a0c7d8c --- /dev/null +++ b/example-http-one/Dockerfile @@ -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"] diff --git a/example-http-one/docker-compose.yml b/example-http-one/docker-compose.yml new file mode 100644 index 0000000..ade4369 --- /dev/null +++ b/example-http-one/docker-compose.yml @@ -0,0 +1,6 @@ +services: + web: + build: . + container_name: example-http-one + ports: + - "18081:8080" diff --git a/example-http-one/index.html b/example-http-one/index.html new file mode 100644 index 0000000..2e9afd6 --- /dev/null +++ b/example-http-one/index.html @@ -0,0 +1,11 @@ + + + + + Example HTTP One + + +

Example HTTP One

+

This container serves a static page with Python's http.server.

+ + diff --git a/example-http-two/Dockerfile b/example-http-two/Dockerfile new file mode 100644 index 0000000..a0c7d8c --- /dev/null +++ b/example-http-two/Dockerfile @@ -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"] diff --git a/example-http-two/docker-compose.yml b/example-http-two/docker-compose.yml new file mode 100644 index 0000000..ef4f3aa --- /dev/null +++ b/example-http-two/docker-compose.yml @@ -0,0 +1,6 @@ +services: + web: + build: . + container_name: example-http-two + ports: + - "18082:8080" diff --git a/example-http-two/index.html b/example-http-two/index.html new file mode 100644 index 0000000..cfbdcb1 --- /dev/null +++ b/example-http-two/index.html @@ -0,0 +1,11 @@ + + + + + Example HTTP Two + + +

Example HTTP Two

+

This container serves a static page with Python's http.server.

+ +