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__)
|
||||
|
||||
# Ensure instance directory exists
|
||||
# Ensure instance and database directories exist
|
||||
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
|
||||
app.config["SECRET_KEY"] = os.environ["FLASK_SECRET_KEY"]
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
# 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
|
||||
# Get database credentials from environment
|
||||
db_password = os.environ['DB_PASSWORD']
|
||||
# URL-encode all special characters including @ and $
|
||||
encoded_password = quote_plus(db_password, safe='')
|
||||
app.logger.info(f"Using database password: {'*' * len(db_password)}")
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = f"postgresql://flaskuser:{db_password}@db:5432/flaskdb"
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||
|
||||
db = SQLAlchemy(app)
|
||||
@ -32,11 +25,9 @@ db = SQLAlchemy(app)
|
||||
def init_db():
|
||||
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():
|
||||
db.create_all()
|
||||
print(f"Database created at {db_path}")
|
||||
print("Database initialized")
|
||||
|
||||
|
||||
login_manager = LoginManager(app)
|
||||
@ -46,7 +37,7 @@ login_manager.login_view = "login"
|
||||
class User(UserMixin, db.Model):
|
||||
id = db.Column(db.Integer, primary_key=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
|
||||
|
||||
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:
|
||||
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:
|
||||
build: .
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
ports:
|
||||
- "5001:5001"
|
||||
environment:
|
||||
- FLASK_ENV=production
|
||||
- FLASK_SECRET_KEY=${FLASK_SECRET_KEY}
|
||||
- SQLALCHEMY_DATABASE_URI=sqlite:////app/instance/database.db
|
||||
- DB_PASSWORD=${DB_PASSWORD}
|
||||
volumes:
|
||||
- ./instance:/app/instance
|
||||
command: >
|
||||
sh -c "flask init-db && gunicorn --bind 0.0.0.0:5001 --workers 4 app:app"
|
||||
command: sh -c "sleep 2 && 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