Spaces:
Sleeping
Sleeping
ichieh commited on
Commit ·
0e8b1df
1
Parent(s): 386e7a4
Improve data persistence handling and documentation
Browse files- Dockerfile +7 -5
- README.md +17 -15
- app.py +14 -1
Dockerfile
CHANGED
|
@@ -11,14 +11,16 @@ RUN apt-get update && apt-get install -y \
|
|
| 11 |
COPY ./requirements.txt /code/requirements.txt
|
| 12 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Copy the rest of the application
|
| 15 |
COPY . /code/
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
RUN
|
| 19 |
-
chmod -R 777 /data && \
|
| 20 |
-
chown -R 1000:1000 /data && \
|
| 21 |
-
chmod -R 777 /code && \
|
| 22 |
chown -R 1000:1000 /code
|
| 23 |
|
| 24 |
# Switch to non-root user
|
|
|
|
| 11 |
COPY ./requirements.txt /code/requirements.txt
|
| 12 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
|
| 14 |
+
# Create data directory with correct permissions
|
| 15 |
+
RUN mkdir -p /data && \
|
| 16 |
+
chmod -R 777 /data && \
|
| 17 |
+
chown -R 1000:1000 /data
|
| 18 |
+
|
| 19 |
# Copy the rest of the application
|
| 20 |
COPY . /code/
|
| 21 |
|
| 22 |
+
# Set code directory permissions
|
| 23 |
+
RUN chmod -R 777 /code && \
|
|
|
|
|
|
|
|
|
|
| 24 |
chown -R 1000:1000 /code
|
| 25 |
|
| 26 |
# Switch to non-root user
|
README.md
CHANGED
|
@@ -18,25 +18,27 @@ persistent_dir: ["/data"]
|
|
| 18 |
|
| 19 |
- 圓桌座位視覺化顯示
|
| 20 |
- 即時座位狀態更新
|
| 21 |
-
- 參與者資訊登記(暱稱、Email、FB連結)
|
| 22 |
-
-
|
| 23 |
|
| 24 |
-
##
|
| 25 |
|
| 26 |
-
|
| 27 |
-
- SQLite 資料庫
|
| 28 |
-
- Bootstrap 前端框架
|
| 29 |
-
- 部署於 Hugging Face Spaces
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
---
|
| 42 |
Hosted on 🤗 Hugging Face Spaces
|
|
|
|
| 18 |
|
| 19 |
- 圓桌座位視覺化顯示
|
| 20 |
- 即時座位狀態更新
|
| 21 |
+
- 參與者資訊登記(暱稱、Email、FB連結、自我介紹)
|
| 22 |
+
- 資料持久化存儲
|
| 23 |
|
| 24 |
+
## 部署說明
|
| 25 |
|
| 26 |
+
### Hugging Face Spaces 部署
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
1. 系統會自動使用 `/data` 目錄進行持久化存儲
|
| 29 |
+
2. 資料庫文件會保存在 `/data/event.db`
|
| 30 |
+
3. 重新部署時不會影響已存在的資料
|
| 31 |
|
| 32 |
+
### 本地開發
|
| 33 |
+
|
| 34 |
+
1. 本地開發時資料庫文件位於 `instance/event.db`
|
| 35 |
+
2. 確保資料目錄有正確的讀寫權限
|
| 36 |
+
|
| 37 |
+
## 注意事項
|
| 38 |
+
|
| 39 |
+
- 每次部署時會保留 `/data` 目錄中的資料
|
| 40 |
+
- 不要手動刪除或修改 `/data` 目錄
|
| 41 |
+
- 如需重置資料,請聯繫管理員
|
| 42 |
|
| 43 |
---
|
| 44 |
Hosted on 🤗 Hugging Face Spaces
|
app.py
CHANGED
|
@@ -20,7 +20,7 @@ if os.environ.get('SPACE_ID'): # 在 Hugging Face Spaces 環境中
|
|
| 20 |
os.makedirs('/data', exist_ok=True)
|
| 21 |
|
| 22 |
# 等待資料目錄就緒並確保權限正確
|
| 23 |
-
max_retries =
|
| 24 |
retry_count = 0
|
| 25 |
while retry_count < max_retries:
|
| 26 |
try:
|
|
@@ -35,6 +35,19 @@ if os.environ.get('SPACE_ID'): # 在 Hugging Face Spaces 環境中
|
|
| 35 |
# 檢查是否可寫
|
| 36 |
if os.access('/data', os.W_OK):
|
| 37 |
print("/data directory is writable")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
break
|
| 39 |
|
| 40 |
print(f"Waiting for /data directory to be writable... Attempt {retry_count + 1}/{max_retries}")
|
|
|
|
| 20 |
os.makedirs('/data', exist_ok=True)
|
| 21 |
|
| 22 |
# 等待資料目錄就緒並確保權限正確
|
| 23 |
+
max_retries = 30 # 增加重試次數
|
| 24 |
retry_count = 0
|
| 25 |
while retry_count < max_retries:
|
| 26 |
try:
|
|
|
|
| 35 |
# 檢查是否可寫
|
| 36 |
if os.access('/data', os.W_OK):
|
| 37 |
print("/data directory is writable")
|
| 38 |
+
# 檢查資料庫文件
|
| 39 |
+
if os.path.exists(db_path):
|
| 40 |
+
print(f"Database file exists at {db_path}")
|
| 41 |
+
if os.access(db_path, os.W_OK):
|
| 42 |
+
print("Database file is writable")
|
| 43 |
+
break
|
| 44 |
+
else:
|
| 45 |
+
print("Setting database file permissions...")
|
| 46 |
+
os.chmod(db_path, 0o666)
|
| 47 |
+
else:
|
| 48 |
+
print(f"Creating new database file at {db_path}")
|
| 49 |
+
open(db_path, 'a').close()
|
| 50 |
+
os.chmod(db_path, 0o666)
|
| 51 |
break
|
| 52 |
|
| 53 |
print(f"Waiting for /data directory to be writable... Attempt {retry_count + 1}/{max_retries}")
|