chore: update
This commit is contained in:
Vendored
+2
-1
@@ -8,7 +8,8 @@
|
|||||||
"**/target": true,
|
"**/target": true,
|
||||||
"**/docker": true,
|
"**/docker": true,
|
||||||
"node_modules": true,
|
"node_modules": true,
|
||||||
"**/.mvn": true
|
"**/.mvn": true,
|
||||||
|
"**/venv": true
|
||||||
},
|
},
|
||||||
"explorerExclude.backup": {},
|
"explorerExclude.backup": {},
|
||||||
"java.compile.nullAnalysis.mode": "automatic",
|
"java.compile.nullAnalysis.mode": "automatic",
|
||||||
|
|||||||
@@ -111,16 +111,6 @@
|
|||||||
<artifactId>quarkus-maven-plugin</artifactId>
|
<artifactId>quarkus-maven-plugin</artifactId>
|
||||||
<version>${quarkus.platform.version}</version>
|
<version>${quarkus.platform.version}</version>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>build</goal>
|
|
||||||
<goal>generate-code</goal>
|
|
||||||
<goal>generate-code-tests</goal>
|
|
||||||
<goal>native-image-agent</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
wrapperVersion=3.3.4
|
||||||
|
distributionType=only-script
|
||||||
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.15/apache-maven-3.9.15-bin.zip
|
||||||
|
distributionSha256Sum=b0d9292f06c5faded31ddcb6cb69099f316d6fea40a7778624b259bad9fed18a
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||||
|
>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.drinkool</groupId>
|
||||||
|
<artifactId>drinkool</artifactId>
|
||||||
|
<version>1.5.24</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>file-service</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<quarkus.container-image.registry>vps.demonkernel.io.vn</quarkus.container-image.registry>
|
||||||
|
<quarkus.container-image.group>foodsurf</quarkus.container-image.group>
|
||||||
|
<quarkus.container-image.name>file-service</quarkus.container-image.name>
|
||||||
|
|
||||||
|
<python.image.full.name>
|
||||||
|
${quarkus.container-image.registry}/${quarkus.container-image.group}/${quarkus.container-image.name}</python.image.full.name>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-container-image-docker</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>docker-build-python</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<executable>docker</executable>
|
||||||
|
<workingDirectory>${project.basedir}/python</workingDirectory>
|
||||||
|
<arguments>
|
||||||
|
<argument>build</argument>
|
||||||
|
<argument>-t</argument>
|
||||||
|
<argument>${python.image.full.name}:${parent.version}</argument>
|
||||||
|
<argument>-t</argument>
|
||||||
|
<argument>${python.image.full.name}:latest</argument>
|
||||||
|
<argument>.</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
|
||||||
|
<execution>
|
||||||
|
<id>docker-push-python</id>
|
||||||
|
<phase>install</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<executable>docker</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>push</argument>
|
||||||
|
<argument>${python.image.full.name}</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# --- Stage 1: Build (Cài đặt thư viện) ---
|
||||||
|
FROM python:3.9-slim AS builder
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
# Khởi tạo môi trường ảo để tách biệt thư viện
|
||||||
|
RUN python -m venv /opt/venv
|
||||||
|
ENV PATH="/opt/venv/bin:$PATH"
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --upgrade --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
|
||||||
|
# --- Stage 2: Runtime (Chỉ chạy Prod) ---
|
||||||
|
FROM python:3.9-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Chỉ copy môi trường ảo đã build xong từ Stage 1
|
||||||
|
COPY --from=builder /opt/venv /opt/venv
|
||||||
|
ENV PATH="/opt/venv/bin:$PATH"
|
||||||
|
|
||||||
|
# Copy mã nguồn
|
||||||
|
COPY main.py .
|
||||||
|
|
||||||
|
# Tạo folder lưu ảnh và phân quyền (tăng tính bảo mật)
|
||||||
|
RUN mkdir images && chmod 777 images
|
||||||
|
|
||||||
|
# Chạy bằng Uvicorn với chế độ production (tắt reload)
|
||||||
|
# Port 80 theo yêu cầu trước đó của bạn
|
||||||
|
EXPOSE 80
|
||||||
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80", "--workers", "4"]
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import os
|
||||||
|
from fastapi import FastAPI, File, UploadFile, HTTPException
|
||||||
|
from fastapi.responses import FileResponse
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
# Thư mục lưu trữ ảnh (nên được mount volume khi chạy docker)
|
||||||
|
STORAGE_DIR = Path("images")
|
||||||
|
STORAGE_DIR.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
@app.post("/")
|
||||||
|
async def upload_image(file: UploadFile = File(...)):
|
||||||
|
# Chỉ chấp nhận định dạng ảnh
|
||||||
|
if not file.content_type.startswith("image/"):
|
||||||
|
raise HTTPException(status_code=400, detail="File không hợp lệ. Chỉ chấp nhận ảnh.")
|
||||||
|
|
||||||
|
file_path = STORAGE_DIR / file.filename
|
||||||
|
|
||||||
|
# Ghi file theo block để tối ưu bộ nhớ
|
||||||
|
with open(file_path, "wb") as f:
|
||||||
|
content = await file.read()
|
||||||
|
f.write(content)
|
||||||
|
|
||||||
|
return {"status": "success", "filename": file.filename}
|
||||||
|
|
||||||
|
@app.get("/{name}")
|
||||||
|
async def get_image(name: str):
|
||||||
|
file_path = STORAGE_DIR / name
|
||||||
|
|
||||||
|
if not file_path.exists() or not file_path.is_file():
|
||||||
|
raise HTTPException(status_code=404, detail="Không tìm thấy ảnh")
|
||||||
|
|
||||||
|
# Trả về ảnh trực tiếp cho trình duyệt/client
|
||||||
|
return FileResponse(file_path)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fastapi
|
||||||
|
uvicorn
|
||||||
|
python-multipart
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: file-deploy
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: file
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: file
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: file-pod
|
||||||
|
image: git.demonkernel.io.vn/foodsurf/file-service:1.5.24
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "32Mi"
|
||||||
|
cpu: "50m"
|
||||||
|
limits:
|
||||||
|
memory: "64Mi"
|
||||||
|
cpu: "250m"
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: file-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: file
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 80
|
||||||
@@ -2,6 +2,7 @@ resources:
|
|||||||
- account.yaml
|
- account.yaml
|
||||||
- eatery.yaml
|
- eatery.yaml
|
||||||
- cart.yaml
|
- cart.yaml
|
||||||
|
- file.yaml
|
||||||
- gateway.yaml
|
- gateway.yaml
|
||||||
- redis.yaml
|
- redis.yaml
|
||||||
- kafdrop.yaml
|
- kafdrop.yaml
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
<module>account-service</module>
|
<module>account-service</module>
|
||||||
<module>gateway-service</module>
|
<module>gateway-service</module>
|
||||||
<module>cart-service</module>
|
<module>cart-service</module>
|
||||||
|
<module>file-service</module>
|
||||||
</modules>
|
</modules>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
Reference in New Issue
Block a user