Ver Fonte

fix mqttt + restart

tuanchris há 2 meses atrás
pai
commit
198d445231
3 ficheiros alterados com 28 adições e 3 exclusões
  1. 10 0
      Dockerfile
  2. 5 1
      docker-compose.yml
  3. 13 2
      modules/update/update_manager.py

+ 10 - 0
Dockerfile

@@ -15,8 +15,18 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
         python3-dev python3-pip \
         python3-dev python3-pip \
         libgpiod2 libgpiod-dev \
         libgpiod2 libgpiod-dev \
         scons \
         scons \
+        systemd \
+        # Docker CLI for container self-restart/update
+        ca-certificates curl gnupg \
     && pip install --upgrade pip \
     && pip install --upgrade pip \
     && pip install --no-cache-dir -r requirements.txt \
     && pip install --no-cache-dir -r requirements.txt \
+    # Install Docker CLI from official Docker repo
+    && install -m 0755 -d /etc/apt/keyrings \
+    && curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
+    && chmod a+r /etc/apt/keyrings/docker.gpg \
+    && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" > /etc/apt/sources.list.d/docker.list \
+    && apt-get update \
+    && apt-get install -y --no-install-recommends docker-ce-cli docker-compose-plugin \
     && apt-get purge -y gcc g++ make scons \
     && apt-get purge -y gcc g++ make scons \
     && rm -rf /var/lib/apt/lists/*
     && rm -rf /var/lib/apt/lists/*
 
 

+ 5 - 1
docker-compose.yml

@@ -6,12 +6,16 @@ services:
     # ports:
     # ports:
     #   - "8080:8080" # Map port 8080 of the container to 8080 of the host (access via http://localhost:8080)
     #   - "8080:8080" # Map port 8080 of the container to 8080 of the host (access via http://localhost:8080)
     network_mode: "host" # Use host network for device access
     network_mode: "host" # Use host network for device access
+    environment:
+      # Pass host project directory for Docker commands from inside container
+      - HOST_PROJECT_DIR=${PWD}
     volumes:
     volumes:
       - .:/app
       - .:/app
+      # Mount Docker socket to allow container to restart itself
+      - /var/run/docker.sock:/var/run/docker.sock
       # Mount timezone file from host for Still Sands scheduling
       # Mount timezone file from host for Still Sands scheduling
       - /etc/timezone:/etc/host-timezone:ro
       - /etc/timezone:/etc/host-timezone:ro
       # Mount systemd to allow host shutdown
       # Mount systemd to allow host shutdown
-      - /bin/systemctl:/bin/systemctl:ro
       - /run/systemd/system:/run/systemd/system:ro
       - /run/systemd/system:/run/systemd/system:ro
       - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro
       - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro
       - /sys/fs/cgroup:/sys/fs/cgroup:ro
       - /sys/fs/cgroup:/sys/fs/cgroup:ro

+ 13 - 2
modules/update/update_manager.py

@@ -76,8 +76,19 @@ def update_software():
         return False, error_msg, error_log
         return False, error_msg, error_log
 
 
     run_command(["git", "checkout", latest_remote_tag, '--force'], f"Failed to checkout version {latest_remote_tag}")
     run_command(["git", "checkout", latest_remote_tag, '--force'], f"Failed to checkout version {latest_remote_tag}")
-    run_command(["docker", "compose", "pull"], "Failed to fetch Docker containers")
-    run_command(["docker", "compose", "up", "-d"], "Failed to restart Docker containers")
+
+    # Get host project directory for docker compose commands
+    # When running inside a container, we need to use the host path for docker compose
+    host_project_dir = os.environ.get("HOST_PROJECT_DIR")
+    if host_project_dir:
+        compose_cmd = ["docker", "compose", "-f", f"{host_project_dir}/docker-compose.yml"]
+        logger.info(f"Using host project directory: {host_project_dir}")
+    else:
+        compose_cmd = ["docker", "compose"]
+        logger.warning("HOST_PROJECT_DIR not set, using default docker compose")
+
+    run_command(compose_cmd + ["pull"], "Failed to fetch Docker containers")
+    run_command(compose_cmd + ["up", "-d"], "Failed to restart Docker containers")
 
 
     update_status = check_git_updates()
     update_status = check_git_updates()