From 1c3f0135f3533a8ce9ba2ad4e6765b80cb53c3e2 Mon Sep 17 00:00:00 2001 From: Lysann Tranvouez Date: Fri, 9 Jan 2026 21:47:47 +0100 Subject: [PATCH] turn into normal docker image (alpine) instead of hass-addon --- .devcontainer/Dockerfile | 60 --------------------- .devcontainer/devcontainer.json | 27 ---------- plejd/Dockerfile | 51 +++--------------- plejd/build.yaml | 6 --- plejd/entrypoint.sh | 39 ++++++++++++++ plejd/options.json.template | 14 +++++ plejd/rootfs/etc/cont-init.d/10-plejd-perms | 4 -- plejd/rootfs/etc/services.d/plejd/run | 14 ----- plejd/rootfs/usr/bin/plejd.sh | 5 -- repository.json | 5 -- 10 files changed, 61 insertions(+), 164 deletions(-) delete mode 100644 .devcontainer/Dockerfile delete mode 100644 .devcontainer/devcontainer.json delete mode 100644 plejd/build.yaml create mode 100644 plejd/entrypoint.sh create mode 100644 plejd/options.json.template delete mode 100755 plejd/rootfs/etc/cont-init.d/10-plejd-perms delete mode 100755 plejd/rootfs/etc/services.d/plejd/run delete mode 100755 plejd/rootfs/usr/bin/plejd.sh delete mode 100644 repository.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index 2ba13bc..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,60 +0,0 @@ -#------------------------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. -#------------------------------------------------------------------------------------------------------------- - -FROM node:12 - -# Avoid warnings by switching to noninteractive -ENV DEBIAN_FRONTEND=noninteractive - -# The node image includes a non-root user with sudo access. Use the "remoteUser" -# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs -# will be updated to match your local UID/GID (when using the dockerFile property). -# See https://aka.ms/vscode-remote/containers/non-root-user for details. -ARG USERNAME=node -ARG USER_UID=1000 -ARG USER_GID=$USER_UID - -# Configure apt and install packages -RUN apt-get update \ - && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ - # - # Verify git and needed tools are installed - && apt-get -y install git iproute2 procps \ - && apt-get -y install libdbus-1-dev libglib2.0-dev \ - # - # Remove outdated yarn from /opt and install via package - # so it can be easily updated via apt-get upgrade yarn - && rm -rf /opt/yarn-* \ - && rm -f /usr/local/bin/yarn \ - && rm -f /usr/local/bin/yarnpkg \ - && apt-get install -y curl apt-transport-https lsb-release \ - && curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \ - && echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ - && apt-get update \ - && apt-get -y install --no-install-recommends yarn \ - # - # Install eslint globally - && npm install -g eslint \ - # - # [Optional] Update a non-root user to UID/GID if needed. - && if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \ - groupmod --gid $USER_GID $USERNAME \ - && usermod --uid $USER_UID --gid $USER_GID $USERNAME \ - && chown -R $USER_UID:$USER_GID /home/$USERNAME; \ - fi \ - # [Optional] Add add sudo support for non-root user - && apt-get install -y sudo \ - && echo node ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ - && chmod 0440 /etc/sudoers.d/$USERNAME \ - # - # Clean up - && apt-get autoremove -y \ - && apt-get clean -y \ - && rm -rf /var/lib/apt/lists/* - -RUN npm install -g node-gyp - -# Switch back to dialog for any ad-hoc use of apt-get -ENV DEBIAN_FRONTEND=dialog diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 2884571..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,27 +0,0 @@ -// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at -// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/javascript-node-12 -{ - "name": "Node.js 12", - "dockerFile": "Dockerfile", - - // Use 'settings' to set *default* container specific settings.json values on container create. - // You can edit these settings after create using File > Preferences > Settings > Remote. - "settings": { - "terminal.integrated.shell.linux": "/bin/bash" - }, - - // Use 'appPort' to create a container with published ports. If the port isn't working, be sure - // your server accepts connections from all interfaces (0.0.0.0 or '*'), not just localhost. - // "appPort": [], - - // Uncomment the next line to run commands after the container is created. - // "postCreateCommand": "yarn install", - - // Uncomment the next line to have VS Code connect as an existing non-root user in the container. - // On Linux, by default, the container user's UID/GID will be updated to match your local user. See - // https://aka.ms/vscode-remote/containers/non-root for details on adding a non-root user if none exist. - // "remoteUser": "node", - - // Add the IDs of extensions you want installed when the container is created in the array below. - "extensions": ["dbaeumer.vscode-eslint"] -} diff --git a/plejd/Dockerfile b/plejd/Dockerfile index d51b9d8..98186a8 100644 --- a/plejd/Dockerfile +++ b/plejd/Dockerfile @@ -1,25 +1,7 @@ -# To specify the base image version, edit build.yaml -# Specifying BUILD_FROM=image:version in this file doesn't work -ARG BUILD_FROM -FROM $BUILD_FROM +FROM alpine:3.23.2 ENV LANG=C.UTF-8 -# Instruct npm to run lifecycle scripts (like preinstall, install, postinstall) -# as the root user, instead of trying to downgrade permissions. -ENV NPM_CONFIG_UNSAFE_PERM=true - -# Set shell -SHELL ["/bin/bash", "-o", "pipefail", "-c"] - -# Copy data for add-on -COPY ./*.js /plejd/ -COPY ./config.json /plejd/ -COPY ./package.json /plejd/ - -ARG BUILD_ARCH - -# Install Node RUN set -eux; \ apk add --no-cache --virtual .build-dependencies \ g++ \ @@ -39,35 +21,18 @@ RUN set -eux; \ dbus-dev \ glib-dev +COPY ./package.json /plejd/ WORKDIR /plejd RUN npm install \ --no-audit \ --no-update-notifier \ --unsafe-perm -# Copy root filesystem -COPY rootfs / -# Ensure runtime scripts remain executable even if modes were lost in the source checkout -RUN set -eux; \ - chmod 0755 /etc/services.d/plejd/run /etc/cont-init.d/10-plejd-perms /usr/bin/plejd.sh +COPY ./*.js /plejd/ +COPY ./config.json /plejd/ -# Build arguments -ARG BUILD_DATE -ARG BUILD_REF -ARG BUILD_VERSION +COPY ./entrypoint.sh /plejd/ +COPY ./options.json.template /plejd/ +RUN chmod a+x /plejd/entrypoint.sh -# Labels -LABEL \ - io.hass.name="Plejd" \ - io.hass.description="Adds support for the Swedish home automation devices from Plejd." \ - io.hass.arch="${BUILD_ARCH}" \ - io.hass.type="addon" \ - io.hass.version=${BUILD_VERSION} \ - maintainer="Marcus Westin " \ - org.label-schema.description="Adds support for the Swedish home automation devices from Plejd." \ - org.label-schema.build-date=${BUILD_DATE} \ - org.label-schema.name="Plejd" \ - org.label-schema.schema-version="1.0" \ - org.label-schema.usage="https://github.com/icanos/hassio-plejd/tree/master/README.md" \ - org.label-schema.vcs-ref=${BUILD_REF} \ - org.label-schema.vcs-url="https://github.com/icanos/hassio-plejd" +ENTRYPOINT ["/bin/sh", "/plejd/entrypoint.sh"] diff --git a/plejd/build.yaml b/plejd/build.yaml deleted file mode 100644 index 7a1e009..0000000 --- a/plejd/build.yaml +++ /dev/null @@ -1,6 +0,0 @@ -build_from: - armhf: ghcr.io/hassio-addons/base/armhf:18.2.0 - armv7: ghcr.io/hassio-addons/base/armv7:18.2.0 - aarch64: ghcr.io/hassio-addons/base/aarch64:18.2.0 - amd64: ghcr.io/hassio-addons/base/amd64:18.2.0 - i386: ghcr.io/hassio-addons/base/i386:18.2.0 diff --git a/plejd/entrypoint.sh b/plejd/entrypoint.sh new file mode 100644 index 0000000..7ffa311 --- /dev/null +++ b/plejd/entrypoint.sh @@ -0,0 +1,39 @@ +#! /bin/sh + +if [ -z "${site}" ]; then + echo "Plejd site not set." + exit 1 +fi + +if [ -z "${username}" ]; then + echo "Plejd username not set." + exit 1 +fi + +if [ -z "${password}" ]; then + echo "Plejd password not set." + exit 1 +fi + +if [ -z "${mqttUsername}" ]; then + echo "Mqtt username not set" + exit 1 +fi + +if [ -z "${mqttPassword}" ]; then + echo "Mqtt password not set" + exit 1 +fi + +mkdir /data + +mqttBroker="${mqttBroker:=mqtt://}" \ +includeRoomsAsLights="${includeRoomsAsLights:=false}" \ +preferCachedApiResponse="${preferCachedApiResponse:=false}" \ +updatePlejdClock="${updatePlejdClock:=false}" \ +logLevel="${logLevel:=info}" \ +connectionTimout="${connectionTimout:=2}" \ +writeQueueWaitTime="${writeQueueWaitTime:=400}" \ +envsubst <"/plejd/options.json.template" >"/data/options.json" + +node /plejd/main.js diff --git a/plejd/options.json.template b/plejd/options.json.template new file mode 100644 index 0000000..21afe63 --- /dev/null +++ b/plejd/options.json.template @@ -0,0 +1,14 @@ +{ + "site": "$site", + "username": "$username", + "password": "$password", + "mqttBroker": "$mqttBroker", + "mqttUsername": "$mqttUsername", + "mqttPassword": "$mqttPassword", + "includeRoomsAsLights": "$includeRoomsAsLights", + "preferCachedApiResponse": "$preferCachedApiResponse", + "updatePlejdClock": "$updatePlejdClock", + "logLevel": "$logLevel", + "connectionTimeout": $connectionTimout, + "writeQueueWaitTime": $writeQueueWaitTime +} diff --git a/plejd/rootfs/etc/cont-init.d/10-plejd-perms b/plejd/rootfs/etc/cont-init.d/10-plejd-perms deleted file mode 100755 index 4074ba6..0000000 --- a/plejd/rootfs/etc/cont-init.d/10-plejd-perms +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/with-contenv bashio - -bashio::log.info 'Ensuring Plejd scripts are executable' -chmod 0755 /etc/services.d/plejd/run /usr/bin/plejd.sh || bashio::exit.nok 'Failed to set permissions' diff --git a/plejd/rootfs/etc/services.d/plejd/run b/plejd/rootfs/etc/services.d/plejd/run deleted file mode 100755 index 7aa83a6..0000000 --- a/plejd/rootfs/etc/services.d/plejd/run +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/with-contenv bashio -# ============================================================================== -# Community Hass.io Add-ons: Plejd -# Runs the Plejd service -# ============================================================================== - -bashio::log.info 'Starting the Plejd service...' - -# Change working directory -cd /plejd || bashio::exit.nok 'Unable to change working directory' - -# Run the Plejd service -bashio::log.info 'Executing startup script' -exec /usr/bin/plejd.sh diff --git a/plejd/rootfs/usr/bin/plejd.sh b/plejd/rootfs/usr/bin/plejd.sh deleted file mode 100755 index 627843e..0000000 --- a/plejd/rootfs/usr/bin/plejd.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/with-contenv bashio - -bashio::log.info 'Running add-on' -exec node /plejd/main.js - diff --git a/repository.json b/repository.json deleted file mode 100644 index 4e46ee7..0000000 --- a/repository.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Unofficial Plejd Add-on", - "url": "https://github.com/icanos/hassio-plejd", - "maintainer": "Marcus Westin " -}