diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3c7112a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +venv/ +__pycache__/ +*.pyc +.env +.git/ +.gitignore +*.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index efb9005..3958e10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN pip install --no-cache-dir -r requirements.txt # On copie tout le reste du projet (tes HTML, CSS, app.py, etc.) COPY . . -# On expose le port 5000 pour ton Mac +# On expose le port 5000 du conteneur EXPOSE 5000 # La commande pour démarrer le serveur diff --git a/config.py b/config.py index 0720195..4f24736 100644 --- a/config.py +++ b/config.py @@ -2,7 +2,7 @@ import os class Config: DB_HOST = os.environ.get("DB_HOST", "localhost") - DB_PORT = os.environ.get("DB_PORT", "5433") + DB_PORT = os.environ.get("DB_PORT", "5432") DB_NAME = os.environ.get("DB_NAME", "ecocharge") DB_USER = os.environ.get("DB_USER", "postgres") DB_PASSWORD = os.environ.get("DB_PASSWORD", "Safouane2005#") diff --git a/create_admin.py b/create_admin.py index 116612a..a21f3b2 100644 --- a/create_admin.py +++ b/create_admin.py @@ -1,11 +1,11 @@ import psycopg2 from werkzeug.security import generate_password_hash -DB_HOST = "localhost" -DB_PORT = "5433" +DB_HOST = "db" +DB_PORT = "5432" DB_NAME = "ecocharge" -DB_USER = "postgres" -DB_PASSWORD = "Safouane2005#" +DB_USER = "ecocharge_user" +DB_PASSWORD = "ecocharge_password" USERNAME = "admin" PLAIN_PASSWORD = "admin123" diff --git a/docker-compose.yml b/docker-compose.yml index 1ecd91d..23dbbdd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,30 +2,36 @@ services: db: image: postgres:15-alpine container_name: ecocharge_db + restart: unless-stopped environment: POSTGRES_USER: ecocharge_user POSTGRES_PASSWORD: ecocharge_password POSTGRES_DB: ecocharge - ports: - - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data - ./database.sql:/docker-entrypoint-initdb.d/init.sql + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ecocharge_user -d ecocharge"] + interval: 5s + timeout: 5s + retries: 10 web: build: . container_name: ecocharge_web + restart: unless-stopped ports: - "5001:5000" depends_on: - - db + db: + condition: service_healthy environment: - - DB_HOST=db - - DB_PORT=5432 - - DB_NAME=ecocharge - - DB_USER=ecocharge_user - - DB_PASSWORD=ecocharge_password - - SECRET_KEY=super_cle_secrete_projet + DB_HOST: db + DB_PORT: 5432 + DB_NAME: ecocharge + DB_USER: ecocharge_user + DB_PASSWORD: ecocharge_password + SECRET_KEY: super_cle_secrete_projet volumes: postgres_data: \ No newline at end of file diff --git a/static/script.js b/static/script.js index 0c85eaa..23bce78 100644 --- a/static/script.js +++ b/static/script.js @@ -301,7 +301,8 @@ async function fetchDatabaseData() { humEl.innerText = data.humidity_ext !== null ? Math.floor(data.humidity_ext) : "--"; if (data.battery_level !== null) { - updateBattery(Math.floor(data.battery_level), data.battery_alert); + const batteryAlert = data.battery_alert === true || data.battery_alert === "true" || data.battery_alert === 1 || data.battery_alert === "1"; +updateBattery(Math.floor(data.battery_level), batteryAlert ? "Alerte batterie" : null); } updateSolar( @@ -349,6 +350,6 @@ fetchHistoryData(); checkSystemStatus(); setInterval(fetchRealWeather, 900000); -setInterval(fetchDatabaseData, 3000); -setInterval(fetchHistoryData, 5000); -setInterval(checkSystemStatus, 1000); \ No newline at end of file +setInterval(fetchDatabaseData, 10000); +setInterval(fetchHistoryData, 30000); +setInterval(checkSystemStatus, 10000); \ No newline at end of file