Spaces:
Sleeping
Sleeping
Commit
·
5bf8b9e
1
Parent(s):
a19690e
Add fetch + static server
Browse files- Dockerfile +27 -0
- app.py +17 -0
- requirements.txt +1 -0
Dockerfile
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM node:18-slim AS node_layer
|
2 |
+
|
3 |
+
# Build layer cho http-server
|
4 |
+
RUN npm install -g http-server
|
5 |
+
|
6 |
+
FROM python:3.9-slim
|
7 |
+
|
8 |
+
# Tạo user không phải root (Hugging Face yêu cầu)
|
9 |
+
RUN useradd -m -u 1000 user
|
10 |
+
USER user
|
11 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
12 |
+
|
13 |
+
WORKDIR /app
|
14 |
+
|
15 |
+
# Cài Python dependencies
|
16 |
+
COPY --chown=user requirements.txt .
|
17 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
18 |
+
|
19 |
+
# Copy toàn bộ app và static
|
20 |
+
COPY --chown=user . /app
|
21 |
+
|
22 |
+
# Copy http-server từ node layer
|
23 |
+
COPY --from=node_layer /usr/local/bin/http-server /usr/local/bin/http-server
|
24 |
+
COPY --from=node_layer /usr/local/lib/node_modules /usr/local/lib/node_modules
|
25 |
+
|
26 |
+
# Chạy 2 tiến trình song song: fetch_data và http-server
|
27 |
+
CMD ["sh", "-c", "python app.py & http-server ./static -p 7860"]
|
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def fetch_data():
|
5 |
+
while True:
|
6 |
+
try:
|
7 |
+
response = requests.get("https://stock.stoknet.org/api/vnindexdata")
|
8 |
+
if response.status_code == 200:
|
9 |
+
print("Fetched data:", response.json())
|
10 |
+
else:
|
11 |
+
print(f"Error fetching data: {response.status_code}")
|
12 |
+
except Exception as e:
|
13 |
+
print("Exception:", e)
|
14 |
+
time.sleep(10)
|
15 |
+
|
16 |
+
if __name__ == "__main__":
|
17 |
+
fetch_data()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
requests
|