Pārlūkot izejas kodu

change Docker usage

highing666 3 gadi atpakaļ
vecāks
revīzija
7af05860c4
4 mainītis faili ar 58 papildinājumiem un 20 dzēšanām
  1. 17 9
      Dockerfile
  2. 5 5
      app/core/config.py
  3. 6 6
      app/main.py
  4. 30 0
      pyproject.toml

+ 17 - 9
Dockerfile

@@ -1,20 +1,28 @@
-FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
+# syntax=docker/dockerfile:1
 
-COPY requirements.txt .
+FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
 
-COPY ./venv/pkgs /app/pkgs
-# RUN cat requirements.txt | xargs -n 1 pip install --no-index --find-links=pkgs
-RUN pip install --no-index --find-links=pkgs -r requirements.txt
+WORKDIR /app
 
+# Install Poetry
+RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \
+    cd /usr/local/bin && \
+    ln -s /opt/poetry/bin/poetry && \
+    poetry config virtualenvs.create false
 
-EXPOSE 8002
+# Copy poetry.lock* in case it doesn't exist in the repo
+COPY pyproject.toml poetry.lock* /app/
 
-COPY .env /app/.env
+# Allow installing dev dependencies to run tests
+ARG INSTALL_DEV=false
+RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
 
 COPY ./app /app/app
-COPY ./logs /app/logs
+ENV PYTHONPATH=/app
+
+EXPOSE 8002
 
-COPY ./ml_models /app/ml_models
+COPY .env_pro /app/.env
 
 ENV TZ=Asia/Shanghai
 

+ 5 - 5
app/core/config.py

@@ -19,9 +19,9 @@ class Settings(BaseSettings):
     PLATFORM_HOST: AnyHttpUrl
     PLATFORM_SECRET: SecretStr
     TRANSFER_HOST: AnyHttpUrl
-    WEATHER_HOST: AnyHttpUrl
+    # WEATHER_HOST: AnyHttpUrl
 
-    HTTPS_PROXY: AnyHttpUrl
+    # HTTPS_PROXY: AnyHttpUrl
 
     TENCENT_NLP_ENDPOINT: str
     TENCENT_SECRET_ID_V1: str
@@ -29,10 +29,10 @@ class Settings(BaseSettings):
 
     DUCKLING_HOST: AnyHttpUrl
 
-    PROJECT_DIR: DirectoryPath
-    LOGS_DIR: DirectoryPath
+    # PROJECT_DIR: DirectoryPath
+    # LOGS_DIR: DirectoryPath
 
-    ML_MODELS_DIR: DirectoryPath
+    # ML_MODELS_DIR: DirectoryPath
 
     PROJECT_NAME: str
 

+ 6 - 6
app/main.py

@@ -25,12 +25,12 @@ from app.db.session import Base, engine
 Base.metadata.create_all(bind=engine)
 
 logging.getLogger().handlers = [InterceptHandler()]
-logger.add(
-    Path(settings.LOGS_DIR, "env_fastapi.log"),
-    level="INFO",
-    rotation="00:00",
-    encoding="utf-8",
-)
+# logger.add(
+#     Path(settings.LOGS_DIR, "env_fastapi.log"),
+#     level="INFO",
+#     rotation="00:00",
+#     encoding="utf-8",
+# )
 
 
 def get_application() -> FastAPI:

+ 30 - 0
pyproject.toml

@@ -0,0 +1,30 @@
+[tool.poetry]
+name = "saga_algo_api"
+version = "0.1.0"
+description = "SagaCare Algorithm Web Server"
+authors = ["highing666 <bigseabigdream@gmail.com>"]
+license = "Apache-2.0"
+
+[tool.poetry.dependencies]
+python = "^3.8"
+Cython = "^0.29.24"
+pandas = "1.2.4"
+fastapi = "^0.68.1"
+python-dotenv = "^0.19.0"
+uvicorn = "^0.13.4"
+psycopg2-binary = "^2.9.1"
+SQLAlchemy = "^1.4.23"
+arrow = "^1.1.1"
+loguru = "^0.5.3"
+httpx = "^0.19.0"
+tencentcloud-sdk-python = "^3.0.470"
+scikit-learn = "^0.24.2"
+
+[tool.poetry.dev-dependencies]
+pylint = "^2.10.2"
+flake8 = "^3.9.2"
+black = "^21.7b0"
+
+[build-system]
+requires = ["poetry-core>=1.0.0"]
+build-backend = "poetry.core.masonry.api"