Skip to content

Commit

Permalink
Sauvegarde
Browse files Browse the repository at this point in the history
  • Loading branch information
ingcloud-fr committed Aug 1, 2024
1 parent 032eb55 commit 5d9cf22
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 383 deletions.
10 changes: 10 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Nom de base de données
DB_NAME=
# Utilisateur
DB_USER=
# Mot de passe
DB_PASSWORD=
# Host Mysql
DB_HOST=
# Clé sécrète generée avec
SECRET_KEY=
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY . .

# Set environment variables
ENV FLASK_APP=app.py
#ENV FLASK_APP=app.py

# Expose port
EXPOSE 5000
Expand Down
179 changes: 0 additions & 179 deletions app copy.py

This file was deleted.

8 changes: 8 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
}

SECRET_KEY = os.getenv('SECRET_KEY', 'your_secret_key')


# Debugging print statements
print(f"DB_HOST={db_config['host']}")
print(f"DB_USER={db_config['user']}")
print(f"DB_PASSWORD={db_config['password']}")
print(f"DB_NAME={db_config['database']}")
print(f"SECRET_KEY={SECRET_KEY}")
32 changes: 12 additions & 20 deletions initialize_db.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
# initialize_db.py
from dotenv import load_dotenv
import os

import time
import mysql.connector
from app import db, app
load_dotenv()

def wait_for_db():
while True:
try:
conn = mysql.connector.connect(
host=app.config['SQLALCHEMY_DATABASE_URI'].split('@')[1].split('/')[0].split(':')[0],
user=app.config['SQLALCHEMY_DATABASE_URI'].split('//')[1].split(':')[0],
password=app.config['SQLALCHEMY_DATABASE_URI'].split(':')[2].split('@')[0]
)
conn.close()
break
except mysql.connector.Error as err:
print("Waiting for MySQL to be ready...")
time.sleep(5)
print(f"DB_HOST={os.getenv('DB_HOST')}")
print(f"DB_USER={os.getenv('DB_USER')}")
print(f"DB_PASSWORD={os.getenv('DB_PASSWORD')}")
print(f"DB_NAME={os.getenv('DB_NAME')}")
print(f"SECRET_KEY={os.getenv('SECRET_KEY')}")

wait_for_db()
from app import db
from config import db_config

with app.app_context():
db.create_all()
print(f"DB Config: {db_config}")

db.create_all()
Loading

0 comments on commit 5d9cf22

Please sign in to comment.