changed db to postgres with password stored in env
This commit is contained in:
parent
2844b4de4b
commit
86a07ad8bd
29
app.py
29
app.py
@ -6,22 +6,15 @@ import os
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# Ensure instance directory exists
|
app.config["SECRET_KEY"] = os.environ["FLASK_SECRET_KEY"]
|
||||||
# Ensure instance and database directories exist
|
from urllib.parse import quote_plus
|
||||||
app.config["SECRET_KEY"] = os.environ.get(
|
|
||||||
"FLASK_SECRET_KEY", "your-secret-key-here" # Fallback for development only
|
|
||||||
)
|
|
||||||
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("SQLALCHEMY_DATABASE_URI", "sqlite:///instance/database.db") # Read from environment
|
|
||||||
|
|
||||||
# Ensure database directory exists AFTER config is set
|
# Get database credentials from environment
|
||||||
with app.app_context():
|
db_password = os.environ['DB_PASSWORD']
|
||||||
db_path = app.config["SQLALCHEMY_DATABASE_URI"].replace("sqlite:///", "")
|
# URL-encode all special characters including @ and $
|
||||||
try:
|
encoded_password = quote_plus(db_password, safe='')
|
||||||
os.makedirs(os.path.dirname(db_path), exist_ok=True, mode=0o755)
|
app.logger.info(f"Using database password: {'*' * len(db_password)}")
|
||||||
print(f"Ensured database directory exists at {os.path.dirname(db_path)}")
|
app.config["SQLALCHEMY_DATABASE_URI"] = f"postgresql://flaskuser:{db_password}@db:5432/flaskdb"
|
||||||
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)
|
||||||
@ -32,11 +25,9 @@ db = SQLAlchemy(app)
|
|||||||
def init_db():
|
def init_db():
|
||||||
import os
|
import os
|
||||||
|
|
||||||
db_path = app.config["SQLALCHEMY_DATABASE_URI"].replace("sqlite:///", "")
|
|
||||||
os.makedirs(os.path.dirname(db_path), exist_ok=True, mode=0o755)
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
print(f"Database created at {db_path}")
|
print("Database initialized")
|
||||||
|
|
||||||
|
|
||||||
login_manager = LoginManager(app)
|
login_manager = LoginManager(app)
|
||||||
@ -46,7 +37,7 @@ login_manager.login_view = "login"
|
|||||||
class User(UserMixin, db.Model):
|
class User(UserMixin, db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
email = db.Column(db.String(100), unique=True)
|
email = db.Column(db.String(100), unique=True)
|
||||||
password = db.Column(db.String(100))
|
password = db.Column(db.String(200)) # Increased for password hash
|
||||||
|
|
||||||
|
|
||||||
@login_manager.user_loader
|
@login_manager.user_loader
|
||||||
|
|||||||
1
db_password.secret
Normal file
1
db_password.secret
Normal file
@ -0,0 +1 @@
|
|||||||
|
pg_5UP3r$3cr3t_P@ssw0rd!
|
||||||
@ -1,15 +1,43 @@
|
|||||||
version: '3.8'
|
version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
db:
|
||||||
|
image: "postgres:latest"
|
||||||
|
volumes:
|
||||||
|
- ./postgres_data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: flaskuser
|
||||||
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||||
|
POSTGRES_DB: flaskdb
|
||||||
|
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U flaskuser -d flaskdb"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
start_period: 10s
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
|
||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
ports:
|
ports:
|
||||||
- "5001:5001"
|
- "5001:5001"
|
||||||
environment:
|
environment:
|
||||||
- FLASK_ENV=production
|
- FLASK_ENV=production
|
||||||
- FLASK_SECRET_KEY=${FLASK_SECRET_KEY}
|
- FLASK_SECRET_KEY=${FLASK_SECRET_KEY}
|
||||||
- SQLALCHEMY_DATABASE_URI=sqlite:////app/instance/database.db
|
- DB_PASSWORD=${DB_PASSWORD}
|
||||||
volumes:
|
volumes:
|
||||||
- ./instance:/app/instance
|
- ./instance:/app/instance
|
||||||
command: >
|
command: sh -c "sleep 2 && flask init-db && gunicorn --bind 0.0.0.0:5001 --workers 4 app:app"
|
||||||
sh -c "flask init-db && gunicorn --bind 0.0.0.0:5001 --workers 4 app:app"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
|||||||
1
postgres_data/PG_VERSION
Normal file
1
postgres_data/PG_VERSION
Normal file
@ -0,0 +1 @@
|
|||||||
|
17
|
||||||
BIN
postgres_data/base/1/112
Normal file
BIN
postgres_data/base/1/112
Normal file
Binary file not shown.
BIN
postgres_data/base/1/113
Normal file
BIN
postgres_data/base/1/113
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1247
Normal file
BIN
postgres_data/base/1/1247
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1247_fsm
Normal file
BIN
postgres_data/base/1/1247_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1247_vm
Normal file
BIN
postgres_data/base/1/1247_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1249
Normal file
BIN
postgres_data/base/1/1249
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1249_fsm
Normal file
BIN
postgres_data/base/1/1249_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1249_vm
Normal file
BIN
postgres_data/base/1/1249_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1255
Normal file
BIN
postgres_data/base/1/1255
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1255_fsm
Normal file
BIN
postgres_data/base/1/1255_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1255_vm
Normal file
BIN
postgres_data/base/1/1255_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1259
Normal file
BIN
postgres_data/base/1/1259
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1259_fsm
Normal file
BIN
postgres_data/base/1/1259_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/1259_vm
Normal file
BIN
postgres_data/base/1/1259_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13402
Normal file
BIN
postgres_data/base/1/13402
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13402_fsm
Normal file
BIN
postgres_data/base/1/13402_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13402_vm
Normal file
BIN
postgres_data/base/1/13402_vm
Normal file
Binary file not shown.
0
postgres_data/base/1/13405
Normal file
0
postgres_data/base/1/13405
Normal file
BIN
postgres_data/base/1/13406
Normal file
BIN
postgres_data/base/1/13406
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13407
Normal file
BIN
postgres_data/base/1/13407
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13407_fsm
Normal file
BIN
postgres_data/base/1/13407_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13407_vm
Normal file
BIN
postgres_data/base/1/13407_vm
Normal file
Binary file not shown.
0
postgres_data/base/1/13410
Normal file
0
postgres_data/base/1/13410
Normal file
BIN
postgres_data/base/1/13411
Normal file
BIN
postgres_data/base/1/13411
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13412
Normal file
BIN
postgres_data/base/1/13412
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13412_fsm
Normal file
BIN
postgres_data/base/1/13412_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13412_vm
Normal file
BIN
postgres_data/base/1/13412_vm
Normal file
Binary file not shown.
0
postgres_data/base/1/13415
Normal file
0
postgres_data/base/1/13415
Normal file
BIN
postgres_data/base/1/13416
Normal file
BIN
postgres_data/base/1/13416
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13417
Normal file
BIN
postgres_data/base/1/13417
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13417_fsm
Normal file
BIN
postgres_data/base/1/13417_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/13417_vm
Normal file
BIN
postgres_data/base/1/13417_vm
Normal file
Binary file not shown.
0
postgres_data/base/1/13420
Normal file
0
postgres_data/base/1/13420
Normal file
BIN
postgres_data/base/1/13421
Normal file
BIN
postgres_data/base/1/13421
Normal file
Binary file not shown.
0
postgres_data/base/1/1417
Normal file
0
postgres_data/base/1/1417
Normal file
0
postgres_data/base/1/1418
Normal file
0
postgres_data/base/1/1418
Normal file
BIN
postgres_data/base/1/174
Normal file
BIN
postgres_data/base/1/174
Normal file
Binary file not shown.
BIN
postgres_data/base/1/175
Normal file
BIN
postgres_data/base/1/175
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2187
Normal file
BIN
postgres_data/base/1/2187
Normal file
Binary file not shown.
0
postgres_data/base/1/2224
Normal file
0
postgres_data/base/1/2224
Normal file
BIN
postgres_data/base/1/2228
Normal file
BIN
postgres_data/base/1/2228
Normal file
Binary file not shown.
0
postgres_data/base/1/2328
Normal file
0
postgres_data/base/1/2328
Normal file
0
postgres_data/base/1/2336
Normal file
0
postgres_data/base/1/2336
Normal file
BIN
postgres_data/base/1/2337
Normal file
BIN
postgres_data/base/1/2337
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2579
Normal file
BIN
postgres_data/base/1/2579
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2600
Normal file
BIN
postgres_data/base/1/2600
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2600_fsm
Normal file
BIN
postgres_data/base/1/2600_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2600_vm
Normal file
BIN
postgres_data/base/1/2600_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2601
Normal file
BIN
postgres_data/base/1/2601
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2601_fsm
Normal file
BIN
postgres_data/base/1/2601_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2601_vm
Normal file
BIN
postgres_data/base/1/2601_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2602
Normal file
BIN
postgres_data/base/1/2602
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2602_fsm
Normal file
BIN
postgres_data/base/1/2602_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2602_vm
Normal file
BIN
postgres_data/base/1/2602_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2603
Normal file
BIN
postgres_data/base/1/2603
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2603_fsm
Normal file
BIN
postgres_data/base/1/2603_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2603_vm
Normal file
BIN
postgres_data/base/1/2603_vm
Normal file
Binary file not shown.
0
postgres_data/base/1/2604
Normal file
0
postgres_data/base/1/2604
Normal file
BIN
postgres_data/base/1/2605
Normal file
BIN
postgres_data/base/1/2605
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2605_fsm
Normal file
BIN
postgres_data/base/1/2605_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2605_vm
Normal file
BIN
postgres_data/base/1/2605_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2606
Normal file
BIN
postgres_data/base/1/2606
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2606_fsm
Normal file
BIN
postgres_data/base/1/2606_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2606_vm
Normal file
BIN
postgres_data/base/1/2606_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2607
Normal file
BIN
postgres_data/base/1/2607
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2607_fsm
Normal file
BIN
postgres_data/base/1/2607_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2607_vm
Normal file
BIN
postgres_data/base/1/2607_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2608
Normal file
BIN
postgres_data/base/1/2608
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2608_fsm
Normal file
BIN
postgres_data/base/1/2608_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2608_vm
Normal file
BIN
postgres_data/base/1/2608_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2609
Normal file
BIN
postgres_data/base/1/2609
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2609_fsm
Normal file
BIN
postgres_data/base/1/2609_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2609_vm
Normal file
BIN
postgres_data/base/1/2609_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2610
Normal file
BIN
postgres_data/base/1/2610
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2610_fsm
Normal file
BIN
postgres_data/base/1/2610_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2610_vm
Normal file
BIN
postgres_data/base/1/2610_vm
Normal file
Binary file not shown.
0
postgres_data/base/1/2611
Normal file
0
postgres_data/base/1/2611
Normal file
BIN
postgres_data/base/1/2612
Normal file
BIN
postgres_data/base/1/2612
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2612_fsm
Normal file
BIN
postgres_data/base/1/2612_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2612_vm
Normal file
BIN
postgres_data/base/1/2612_vm
Normal file
Binary file not shown.
0
postgres_data/base/1/2613
Normal file
0
postgres_data/base/1/2613
Normal file
BIN
postgres_data/base/1/2615
Normal file
BIN
postgres_data/base/1/2615
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2615_fsm
Normal file
BIN
postgres_data/base/1/2615_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2615_vm
Normal file
BIN
postgres_data/base/1/2615_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2616
Normal file
BIN
postgres_data/base/1/2616
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2616_fsm
Normal file
BIN
postgres_data/base/1/2616_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2616_vm
Normal file
BIN
postgres_data/base/1/2616_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2617
Normal file
BIN
postgres_data/base/1/2617
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2617_fsm
Normal file
BIN
postgres_data/base/1/2617_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2617_vm
Normal file
BIN
postgres_data/base/1/2617_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2618
Normal file
BIN
postgres_data/base/1/2618
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2618_fsm
Normal file
BIN
postgres_data/base/1/2618_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2618_vm
Normal file
BIN
postgres_data/base/1/2618_vm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2619
Normal file
BIN
postgres_data/base/1/2619
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2619_fsm
Normal file
BIN
postgres_data/base/1/2619_fsm
Normal file
Binary file not shown.
BIN
postgres_data/base/1/2619_vm
Normal file
BIN
postgres_data/base/1/2619_vm
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user