Commit ·
44c5a99
1
Parent(s): f64ea82
dbvhbf
Browse files- Dockerfile +7 -2
- controllers/main.py +0 -0
- database/database.py +12 -1
Dockerfile
CHANGED
|
@@ -1,11 +1,16 @@
|
|
| 1 |
# Sử dụng Python 3.10
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Cài đặt thư viện hệ thống cho OpenCV và Compiler C++ cho Insightface
|
| 5 |
-
RUN apt-get update && apt-get install -y \
|
| 6 |
libgl1 \
|
| 7 |
libglib2.0-0 \
|
| 8 |
build-essential \
|
|
|
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
# Cấu hình User cho Hugging Face
|
|
@@ -27,4 +32,4 @@ COPY --chown=user . .
|
|
| 27 |
EXPOSE 7860
|
| 28 |
|
| 29 |
# Khởi động server API
|
| 30 |
-
CMD ["uvicorn", "controllers.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
# Sử dụng Python 3.10
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
ENV TZ=Asia/Ho_Chi_Minh \
|
| 5 |
+
APP_TIMEZONE=Asia/Ho_Chi_Minh \
|
| 6 |
+
DB_TIME_ZONE=+07:00
|
| 7 |
+
|
| 8 |
# Cài đặt thư viện hệ thống cho OpenCV và Compiler C++ cho Insightface
|
| 9 |
+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
| 10 |
libgl1 \
|
| 11 |
libglib2.0-0 \
|
| 12 |
build-essential \
|
| 13 |
+
tzdata \
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
|
| 16 |
# Cấu hình User cho Hugging Face
|
|
|
|
| 32 |
EXPOSE 7860
|
| 33 |
|
| 34 |
# Khởi động server API
|
| 35 |
+
CMD ["uvicorn", "controllers.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
controllers/main.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
database/database.py
CHANGED
|
@@ -9,6 +9,7 @@ load_dotenv()
|
|
| 9 |
DEFAULT_ADMIN_USERNAME = "admin"
|
| 10 |
DEFAULT_ADMIN_PASSWORD = "123456"
|
| 11 |
DEFAULT_ADMIN_NAME = "Administrator"
|
|
|
|
| 12 |
|
| 13 |
db_config = {
|
| 14 |
"host": os.getenv("DB_HOST", "gateway01.ap-northeast-1.prod.aws.tidbcloud.com"),
|
|
@@ -28,7 +29,17 @@ except Exception as e:
|
|
| 28 |
print(f"[LOI] Loi khoi tao Pool MySQL: {e}")
|
| 29 |
|
| 30 |
def get_db_connection():
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
def _hash_password(password: str, salt: str) -> str:
|
| 34 |
return hashlib.sha256(f"{salt}:{password}".encode("utf-8")).hexdigest()
|
|
|
|
| 9 |
DEFAULT_ADMIN_USERNAME = "admin"
|
| 10 |
DEFAULT_ADMIN_PASSWORD = "123456"
|
| 11 |
DEFAULT_ADMIN_NAME = "Administrator"
|
| 12 |
+
DB_TIME_ZONE = os.getenv("DB_TIME_ZONE", "+07:00")
|
| 13 |
|
| 14 |
db_config = {
|
| 15 |
"host": os.getenv("DB_HOST", "gateway01.ap-northeast-1.prod.aws.tidbcloud.com"),
|
|
|
|
| 29 |
print(f"[LOI] Loi khoi tao Pool MySQL: {e}")
|
| 30 |
|
| 31 |
def get_db_connection():
|
| 32 |
+
conn = connection_pool.get_connection()
|
| 33 |
+
cursor = None
|
| 34 |
+
try:
|
| 35 |
+
cursor = conn.cursor()
|
| 36 |
+
cursor.execute("SET time_zone = %s", (DB_TIME_ZONE,))
|
| 37 |
+
except Exception as e:
|
| 38 |
+
print(f"[WARN] Khong the set time_zone MySQL {DB_TIME_ZONE}: {e}")
|
| 39 |
+
finally:
|
| 40 |
+
if cursor:
|
| 41 |
+
cursor.close()
|
| 42 |
+
return conn
|
| 43 |
|
| 44 |
def _hash_password(password: str, salt: str) -> str:
|
| 45 |
return hashlib.sha256(f"{salt}:{password}".encode("utf-8")).hexdigest()
|