diff --git a/app/algorithms/online_Analysis.py b/app/algorithms/online_Analysis.py index c9fc28d..509bd11 100644 --- a/app/algorithms/online_Analysis.py +++ b/app/algorithms/online_Analysis.py @@ -18,7 +18,7 @@ import geopandas as gpd from sqlalchemy import create_engine import ast import sensitivity -import app.services.project_info as project_info +import configs.project_info as project_info import app.algorithms.api_ex.kmeans_sensor import app.algorithms.api_ex.Fdataclean import app.algorithms.api_ex.Pdataclean diff --git a/app/infra/db/influxdb/api.py b/app/infra/db/influxdb/api.py index 71c7325..4647740 100644 --- a/app/infra/db/influxdb/api.py +++ b/app/infra/db/influxdb/api.py @@ -27,7 +27,7 @@ import pandas as pd import openpyxl import pytz import app.infra.db.influxdb.info as influxdb_info -import app.services.project_info as project_info +import configs.project_info as project_info import app.services.time_api as time_api from app.native.api.postgresql_info import get_pgconn_string diff --git a/app/main.py b/app/main.py index 5be0bbd..2ad347c 100644 --- a/app/main.py +++ b/app/main.py @@ -47,7 +47,7 @@ import py_linq import app.services.time_api as time_api import app.services.simulation as simulation import app.services.globals as globals -import app.services.project_info as project_info +import configs.project_info as project_info from app.infra.db.timescaledb.database import db as tsdb from app.infra.db.postgresql.database import db as pgdb from app.algorithms.online_Analysis import * diff --git a/app/services/simulation.py b/app/services/simulation.py index af085f9..31984a8 100644 --- a/app/services/simulation.py +++ b/app/services/simulation.py @@ -19,7 +19,7 @@ import psycopg import logging import app.services.globals as globals import uuid -import app.services.project_info as project_info +import configs.project_info as project_info from app.native.api.postgresql_info import get_pgconn_string from timescaledb.internal_queries import InternalQueries as TimescaleInternalQueries from timescaledb.internal_queries import InternalStorage as TimescaleInternalStorage diff --git a/app/services/project_info.py b/configs/project_info.py similarity index 100% rename from app/services/project_info.py rename to configs/project_info.py diff --git a/infra/docker/Dockerfile b/infra/docker/Dockerfile index 6801213..3c0baa3 100644 --- a/infra/docker/Dockerfile +++ b/infra/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-slim +FROM python:3.12-slim WORKDIR /app diff --git a/infra/docker/docker-compose.yml b/infra/docker/docker-compose.yml index 3f54ba1..a525af6 100644 --- a/infra/docker/docker-compose.yml +++ b/infra/docker/docker-compose.yml @@ -1,23 +1,164 @@ -version: '3.8' - services: + # ========================================== + # Core API Service + # ========================================== api: build: context: ../.. dockerfile: infra/docker/Dockerfile + container_name: tjwater_api + restart: always ports: - - "8000:8000" + - "${API_PORT}:8000" volumes: - ../../app:/app/app - ../../resources:/app/resources environment: - PYTHONPATH=/app + - REDIS_HOST=redis + - REDIS_PORT=${REDIS_PORT} + - REDIS_PASSWORD=${REDIS_PASSWORD} + # Add other DB connections here as needed by your app depends_on: - redis + - timescaledb + - postgis + # ========================================== + # Infrastructure Services + # ========================================== + + # --- Redis --- redis: - image: redis:alpine + image: redis:latest + container_name: redis + restart: always + command: redis-server --requirepass ${REDIS_PASSWORD} ports: - - "6379:6379" + - "${REDIS_PORT}:6379" + volumes: + - ./redis/data:/data -# Add other services as needed (postgres, influxdb, timescaledb) + # --- InfluxDB --- + influxdb: + image: influxdb:2.7 + container_name: influxdb + restart: always + environment: + DOCKER_INFLUXDB_INIT_MODE: setup + DOCKER_INFLUXDB_INIT_USERNAME: ${INFLUXDB_USER} + DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_PASSWORD} + DOCKER_INFLUXDB_INIT_ORG: ${INFLUXDB_ORG} + DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUXDB_BUCKET} + DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUXDB_ADMIN_TOKEN} + ports: + - "${INFLUXDB_PORT}:8086" + volumes: + - ./influxdb/data:/var/lib/influxdb2 + + # --- Keycloak --- + keycloakDB: + image: postgis/postgis:14-3.5 + container_name: keycloakDB + restart: always + environment: + POSTGRES_DB: ${KEYCLOAK_DB_NAME} + POSTGRES_USER: ${KEYCLOAK_DB_USER} + POSTGRES_PASSWORD: ${KEYCLOAK_DB_PASSWORD} + ports: + - "${KEYCLOAK_DB_PORT}:5432" + volumes: + - ./keycloak/db_data:/var/lib/postgresql/data + + keycloak: + image: keycloak/keycloak:latest + container_name: keycloak + restart: always + environment: + KC_HOSTNAME: localhost + KC_HOSTNAME_STRICT_BACKCHANNEL: "true" + KEYCLOAK_ADMIN: ${KEYCLOAK_ADMIN_USER} + KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD} + KC_HEALTH_ENABLED: "true" + KC_LOG_LEVEL: info + KC_DB: postgres + KC_DB_URL: jdbc:postgresql://keycloakDB:5432/${KEYCLOAK_DB_NAME} + KC_DB_USERNAME: ${KEYCLOAK_DB_USER} + KC_DB_PASSWORD: ${KEYCLOAK_DB_PASSWORD} + volumes: + - ./keycloak/themes:/opt/keycloak/themes + - ./keycloak/import:/opt/keycloak/data/import + healthcheck: + test: [ "CMD", "curl", "-f", "http://localhost:8080/health/ready" ] + interval: 15s + timeout: 2s + retries: 15 + command: [ "start-dev", "--import-realm" ] + ports: + - "${KEYCLOAK_PORT}:8080" + depends_on: + - keycloakDB + + # --- TimescaleDB & Grafana --- + timescaledb: + image: timescale/timescaledb:latest-pg15 + container_name: timescaledb + restart: always + environment: + POSTGRES_DB: ${TIMESCALE_DB_NAME} + POSTGRES_USER: ${TIMESCALE_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD_SHARED} + ports: + - "${TIMESCALE_PORT}:5432" + volumes: + - ./timescaledb/data:/var/lib/postgresql/data + + grafana: + image: grafana/grafana:latest + container_name: grafana + restart: always + ports: + - "${GRAFANA_PORT}:3000" + depends_on: + - timescaledb + volumes: + - ./timescaledb/grafana_data:/var/lib/grafana + environment: + - GF_SECURITY_ADMIN_USER=${GRAFANA_ADMIN_USER} + - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD} + + # --- MapService (PostGIS & GeoServer) --- + postgis: + image: postgis/postgis:14-3.5 + container_name: postgis + restart: always + environment: + POSTGRES_DB: ${POSTGIS_DB_NAME} + POSTGRES_USER: ${POSTGIS_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD_SHARED} + ports: + - "${POSTGIS_PORT}:5432" + volumes: + - ./mapservice/data:/var/lib/postgresql/data + + geoserver: + image: docker.osgeo.org/geoserver:2.27.1 + container_name: geoserver + restart: always + ports: + - "${GEOSERVER_PORT}:8080" + depends_on: + - postgis + environment: + - GEOSERVER_ADMIN_USER=${GEOSERVER_ADMIN_USER} + - GEOSERVER_ADMIN_PASSWORD=${GEOSERVER_ADMIN_PASSWORD} + - INSTALL_EXTENSIONS=true + - STABLE_EXTENSIONS=css,vectortiles + - CORS_ENABLED=true + - CORS_ALLOWED_ORIGINS=* + volumes: + - ./mapservice/geoserver_data:/opt/geoserver_data + +networks: + default: + driver: bridge diff --git a/requirements.txt b/requirements.txt index 5b04d85..0700705 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/resources/old_requirements.txt b/resources/old_requirements.txt new file mode 100644 index 0000000..5b04d85 Binary files /dev/null and b/resources/old_requirements.txt differ diff --git a/resources/requirements2.txt b/resources/requirements2.txt deleted file mode 100644 index 0700705..0000000 --- a/resources/requirements2.txt +++ /dev/null @@ -1,168 +0,0 @@ -annotated-doc==0.0.4 -annotated-types==0.7.0 -anyio==4.8.0 -attrs==25.4.0 -Authlib==1.6.6 -beartype==0.22.9 -beautifulsoup4==4.13.4 -cachetools==6.2.4 -certifi==2024.8.30 -cffi==2.0.0 -chardet==5.2.0 -charset-normalizer==3.4.0 -click==8.1.8 -cloudpickle==3.1.2 -colorama==0.4.6 -contourpy==1.3.2 -cryptography==46.0.3 -cycler==0.12.1 -cyclopts==4.5.0 -Cython==3.0.12 -diskcache==5.6.3 -distro==1.9.0 -dnspython==2.8.0 -docstring_parser==0.17.0 -docutils==0.21.2 -dotenv==0.9.9 -ecos==2.0.14 -email-validator==2.3.0 -esda==2.7.0 -et_xmlfile==2.0.0 -exceptiongroup==1.3.1 -fakeredis==2.33.0 -fastapi==0.128.0 -fastmcp==2.9.2 -fonttools==4.58.0 -future==0.18.3 -GeoAlchemy2==0.17.1 -geopandas==1.0.1 -greenlet==3.1.1 -h11==0.14.0 -httpcore==1.0.7 -httpx==0.28.1 -httpx-sse==0.4.3 -idna==3.10 -importlib_metadata==8.7.1 -influxdb-client==1.48.0 -iniconfig==2.0.0 -jaraco.classes==3.4.0 -jaraco.context==6.1.0 -jaraco.functools==4.4.0 -jeepney==0.9.0 -Jinja2==3.1.6 -jiter==0.8.2 -joblib==1.5.0 -jsonschema==4.26.0 -jsonschema-path==0.3.4 -jsonschema-specifications==2025.9.1 -keyring==25.7.0 -Kivy==2.3.0 -Kivy-Garden==0.1.5 -kiwisolver==1.4.8 -libpysal==4.13.0 -lupa==2.6 -mapclassify==2.8.1 -markdown-it-py==3.0.0 -MarkupSafe==3.0.3 -matplotlib==3.10.3 -mcp==1.9.4 -mdurl==0.1.2 -more-itertools==10.8.0 -msgpack==1.1.0 -networkx==3.4.2 -numexpr==2.14.1 -numpy==1.26.2 -openai==1.63.0 -openapi-pydantic==0.5.1 -openpyxl==3.1.5 -opentelemetry-api==1.39.1 -opentelemetry-exporter-prometheus==0.60b1 -opentelemetry-instrumentation==0.60b1 -opentelemetry-sdk==1.39.1 -opentelemetry-semantic-conventions==0.60b1 -osqp==1.0.5 -packaging==25.0 -pandas==2.2.3 -pathable==0.4.4 -pathvalidate==3.3.1 -pillow==11.2.1 -pipdeptree==2.30.0 -platformdirs==4.3.8 -pluggy==1.5.0 -pointpats==2.5.1 -prometheus_client==0.24.1 -psycopg==3.2.5 -psycopg-binary==3.2.5 -psycopg-pool==3.3.0 -psycopg2==2.9.10 -PuLP==3.1.1 -py-key-value-aio==0.3.0 -py-key-value-shared==0.3.0 -py-linq==1.4.0 -pyarmor==9.0.7 -pyarmor.cli.core==7.6.4 -pybind11-stubgen==2.5.1 -pycparser==2.23 -pydantic==2.10.6 -pydantic-settings==2.12.0 -pydantic_core==2.27.2 -pydevd-pycharm==243.16718.36 -pydocket==0.16.6 -Pygments==2.18.0 -PyJWT==2.10.1 -pykalman==0.10.2 -# pymetis @ file:///D:/bld/pymetis_1762455149640/work 通过 conda 安装 pymetis,避免编译问题 conda install -c conda-forge pymetis -pynvim==0.5.0 -pyogrio==0.11.0 -pyparsing==3.2.3 -pyperclip==1.11.0 -pyproj==3.7.1 -pytest==8.3.5 -python-dateutil==2.9.0.post0 -python-dotenv==1.2.1 -python-json-logger==4.0.0 -python-multipart==0.0.20 -pytz==2025.2 -PyYAML==6.0.3 -pyzmq==26.2.1 -reactivex==4.0.4 -redis==5.2.1 -referencing==0.36.2 -requests==2.32.3 -rich==14.2.0 -rich-rst==1.3.2 -rpds-py==0.30.0 -rtree==1.4.0 -schedule==1.2.2 -scikit-base==0.12.6 -scikit-fuzzy==0.5.0 -scikit-learn==1.6.1 -scikit-survival==0.26.0 -scipy==1.15.2 -SecretStorage==3.5.0 -setuptools==80.7.1 -shapely==2.1.0 -shellingham==1.5.4 -six==1.17.0 -sniffio==1.3.1 -sortedcontainers==2.4.0 -soupsieve==2.7 -spaghetti==1.7.6 -spopt==0.6.1 -SQLAlchemy==2.0.41 -sse-starlette==3.0.4 -starlette==0.50.0 -threadpoolctl==3.6.0 -tqdm==4.67.1 -typer==0.21.1 -typing-inspection==0.4.0 -typing_extensions==4.12.2 -tzdata==2025.2 -urllib3==2.2.3 -uvicorn==0.34.0 -websockets==16.0 -wheel==0.45.1 -wntr==1.3.2 -wrapt==1.17.3 -zipp==3.23.0 -zmq==0.0.0