Skip to content

Commit

Permalink
Merge pull request #40 from f18m/master
Browse files Browse the repository at this point in the history
Dockerfile not working
  • Loading branch information
eschava authored Apr 28, 2024
2 parents 0009491 + 450cf73 commit 5b47c3f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 13 deletions.
33 changes: 29 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#
# Builder docker
#

FROM public.ecr.aws/docker/library/python:3.11-alpine AS builder

RUN apk add build-base linux-headers
Expand All @@ -18,21 +22,42 @@ RUN rm -rf \
src/*_test.py \
psutil/tests


#
# Production docker
#

FROM public.ecr.aws/docker/library/python:3.11-alpine
RUN apk add bash

# when USERNAME=root is provided, the application runs as root within the container, this is useful in case 'pySMART' or any SMART attribute
# has been configured (smartctl requires root permissions)
ARG USERNAME=psmqtt

LABEL org.opencontainers.image.source=https://github.com/f18m/psmqtt

RUN apk add bash smartmontools

WORKDIR /opt/psmqtt
COPY --from=builder /build .

RUN mkdir ./src
COPY *.py ./
COPY src/*.py ./src
COPY psmqtt.service .
COPY logging.conf .

RUN mkdir ./conf
COPY psmqtt.conf ./conf

# add user psmqtt to image
RUN addgroup -S psmqtt && adduser -S psmqtt -G psmqtt
RUN chown -R psmqtt:psmqtt /opt/psmqtt
RUN if [[ "$USERNAME" != "root" ]]; then \
addgroup -S psmqtt && \
adduser -S ${USERNAME} -G psmqtt && \
chown -R ${USERNAME}:psmqtt /opt/psmqtt ; \
fi

# process run as psmqtt user
USER psmqtt
USER ${USERNAME}

# set conf path
ENV PSMQTTCONFIG="/opt/psmqtt/conf/psmqtt.conf"
Expand Down
43 changes: 41 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
.. contents:: Table of Contents
===============
About this fork
===============

I created this fork to allow psmqtt to run on my TerraMaster NAS.
Use it like this::

docker run -d -v <your config file>:/opt/psmqtt/conf/psmqtt.conf \
--privileged --hostname tnas \
ghcr.io/f18m/psmqtt:1.0.2

Example of my psmqtt.conf::

mqtt_broker = '192.168.1.8' # default: 'localhost'
mqtt_username = 'psmqtt'
mqtt_password = 'psmqtt'
mqtt_clean_session = False
mqtt_qos = 0
mqtt_retain = False
mqtt_request_topic = 'request'

schedule = {
"every 5 sec": [
"cpu_percent",
"virtual_memory/percent",
"sensors_temperatures/rtk_thermal/*",
'smart/sdc/temperature',
'smart/sdd/temperature',
],
"every 60 minutes": "disk_usage/percent/|", # slash replaced with vertical slash
"every 3 hours": {
"boot_time/{{x|uptime}}": "uptime",
}
}

To push a new docker version with architecture arm64, use::

docker buildx build --platform linux/arm64/v8 --tag ghcr.io/f18m/psmqtt:1.0.2 --build-arg USERNAME=root --push .

(remember to update the tag version)

=======
Summary
Expand All @@ -11,7 +50,7 @@ metrics (CPU, memory, disks, network, smart disk data) to an MQTT broker.

* `paho-mqtt <https://github.com/eclipse/paho.mqtt.python>` to communicate with the MQTT broker;
* `psutil <https://github.com/giampaolo/psutil>` to collect metrics;
* `pySMART <https://github.com/jakogut/pySMART>` to collect SMART data;
* `pySMART <https://github.com/truenas/py-SMART>` to collect SMART data;
* `recurrent <https://github.com/kvh/recurrent>` to describe reporting schedule.
* `jinja2 <https://github.com/alex-foundation/jinja2>` to format the data.

Expand Down
5 changes: 5 additions & 0 deletions psmqtt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# PSMQTT configuration file
# NOTE: this is actually imported as a Python file, so it's using Python syntax
#

#import socket

mqtt_broker = 'mqtt' # default: 'localhost'
Expand Down
15 changes: 8 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
recurrent
paho-mqtt
python-dateutil
psutil
jinja2
types-paho-mqtt
pySMART
recurrent>=0.4.1
paho-mqtt>=1.6.1
python-dateutil>=2.8.2
psutil>=5.9.5
jinja2>=3.1.3
types-paho-mqtt>=1.6.0.20240321
# pySMART>=1.3.1.dev8 is required, see https://github.com/truenas/py-SMART/issues/86
pySMART>=1.3.1.dev8

0 comments on commit 5b47c3f

Please sign in to comment.