From 9ebe251d46563d068b627efc5ca15db1f03ff1c1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 3 Oct 2024 20:35:01 +0200 Subject: [PATCH] Several Docker image improvements. - Reduced size of the Ubuntu image by removing some unneeded packages (docutils, manpages, babel, fonts, python-pil etc.) that take a lot of space. - Better self-documented docker-compose.yml. - Added reference to the registry.platypush.tech/platypush image in docker-compose.yml (README reference will follow). - Fixed grep condition in the Docker prepare script. - Pass `--no-deps` to `pip install platypush`. The dependencies of the application, now that `marshmallow_dataclasses` has been removed, are all available in the package managers of the supported images (with the exception for croniter in Alpine Linux for now), so they can all be installed via system package manager rather than pip. This also prevents Ubuntu builds from breaking because system-installed packages are being overwritten with pip-installed copies. --- docker-compose.yml | 54 +++++++++++++--------- platypush/install/docker/alpine.Dockerfile | 5 +- platypush/install/docker/debian.Dockerfile | 5 +- platypush/install/docker/fedora.Dockerfile | 11 ++--- platypush/install/docker/ubuntu.Dockerfile | 14 ++++-- 5 files changed, 50 insertions(+), 39 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index cff19ee7b8..a9ff67607e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,9 @@ services: platypush: - restart: "always" - command: - - platypush - # Comment --start-redis if you want to run an external Redis service - # In such case you'll also have to ensure that the appropriate Redis - # variables are set in the .env file, or the Redis configuration is - # passed in the config.yaml, or use the --redis-host and --redis-port - # command-line options - - --start-redis - - # Custom list of host devices that should be accessible to the container - - # e.g. an Arduino, an ESP-compatible microcontroller, a joystick etc. - # devices: - # - /dev/ttyUSB0 - - # Uncomment if you need plugins that require access to low-level hardware - # (e.g. Bluetooth BLE or GPIO/SPI/I2C) if access to individual devices is - # not enough or isn't practical - # privileged: true + # Replace the build section with the next line if instead of building the + # image from a local checkout you want to pull the latest base + # (Alpine-based) image from the remote registry + # image: "registry.platypush.tech/platypush:latest" build: context: . @@ -31,6 +16,25 @@ services: # Fedora base image # dockerfile: ./platypush/install/docker/fedora.Dockerfile + restart: "always" + command: + - platypush + - --redis-host + - redis + # Or, if you want to run Redis from the same container as Platypush, + # replace --redis-host redis with the line below + # - --start-redis + + # Custom list of host devices that should be accessible to the container - + # e.g. an Arduino, an ESP-compatible microcontroller, a joystick etc. + # devices: + # - /dev/ttyUSB0 + + # Uncomment if you need plugins that require access to low-level hardware + # (e.g. Bluetooth BLE or GPIO/SPI/I2C) if access to individual devices is + # not enough or isn't practical + # privileged: true + # Copy .env.example to .env and modify as needed # env_file: # - .env @@ -40,7 +44,13 @@ services: # expose it - "8008:8008" - volumes: - - /path/to/your/config.yaml:/etc/platypush - - /path/to/a/workdir:/var/lib/platypush + # volumes: + # Replace with a path that contains/will contain your config.yaml file + # - /path/to/your/config:/etc/platypush + # Replace with a path that contains/will contain your working directory + # - /path/to/a/workdir:/var/lib/platypush + # Optionally, use an external volume for the cache # - /path/to/a/cachedir:/var/cache/platypush + + redis: + image: redis diff --git a/platypush/install/docker/alpine.Dockerfile b/platypush/install/docker/alpine.Dockerfile index b15ef7e3b2..8e9f92374c 100644 --- a/platypush/install/docker/alpine.Dockerfile +++ b/platypush/install/docker/alpine.Dockerfile @@ -7,7 +7,7 @@ WORKDIR /var/lib/platypush RUN --mount=type=bind,source=.,target=/curdir \ apk update && \ # If the current directory is the Platypush repository, then we can copy the existing files \ - if grep 'name="platypush"' /curdir/pyproject.toml >/dev/null 2>&1; \ + if grep -E 'name\s*=\s*"platypush"' /curdir/pyproject.toml >/dev/null 2>&1; \ then \ cp -r /curdir /install; \ # Otherwise, we need to clone the repository \ @@ -18,10 +18,9 @@ RUN --mount=type=bind,source=.,target=/curdir \ RUN /install/platypush/install/scripts/alpine/install.sh && \ cd /install && \ - pip install -U --no-input --no-cache-dir . --break-system-packages && \ + pip install -U --no-input --no-cache-dir --no-deps . croniter --break-system-packages && \ rm -rf /install && \ rm -rf /root/.cache && \ - find / | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf && \ apk del gcc git && \ apk cache clean && \ rm -rf /var/cache/apk/* && \ diff --git a/platypush/install/docker/debian.Dockerfile b/platypush/install/docker/debian.Dockerfile index 346ee8c676..5f9c67359c 100644 --- a/platypush/install/docker/debian.Dockerfile +++ b/platypush/install/docker/debian.Dockerfile @@ -10,7 +10,7 @@ ENV DOCKER_CTX=1 RUN --mount=type=bind,source=.,target=/curdir \ apt update && \ # If the current directory is the Platypush repository, then we can copy the existing files \ - if grep 'name="platypush"' /curdir/pyproject.toml >/dev/null 2>&1; \ + if grep -E 'name\s*=\s*"platypush"' /curdir/pyproject.toml >/dev/null 2>&1; \ then \ cp -r /curdir /install; \ # Otherwise, we need to clone the repository \ @@ -21,10 +21,9 @@ RUN --mount=type=bind,source=.,target=/curdir \ RUN /install/platypush/install/scripts/debian/install.sh && \ cd /install && \ - pip install -U --no-input --no-cache-dir . --break-system-packages && \ + pip install -U --no-input --no-cache-dir --no-deps . --break-system-packages && \ rm -rf /install && \ rm -rf /root/.cache && \ - find / | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf && \ apt remove -y git build-essential && \ rm -rf /var/lib/apt/lists/* && \ apt autoclean -y && \ diff --git a/platypush/install/docker/fedora.Dockerfile b/platypush/install/docker/fedora.Dockerfile index e028e03df7..67e46801aa 100644 --- a/platypush/install/docker/fedora.Dockerfile +++ b/platypush/install/docker/fedora.Dockerfile @@ -7,20 +7,19 @@ ENV DOCKER_CTX=1 RUN --mount=type=bind,source=.,target=/curdir \ # If the current directory is the Platypush repository, then we can copy the existing files \ - if grep 'name="platypush"' /curdir/pyproject.toml >/dev/null 2>&1; \ + if grep -E 'name\s*=\s*"platypush"' /curdir/pyproject.toml >/dev/null 2>&1; \ then \ cp -r /curdir /install; \ # Otherwise, we need to clone the repository \ else \ dnf install -y git && \ git clone https://github.com/blacklight/platypush.git /install; \ - fi + fi; \ + dnf install -y https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm -# Enable the RPM Fusion repository -RUN dnf install -y https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm && \ - /install/platypush/install/scripts/fedora/install.sh && \ +RUN /install/platypush/install/scripts/fedora/install.sh && \ cd /install && \ - pip install -U --no-input --no-cache-dir . --break-system-packages && \ + pip install -U --no-input --no-cache-dir --no-deps . --break-system-packages && \ rm -rf /install && \ rm -rf /root/.cache && \ dnf remove -y build-essential git && \ diff --git a/platypush/install/docker/ubuntu.Dockerfile b/platypush/install/docker/ubuntu.Dockerfile index d03210487f..1442e8ba0c 100644 --- a/platypush/install/docker/ubuntu.Dockerfile +++ b/platypush/install/docker/ubuntu.Dockerfile @@ -10,7 +10,7 @@ ENV DOCKER_CTX=1 RUN --mount=type=bind,source=.,target=/curdir \ apt update && \ # If the current directory is the Platypush repository, then we can copy the existing files \ - if grep 'name="platypush"' /curdir/pyproject.toml >/dev/null 2>&1; \ + if grep -E 'name\s*=\s*"platypush"' /curdir/pyproject.toml >/dev/null 2>&1; \ then \ cp -r /curdir /install; \ # Otherwise, we need to clone the repository \ @@ -21,12 +21,16 @@ RUN --mount=type=bind,source=.,target=/curdir \ RUN /install/platypush/install/scripts/debian/install.sh && \ cd /install && \ - pip install -U --no-input --no-cache-dir . --break-system-packages && \ + pip install -U --no-input --no-cache-dir --no-deps . --break-system-packages && \ rm -rf /install && \ rm -rf /root/.cache && \ - find / | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf && \ - apt remove -y git build-essential && \ - rm -rf /var/lib/apt/lists/* && \ + apt remove -y git \ + build-essential \ + docutils-common \ + fonts-dejavu-mono \ + manpages \ + manpages-dev \ + python-babel-localedata && \ apt autoclean -y && \ apt autoremove -y && \ apt clean && \