From 341f5ccbee52f2389fb41539d42b52e8bdad6a11 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Fri, 26 Apr 2024 17:58:17 -0400 Subject: [PATCH] Everything seems to be working with FastAPI 110 now!! Need to work on SQLAlchemy upgrade to 2.0.29 soon. --- aether_fastapi_gunicorn.Dockerfile | 21 +++++- conf/aether_fastapi_requirements.txt | 34 +++++----- ...ts_[freeze_2024-04-26_1240_fastapi110].txt | 67 +++++++++++++++++++ conf/aether_fastapi_requirements_current.txt | 8 +-- .../site-enabled_aether_fastapi_gunicorn.conf | 39 +++++++---- docker-compose.yml | 7 +- 6 files changed, 140 insertions(+), 36 deletions(-) create mode 100644 conf/aether_fastapi_requirements_[freeze_2024-04-26_1240_fastapi110].txt diff --git a/aether_fastapi_gunicorn.Dockerfile b/aether_fastapi_gunicorn.Dockerfile index 0e3dde0..0a4d1c8 100644 --- a/aether_fastapi_gunicorn.Dockerfile +++ b/aether_fastapi_gunicorn.Dockerfile @@ -22,7 +22,24 @@ RUN apt-get update; \ COPY conf/aether_fastapi_requirements.txt /tmp/requirements.txt RUN pip install --no-cache-dir -r /tmp/requirements.txt -RUN pip freeze > /aether_fastapi_requirements_current.txt -RUN pip freeze > /tmp/aether_fastapi_requirements_current.txt +# Freeze the requirements and then export them to a file that is accessible to the host +RUN pip freeze >> /tmp/aether_fastapi_requirements_current.txt +# docker cp ae_api_dev:/tmp/aether_fastapi_requirements_current.txt /home/scott/tmp/docker + +# RUN pip freeze > /tmp/aether_fastapi_requirements_new.txt +# RUN cp /tmp/aether_fastapi_requirements_new.txt /tmp/aether_fastapi_requirements_new_copy.txt + +# RUN pip freeze > /tmp/aether_fastapi_requirements_current.txt +# RUN cp /aether_fastapi_requirements_current.txt /var/aether_fastapi_requirements_current.txt +# RUN pip freeze >> /var/aether_fastapi_requirements_current.txt + +# VOLUME ["/export"] + +# RUN pip freeze > /logs/aether_fastapi_requirements_current.txt +# RUN pip freeze > /temp/aether_fastapi_requirements_current.txt +# RUN pip freeze > /tmp/aether_fastapi_requirements_current.txt +# RUN pip freeze > /var/aether_fastapi_requirements_current.txt + +# RUN pip freeze CMD ["gunicorn", "--conf", "/conf/gunicorn_fastapi_conf.py"] diff --git a/conf/aether_fastapi_requirements.txt b/conf/aether_fastapi_requirements.txt index 7a534c8..e52073a 100644 --- a/conf/aether_fastapi_requirements.txt +++ b/conf/aether_fastapi_requirements.txt @@ -1,4 +1,4 @@ -# Updated manually 2023-09-12 with a lot of trial and error. +# Updated manually 2024-04-26 with a lot of trial and error. # A few are commented out even though they are actually used and required. Other packages already pull them in. # SQLAlchemy needs to be upgraded to 2.x. There are issues with async IO or something related to that. # https://docs.sqlalchemy.org/en/14/changelog/migration_20.html @@ -20,12 +20,12 @@ Deprecated dnspython email-validator et-xmlfile -fastapi>=0.88.0 +fastapi==0.110.2 # working 0.95.1 0.94.1, 0.88.0; testing 0.108.0 0.99.1; not working >= 0.95.0 # greenlet>=2.0.2 # gevent -gunicorn>=22.0.0 +gunicorn # working >=21.2.0 h11 -html2text>=2020.1.16 +html2text httpcore httptools httpx @@ -34,40 +34,40 @@ itsdangerous # Jinja2>=3.1.2 MarkupSafe mysqlclient -numpy>=1.25.2 +numpy openpyxl orjson # packaging -pandas>=2.1.0 +pandas passlib -pdf2image>=1.16.3 -Pillow>=10.0.0 +pdf2image +Pillow pycparser -pydantic>=1.10.12 -PyJWT>=2.8.0 +pydantic +PyJWT pyparsing python-dateutil python-dotenv python-multipart pytz -PyYAML>=6.0.1 -qrcode>=7.4.2 +PyYAML +qrcode redis[hiredis] # redis==5.0.0 hiredis==2.2.3 requests rfc3986 six sniffio -SQLAlchemy==1.4.49 # 1.4.47 is the newest (2.0.20) I am working with -starlette>=0.22.0 -stripe>=6.4.0 +SQLAlchemy==1.4.52 # working 1.4.52; (2.0.29) I am working with +starlette # working ==0.26.1, 0.22.0; not working newest 0.37.2 +stripe typing_extensions ujson urllib3 -uvicorn +uvicorn # working ==0.20.0 uvloop Wand watchfiles watchgod -websockets>=11.0.3 +websockets wrapt xlrd diff --git a/conf/aether_fastapi_requirements_[freeze_2024-04-26_1240_fastapi110].txt b/conf/aether_fastapi_requirements_[freeze_2024-04-26_1240_fastapi110].txt new file mode 100644 index 0000000..9b5dc15 --- /dev/null +++ b/conf/aether_fastapi_requirements_[freeze_2024-04-26_1240_fastapi110].txt @@ -0,0 +1,67 @@ +aiofiles==23.2.1 +anyio==3.7.1 +argon2-cffi==23.1.0 +argon2-cffi-bindings==21.2.0 +async-timeout==4.0.3 +baize==0.20.8 +certifi==2024.2.2 +cffi==1.16.0 +charset-normalizer==3.3.2 +click==8.1.7 +Deprecated==1.2.14 +dnspython==2.6.1 +email_validator==2.1.1 +et-xmlfile==1.1.0 +fastapi==0.110.2 +greenlet==3.0.3 +gunicorn==21.2.0 +h11==0.14.0 +hiredis==2.3.2 +html2text==2024.2.26 +httpcore==1.0.5 +httptools==0.6.1 +httpx==0.27.0 +idna==3.7 +itsdangerous==2.2.0 +Jinja2==3.1.3 +MarkupSafe==2.1.5 +mysqlclient==2.2.4 +numpy==1.26.4 +openpyxl==3.1.2 +orjson==3.10.1 +packaging==24.0 +pandas==2.2.2 +passlib==1.7.4 +pdf2image==1.17.0 +pillow==10.3.0 +pycparser==2.22 +pydantic==1.10.15 +PyJWT==2.8.0 +pyparsing==3.1.2 +pypng==0.20220715.0 +python-dateutil==2.9.0.post0 +python-dotenv==1.0.1 +python-multipart==0.0.9 +pytz==2024.1 +PyYAML==6.0.1 +qrcode==7.4.2 +redis==5.0.4 +requests==2.31.0 +rfc3986==2.0.0 +six==1.16.0 +sniffio==1.3.1 +SQLAlchemy==1.4.52 +starlette==0.37.2 +stripe==9.4.0 +typing_extensions==4.11.0 +tzdata==2024.1 +ujson==5.9.0 +urllib3==2.2.1 +uvicorn==0.20.0 +uvloop==0.19.0 +Wand==0.6.13 +watchfiles==0.21.0 +watchgod==0.8.2 +websockets==12.0 +wrapt==1.16.0 +xlrd==2.0.1 diff --git a/conf/aether_fastapi_requirements_current.txt b/conf/aether_fastapi_requirements_current.txt index 4968fcb..c87e088 100644 --- a/conf/aether_fastapi_requirements_current.txt +++ b/conf/aether_fastapi_requirements_current.txt @@ -1,4 +1,4 @@ -# Updated manually 2023-09-12 with a lot of trial and error. +# Updated manually 2024-04-26 with a lot of trial and error. # A few are commented out even though they are actually used and required. Other packages already pull them in. # SQLAlchemy needs to be upgraded to 2.x. There are issues with async IO or something related to that. # https://docs.sqlalchemy.org/en/14/changelog/migration_20.html @@ -19,9 +19,9 @@ Deprecated dnspython email-validator et-xmlfile -fastapi>=0.88.0 +fastapi==0.94.1 # working 0.94.1, 0.88.0; not working >= 0.95.0 greenlet>=2.0.2 -gunicorn>=20.1.0 +gunicorn>=22.0.0 h11 html2text>=2020.1.16 httpcore @@ -55,7 +55,7 @@ requests rfc3986 six sniffio -SQLAlchemy==1.4.49 # 1.4.47 is the newest (2.0.20) I am working with +SQLAlchemy==1.4.49 # 1.4.49 is the newest (2.0.20) I am working with starlette>=0.22.0 stripe>=6.4.0 typing_extensions diff --git a/conf/nginx/site-enabled_aether_fastapi_gunicorn.conf b/conf/nginx/site-enabled_aether_fastapi_gunicorn.conf index 1cbae73..f7f644f 100644 --- a/conf/nginx/site-enabled_aether_fastapi_gunicorn.conf +++ b/conf/nginx/site-enabled_aether_fastapi_gunicorn.conf @@ -1,3 +1,8 @@ +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + server { listen 80; listen [::]:80; @@ -21,21 +26,26 @@ server { client_max_body_size ${OSIT_WEB_MAX_BODY_SIZE}; # 5120M; #4096M or 4G; 5120M or 5G; location / { + # Based on recommendations here: https://www.uvicorn.org/deployment/#running-behind-nginx proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; proxy_redirect off; proxy_buffering off; + # I think "X-Real-IP" might be needed for some things? + proxy_set_header X-Real-IP $remote_addr; + # This is needed for long running Python code. Default is 60 seconds # Increased from 1200 to 1500 on 2022-04-17 # Increased from 1500 to 2000 on 2023-03-15 # Increased proxy read timeout to 2100 and decreased fastcgi options to 35s on 2023-03-16 - fastcgi_connect_timeout 4s; - fastcgi_send_timeout 5s; - fastcgi_read_timeout 5s; + # fastcgi_connect_timeout 4s; + # fastcgi_send_timeout 5s; + # fastcgi_read_timeout 5s; # proxy read timeout being too low will cause 504 Gateway Time-out on the client browser proxy_read_timeout 2100s; @@ -101,21 +111,26 @@ server { client_max_body_size ${OSIT_WEB_MAX_BODY_SIZE}; # 5120M; #4096M or 4G; 5120M or 5G; location / { + # Based on recommendations here: https://www.uvicorn.org/deployment/#running-behind-nginx proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; proxy_redirect off; proxy_buffering off; - # This is needed for long running Python code. Default is 60 seconds - # Increased from 1200 to 1500 on 2022-04-17 - # Increased from 1500 to 2000 on 2023-03-15 - # Increased proxy read timeout to 2100 and decreased fastcgi options to 35s on 2023-03-16 - fastcgi_connect_timeout 35s; - fastcgi_send_timeout 35s; - fastcgi_read_timeout 35s; + # I think "X-Real-IP" might be needed for some things? + proxy_set_header X-Real-IP $remote_addr; + + # # This is needed for long running Python code. Default is 60 seconds + # # Increased from 1200 to 1500 on 2022-04-17 + # # Increased from 1500 to 2000 on 2023-03-15 + # # Increased proxy read timeout to 2100 and decreased fastcgi options to 35s on 2023-03-16 + # fastcgi_connect_timeout 35s; + # fastcgi_send_timeout 35s; + # fastcgi_read_timeout 35s; # proxy read timeout being too low will cause 504 Gateway Time-out on the client browser proxy_read_timeout 2100s; diff --git a/docker-compose.yml b/docker-compose.yml index 9c7cc9b..8360cfb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -139,6 +139,9 @@ services: dockerfile: aether_fastapi_gunicorn.Dockerfile env_file: - ./.env + environment: + - PUID=1000 + - PGID=1000 ports: - "${AE_API_GUNICORN_PORT}:5005" extra_hosts: @@ -165,7 +168,9 @@ services: - ./srv/hosted_tmp_ln:/srv/hosted_tmp # - ./tmp/ae_api:/tmp - - ./temp/ae_api:/temp + # - ./tmp/root/aether_fastapi_requirements_current.txt:/aether_fastapi_requirements_current.txt + # - ./temp/ae_api/aether_fastapi_requirements_current.txt:/temp/aether_fastapi_requirements_current.txt + # - ./tmp/test:/var # links: # - redis depends_on: