diff --git a/Makefile b/Makefile index 02469ec..33bc825 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ -IP ?= 192.168.1.195 -REMOTE_USER ?= pi -REMOTE = $(REMOTE_USER)@$(IP) -DEST ?= /home/$(REMOTE_USER)/projet-agreg +IP ?= 192.168.1.195 +REMOTE_USER ?= pi +REMOTE = $(REMOTE_USER)@$(IP) +SERVER = server +GATEWAY = lora-gateway +DEST ?= /home/$(REMOTE_USER)/projet-agreg RSYNC_OPTS = -arvz --delete --exclude='__pycache__' --exclude='*.pyc' --exclude='.env' --exclude='.venv' --exclude='Makefile' --exclude='.git' --exclude='.vscode' --exclude='.gitignore' .PHONY: deploy deploy-gw deploy-app clean-app clean-gw clean-all @@ -11,29 +13,29 @@ deploy-all: deploy-gw deploy-app deploy-app: @echo "Déploiement sur $(REMOTE):$(DEST)" ssh $(REMOTE) "mkdir -p $(DEST)" - rsync $(RSYNC_OPTS) app $(REMOTE):$(DEST) + rsync $(RSYNC_OPTS) $(SERVER) $(REMOTE):$(DEST) @echo "Déploiement terminé" - ssh $(REMOTE) "cd $(DEST)/app && docker compose up -d --build" + ssh $(REMOTE) "cd $(DEST)/$(SERVER) && docker compose up -d --build" @echo "Services redémarrés" deploy-gw: @echo "Déploiement sur $(REMOTE):$(DEST)" ssh $(REMOTE) "mkdir -p $(DEST)" - rsync $(RSYNC_OPTS) lora-gateway $(REMOTE):$(DEST) + rsync $(RSYNC_OPTS) $(GATEWAY) $(REMOTE):$(DEST) @echo "Déploiement terminé" - ssh $(REMOTE) "cd $(DEST)/lora-gateway && docker compose up -d" + ssh $(REMOTE) "cd $(DEST)/$(GATEWAY) && docker compose up -d" @echo "Services redémarrés" clean-app: - @echo "Nettoyage de l'app sur $(REMOTE):$(DEST)/app" - ssh $(REMOTE) "cd $(DEST)/app && docker compose down --volumes --remove-orphans || true" - ssh $(REMOTE) "rm -rf $(DEST)/app" + @echo "Nettoyage de l'app sur $(REMOTE):$(DEST)/$(SERVER)" + ssh $(REMOTE) "cd $(DEST)/$(SERVER) && docker compose down --volumes --remove-orphans || true" + ssh $(REMOTE) "rm -rf $(DEST)/$(SERVER)" @echo "Nettoyage de l'application terminé" clean-gw: - @echo "Nettoyage de la gateway sur $(REMOTE):$(DEST)/lora-gateway" - ssh $(REMOTE) "cd $(DEST)/lora-gateway && docker compose down --volumes --remove-orphans || true" - ssh $(REMOTE) "rm -rf $(DEST)/lora-gateway" + @echo "Nettoyage de la gateway sur $(REMOTE):$(DEST)/$(GATEWAY)" + ssh $(REMOTE) "cd $(DEST)/$(GATEWAY) && docker compose down --volumes --remove-orphans || true" + ssh $(REMOTE) "rm -rf $(DEST)/$(GATEWAY)" @echo "Nettoyage de la gateway terminé" clean-all: clean-app clean-gw diff --git a/server/app/.dockerignore b/server/app/.dockerignore new file mode 100644 index 0000000..1d1fe94 --- /dev/null +++ b/server/app/.dockerignore @@ -0,0 +1 @@ +Dockerfile \ No newline at end of file diff --git a/app/consumer/Dockerfile b/server/app/Dockerfile similarity index 71% rename from app/consumer/Dockerfile rename to server/app/Dockerfile index 757c3ee..090b299 100644 --- a/app/consumer/Dockerfile +++ b/server/app/Dockerfile @@ -2,5 +2,5 @@ FROM python:3.13-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt -COPY ./src/. /app/ -CMD ["python", "main.py"] \ No newline at end of file +COPY . . +CMD ["python", "consumer.py"] \ No newline at end of file diff --git a/app/consumer/src/adapters/__init__.py b/server/app/adapters/__init__.py similarity index 100% rename from app/consumer/src/adapters/__init__.py rename to server/app/adapters/__init__.py diff --git a/app/consumer/src/adapters/mqtt.py b/server/app/adapters/mqtt.py similarity index 95% rename from app/consumer/src/adapters/mqtt.py rename to server/app/adapters/mqtt.py index 4dd66ef..9852ed2 100644 --- a/app/consumer/src/adapters/mqtt.py +++ b/server/app/adapters/mqtt.py @@ -8,8 +8,8 @@ from paho.mqtt.enums import CallbackAPIVersion from paho.mqtt.properties import Properties from paho.mqtt.reasoncodes import ReasonCode -from exceptions import MessageBrokerError, InfrastructureError -from entities import UplinkEvent +from domain.exceptions import MessageBrokerError, InfrastructureError +from domain.entities import UplinkEvent from ports import MessageBroker log = logging.getLogger(__name__) diff --git a/app/consumer/src/adapters/postgres.py b/server/app/adapters/postgres.py similarity index 96% rename from app/consumer/src/adapters/postgres.py rename to server/app/adapters/postgres.py index 73b4f29..cb0a596 100644 --- a/app/consumer/src/adapters/postgres.py +++ b/server/app/adapters/postgres.py @@ -4,7 +4,7 @@ import time import psycopg2 from psycopg2.extensions import connection from ports import DeviceRepository, ReadingRepository -from exceptions import DatabaseConnectionError, DatabaseError +from domain.exceptions import DatabaseConnectionError, DatabaseError log = logging.getLogger(__name__) diff --git a/app/consumer/src/main.py b/server/app/consumer.py similarity index 100% rename from app/consumer/src/main.py rename to server/app/consumer.py diff --git a/app/consumer/src/services/__init__.py b/server/app/domain/__init__.py similarity index 100% rename from app/consumer/src/services/__init__.py rename to server/app/domain/__init__.py diff --git a/app/consumer/src/entities/__init__.py b/server/app/domain/entities/__init__.py similarity index 100% rename from app/consumer/src/entities/__init__.py rename to server/app/domain/entities/__init__.py diff --git a/app/consumer/src/entities/uplink_event.py b/server/app/domain/entities/uplink_event.py similarity index 100% rename from app/consumer/src/entities/uplink_event.py rename to server/app/domain/entities/uplink_event.py diff --git a/app/consumer/src/exceptions.py b/server/app/domain/exceptions.py similarity index 100% rename from app/consumer/src/exceptions.py rename to server/app/domain/exceptions.py diff --git a/app/consumer/src/ports/__init__.py b/server/app/ports/__init__.py similarity index 100% rename from app/consumer/src/ports/__init__.py rename to server/app/ports/__init__.py diff --git a/app/consumer/src/ports/device_repository.py b/server/app/ports/device_repository.py similarity index 100% rename from app/consumer/src/ports/device_repository.py rename to server/app/ports/device_repository.py diff --git a/app/consumer/src/ports/message_broker.py b/server/app/ports/message_broker.py similarity index 87% rename from app/consumer/src/ports/message_broker.py rename to server/app/ports/message_broker.py index af42035..5d5c65f 100644 --- a/app/consumer/src/ports/message_broker.py +++ b/server/app/ports/message_broker.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from typing import Callable -from entities import UplinkEvent +from domain.entities import UplinkEvent class MessageBroker(ABC): @abstractmethod diff --git a/app/consumer/src/ports/reading_repository.py b/server/app/ports/reading_repository.py similarity index 100% rename from app/consumer/src/ports/reading_repository.py rename to server/app/ports/reading_repository.py diff --git a/app/consumer/requirements.txt b/server/app/requirements.txt similarity index 100% rename from app/consumer/requirements.txt rename to server/app/requirements.txt diff --git a/server/app/services/__init__.py b/server/app/services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/consumer/src/services/uplink_service.py b/server/app/services/uplink_service.py similarity index 93% rename from app/consumer/src/services/uplink_service.py rename to server/app/services/uplink_service.py index 40ace3a..65e7fec 100644 --- a/app/consumer/src/services/uplink_service.py +++ b/server/app/services/uplink_service.py @@ -1,6 +1,6 @@ import logging from ports import DeviceRepository, ReadingRepository -from entities import UplinkEvent +from domain.entities import UplinkEvent log = logging.getLogger(__name__) diff --git a/app/docker-compose.yml b/server/docker-compose.yml similarity index 90% rename from app/docker-compose.yml rename to server/docker-compose.yml index 9b6e15b..d02adbb 100644 --- a/app/docker-compose.yml +++ b/server/docker-compose.yml @@ -1,6 +1,6 @@ services: consumer: - build: ./consumer + build: ./app restart: unless-stopped networks: - lora-gateway_mqtt @@ -10,7 +10,7 @@ services: image: postgres:18-alpine restart: unless-stopped volumes: - - ./consumer/initdb:/docker-entrypoint-initdb.d:ro + - ./initdb:/docker-entrypoint-initdb.d:ro - db:/var/lib/postgresql networks: - database diff --git a/app/consumer/initdb/01_schema.sql b/server/initdb/01_schema.sql similarity index 100% rename from app/consumer/initdb/01_schema.sql rename to server/initdb/01_schema.sql diff --git a/app/consumer/initdb/02_dummy_data.sql b/server/initdb/02_dummy_data.sql similarity index 100% rename from app/consumer/initdb/02_dummy_data.sql rename to server/initdb/02_dummy_data.sql diff --git a/app/servers.json b/server/servers.json similarity index 100% rename from app/servers.json rename to server/servers.json