Skip to content

Commit 2e883e2

Browse files
author
SM_SAYEED
committed
redeployment survival improved
1 parent fc59bd3 commit 2e883e2

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

app.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pandas as pd
77
import numpy as np
88
import sqlite3
9+
import secrets
910

1011
from werkzeug.utils import secure_filename
1112
import datetime
@@ -15,22 +16,49 @@
1516
import io, base64, zipfile
1617
from typing import List, Dict, Optional
1718

18-
# ========== SETTINGS ==========
1919

20-
UPLOAD_FOLDER = 'uploads'
21-
DB_NAME = 'patterns-matter.db' # SQLite database file
22-
ADMIN_PASSWORD = 'IronMa1deN!'
20+
# ========== SETTINGS (Drive-only materials; DB persisted on Fly volume) ==========
21+
# Persist app state (SQLite DB, optional legacy uploads) on Fly's volume
22+
DATA_DIR = os.environ.get("DATA_DIR", "/data")
23+
os.makedirs(DATA_DIR, exist_ok=True)
2324

24-
ALLOWED_DATASET_EXTENSIONS = {'csv', 'npy'}
25-
ALLOWED_RESULTS_EXTENSIONS = {'jpg', 'jpeg', 'png', 'gif', 'pdf', 'docx'}
26-
ALLOWED_MUSIC_EXTENSIONS = {'mp3', 'wav', 'm4a', 'ogg', 'mp4'}
25+
# SQLite DB lives on the volume so admin history / catalog survive deploys
26+
DB_NAME = os.path.join(DATA_DIR, "patterns-matter.db")
2727

28-
app = Flask(__name__)
29-
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
30-
app.secret_key = 'IronMa1deN!'
28+
# Local uploads folder (not used for Drive materials, but harmless to keep)
29+
UPLOAD_FOLDER = os.path.join(DATA_DIR, "uploads")
30+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
31+
32+
ALLOWED_DATASET_EXTENSIONS = {"csv", "npy"}
33+
ALLOWED_RESULTS_EXTENSIONS = {"jpg", "jpeg", "png", "gif", "pdf", "docx"}
34+
ALLOWED_MUSIC_EXTENSIONS = {"mp3", "wav", "m4a", "ogg", "mp4"}
3135

36+
app = Flask(__name__)
37+
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
38+
39+
# ---------- Secrets: require in prod, friendly defaults in dev ----------
40+
IS_PROD = bool(os.getenv("FLY_APP_NAME"))
41+
42+
def _require_env(name: str) -> str:
43+
val = os.getenv(name)
44+
if not val:
45+
raise RuntimeError(f"Missing required environment variable: {name}")
46+
return val
47+
48+
if IS_PROD:
49+
# In production, these MUST be set via Fly secrets:
50+
# fly secrets set ADMIN_PASSWORD='...' FLASK_SECRET_KEY='...'
51+
ADMIN_PASSWORD = _require_env("ADMIN_PASSWORD")
52+
app.secret_key = _require_env("FLASK_SECRET_KEY")
53+
else:
54+
# Local dev fallbacks (or read from a local .env before this block)
55+
ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "devpassword")
56+
app.secret_key = os.getenv("FLASK_SECRET_KEY", "dev-secret-keep-local")
57+
58+
# Google Drive scope for the Service Account (secrets provided via Fly)
3259
GDRIVE_SCOPES = ["https://www.googleapis.com/auth/drive"]
3360

61+
3462
# ---------- Utility Functions ----------
3563

3664
def allowed_dataset_file(filename):

patterns-matter.db

-24 MB
Binary file not shown.

0 commit comments

Comments
 (0)