changed db to more relative path
This commit is contained in:
parent
6cbbc36410
commit
2844b4de4b
17
app.py
17
app.py
@ -5,12 +5,23 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# Ensure instance directory exists
|
||||||
|
# Ensure instance and database directories exist
|
||||||
app.config["SECRET_KEY"] = os.environ.get(
|
app.config["SECRET_KEY"] = os.environ.get(
|
||||||
"FLASK_SECRET_KEY", "your-secret-key-here" # Fallback for development only
|
"FLASK_SECRET_KEY", "your-secret-key-here" # Fallback for development only
|
||||||
)
|
)
|
||||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(
|
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("SQLALCHEMY_DATABASE_URI", "sqlite:///instance/database.db") # Read from environment
|
||||||
os.path.abspath(os.path.dirname(__file__)), "instance/database.db"
|
|
||||||
)
|
# Ensure database directory exists AFTER config is set
|
||||||
|
with app.app_context():
|
||||||
|
db_path = app.config["SQLALCHEMY_DATABASE_URI"].replace("sqlite:///", "")
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(db_path), exist_ok=True, mode=0o755)
|
||||||
|
print(f"Ensured database directory exists at {os.path.dirname(db_path)}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error creating database directory: {str(e)}")
|
||||||
|
raise
|
||||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||||
|
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
|
|||||||
@ -7,7 +7,9 @@ services:
|
|||||||
- "5001:5001"
|
- "5001:5001"
|
||||||
environment:
|
environment:
|
||||||
- FLASK_ENV=production
|
- FLASK_ENV=production
|
||||||
- FLASK_SECRET_KEY=${FLASK_SECRET_KEY} # Required - set in .env file
|
- FLASK_SECRET_KEY=${FLASK_SECRET_KEY}
|
||||||
- SQLALCHEMY_DATABASE_URI=sqlite:////app/instance/database.db
|
- SQLALCHEMY_DATABASE_URI=sqlite:////app/instance/database.db
|
||||||
volumes:
|
volumes:
|
||||||
- ./instance:/app/instance
|
- ./instance:/app/instance
|
||||||
|
command: >
|
||||||
|
sh -c "flask init-db && gunicorn --bind 0.0.0.0:5001 --workers 4 app:app"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user