Skip to content

Commit f67be00

Browse files
authored
Development (#250)
* remove unused variables * fix badges * user set
1 parent c3c469b commit f67be00

File tree

17 files changed

+222
-123
lines changed

17 files changed

+222
-123
lines changed

.dockerignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.git
2-
LICENSE
2+
.gitignore
3+
.github
4+
.gitkeep
5+
.gitattributes
36
README.md

.github/workflows/build_release.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ env:
1919
DOCKER_BASE_IMAGE: python:3-alpine3.13
2020
DOCKER_TARGET_REPO: xirixiz/dsmr-reader-docker
2121
DOCKERFILE: Dockerfile
22-
DOCKER_TARGET_RELEASE: 2021.12.08
22+
DOCKER_TARGET_RELEASE: 2021.12.09
2323

2424
jobs:
2525
################################################
@@ -135,9 +135,9 @@ jobs:
135135
env:
136136
dsmr_version: ${{ steps.dsmr_version.outputs.version }}
137137
run: |
138-
mkdir -p tmp/dsmr
139-
curl -SskLf "https://github.com/dsmrreader/dsmr-reader/archive/v${dsmr_version}.tar.gz" | tar xvzf - --strip-components=1 -C tmp/dsmr
140-
pushd tmp/dsmr &&
138+
mkdir -p tmp/app
139+
curl -SskLf "https://github.com/dsmrreader/dsmr-reader/archive/v${dsmr_version}.tar.gz" | tar xvzf - --strip-components=1 -C tmp/app
140+
pushd tmp/app &&
141141
curl -SskLf "https://raw.githubusercontent.com/dsmrreader/dsmr-reader/v4/dsmr_datalogger/scripts/dsmr_datalogger_api_client.py" -O &&
142142
popd
143143
@@ -181,6 +181,7 @@ jobs:
181181
--build-arg BASE_IMAGE=${{ matrix.BASE_IMAGE }} \
182182
--build-arg QEMU_ARCH=${{ matrix.QEMU_ARCH }} \
183183
--build-arg S6_ARCH=${{ matrix.S6_ARCH }} \
184+
--build-arg DOCKER_TARGET_RELEASE=${DOCKER_TARGET_RELEASE} \
184185
-t ${DOCKER_TARGET_REPO}:${{ matrix.DOCKER_TAG_SUFFIX }}${DOCKER_TAG_SUFFIX_BRANCH} \
185186
.
186187

.gitignore

+48-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
1-
dsmrdb/
2-
src/dsmr/
3-
tmp/
4-
.DS_Store
1+
# Windows image file caches
2+
Thumbs.db
3+
ehthumbs.db
4+
5+
# Folder config file
6+
Desktop.ini
7+
8+
# Recycle Bin used on file shares
9+
$RECYCLE.BIN/
10+
11+
# Windows Installer files
12+
*.cab
13+
*.msi
14+
*.msm
15+
*.msp
16+
17+
# Windows shortcuts
18+
*.lnk
19+
20+
# =========================
21+
# Operating System Files
22+
# =========================
23+
24+
# OSX
25+
# =========================
26+
27+
.DS_Store
28+
.AppleDouble
29+
.LSOverride
30+
31+
# Thumbnails
32+
._*
33+
34+
# Files that might appear on external disk
35+
.Spotlight-V100
36+
.Trashes
37+
38+
# Directories potentially created on remote AFP share
39+
.AppleDB
40+
.AppleDesktop
41+
Network Trash Folder
42+
Temporary Items
43+
.apdisk
44+
.jenkins-external
45+
46+
# Ansible
47+
*.retry
48+
ansible.log

Dockerfile

+32-15
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ FROM ${BASE_IMAGE:-amd64/python:3-alpine3.13}
44
ARG QEMU_ARCH
55
ARG S6_ARCH
66
ARG DSMR_VERSION
7+
ARG DOCKER_TARGET_RELEASE
78

8-
ENV QEMU_ARCH=${QEMU_ARCH:-x86_64}
9-
ENV S6_ARCH=${S6_ARCH:-amd64}
10-
ENV S6_KEEP_ENV=1
11-
ENV DSMR_VERSION=${DSMR_VERSION:-4.19.0}
9+
# environment variables
10+
ENV PS1="$(whoami)@dsmr_reader_docker:$(pwd)\\$ " \
11+
TERM="xterm"
12+
13+
ENV QEMU_ARCH=${QEMU_ARCH:-x86_64} \
14+
S6_ARCH=${S6_ARCH:-amd64} \
15+
S6_KEEP_ENV=1 \
16+
DSMR_VERSION=${DSMR_VERSION:-4.19.0} \
17+
DOCKER_TARGET_RELEASE=${DOCKER_TARGET_RELEASE}
1218

1319
ENV DJANGO_SECRET_KEY=dsmrreader \
1420
DJANGO_DATABASE_ENGINE=django.db.backends.postgresql \
@@ -23,15 +29,18 @@ ENV DJANGO_SECRET_KEY=dsmrreader \
2329
DATALOGGER_MODE=standalone \
2430
VACUUM_DB_ON_STARTUP=false
2531

32+
# copy qemu, s6-overlay and local files
2633
COPY /tmp/qemu/qemu-${QEMU_ARCH}-static /usr/bin/qemu-${QEMU_ARCH}-static
2734
COPY /tmp/s6-${S6_ARCH}/ /
28-
COPY /tmp/dsmr/ /dsmr
29-
30-
COPY app /app
35+
COPY /tmp/app/ /app
3136
COPY rootfs /
3237

33-
RUN apk --update add --no-cache \
38+
RUN echo "**** install runtime packages ****" \
39+
&& apk --update add --no-cache \
3440
bash \
41+
coreutils \
42+
ca-certificates \
43+
shadow \
3544
dpkg \
3645
curl \
3746
nginx \
@@ -42,30 +51,38 @@ RUN apk --update add --no-cache \
4251
mariadb-client \
4352
tzdata
4453

45-
RUN cp -f /dsmr/dsmrreader/provisioning/django/settings.py.template /dsmr/dsmrreader/settings.py
46-
47-
RUN apk add --no-cache --virtual .build-deps gcc python3-dev musl-dev postgresql-dev build-base mariadb-dev libressl-dev libffi-dev cargo rust \
54+
RUN echo "**** install build packages ****" \
55+
&& apk add --no-cache --virtual .build-deps gcc python3-dev musl-dev postgresql-dev build-base mariadb-dev libressl-dev libffi-dev cargo rust \
56+
&& echo "**** install pip packages ****" \
4857
&& python3 -m pip install --upgrade pip \
49-
&& python3 -m pip install -r /dsmr/dsmrreader/provisioning/requirements/base.txt --no-cache-dir \
58+
&& python3 -m pip install -r /app/dsmrreader/provisioning/requirements/base.txt --no-cache-dir \
5059
&& python3 -m pip install psycopg2 --no-cache-dir \
5160
&& python3 -m pip install mysqlclient --no-cache-dir \
5261
&& python3 -m pip install tzupdate --no-cache-dir \
62+
&& echo "**** create app user and make base folders ****" \
63+
&& groupmod -g 1000 users \
64+
&& useradd -u 803 -U -d /config -s /bin/false app \
65+
&& usermod -G users app \
5366
&& mkdir -p /app /config /defaults \
67+
&& echo "**** copy default settings dsmr reader ****" \
68+
&& cp -f /app/dsmrreader/provisioning/django/settings.py.template /app/dsmrreader/settings.py \
69+
&& echo "**** cleanup package leftovers ****" \
5470
&& apk --purge del .build-deps \
5571
&& apk --purge del \
5672
&& rm -rf /var/cache/apk/* \
5773
&& rm -rf /tmp/*
5874

59-
RUN mkdir -p /run/nginx/ \
75+
RUN echo "**** configure nginx package ****" \
76+
&& mkdir -p /run/nginx/ \
6077
&& ln -sf /dev/stdout /var/log/nginx/access.log \
6178
&& ln -sf /dev/stderr /var/log/nginx/error.log \
6279
&& rm -f /etc/nginx/conf.d/default.conf \
6380
&& mkdir -p /var/www/dsmrreader/static \
64-
&& cp -f /dsmr/dsmrreader/provisioning/nginx/dsmr-webinterface /etc/nginx/conf.d/dsmr-webinterface.conf
81+
&& cp -f /app/dsmrreader/provisioning/nginx/dsmr-webinterface /etc/nginx/conf.d/dsmr-webinterface.conf
6582

6683
# TODO: Improve healtcheck to respond on 200 only
6784
HEALTHCHECK --interval=5s --timeout=3s --retries=10 CMD curl -Lsf http://127.0.0.1/about -o /dev/null -w "HTTP_%{http_code}" || exit 1
6885

69-
WORKDIR /dsmr
86+
WORKDIR /app
7087

7188
ENTRYPOINT ["/init"]

README.md

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<font size="-1">
22

3-
[![DockerPulls](https://img.shields.io/docker/pulls/xirixiz/dsmr-reader-docker.svg)](https://img.shields.io/docker/pulls/xirixiz/dsmr-reader-docker/)
4-
[![Docker Build Status](https://github.com/oznu/docker-homebridge/workflows/Build/badge.svg)](https://github.com/xirixiz/dsmr-reader-docker/actions)
5-
[![Donate](https://img.shields.io/badge/donate-paypal-yellowgreen.svg)](https://www.paypal.com/donate/?business=9M4P6DGT7U7VU&no_recurring=0&item_name=Open+source+project+development.&currency_code=EUR)
3+
[![Docker Pulls](https://img.shields.io/docker/pulls/xirixiz/dsmr-reader-docker.svg?logo=docker)](https://img.shields.io/docker/pulls/xirixiz/dsmr-reader-docker/)
4+
[![Docker Stars](https://img.shields.io/docker/stars/xirixiz/dsmr-reader-docker.svg?logo=docker)](https://hub.docker.com/r/xirixiz/dsmr-reader-docker)
5+
[![GitHub Build Status](https://github.com/xirixiz/dsmr-reader-docker/workflows/DSMR:%20Build%20Docker%20images/badge.svg?logo=github)](https://github.com/xirixiz/dsmr-reader-docker/actions)
6+
[![GitHub Stars](https://img.shields.io/github/stars/xirixiz/dsmr-reader-docker.svg?logo=github)](https://github.com/xirixiz/dsmr-reader-docker/)
7+
[![Donate](https://img.shields.io/badge/donate-paypal-yellowgreen.svg?logo=paypal)](https://www.paypal.com/donate/?business=9M4P6DGT7U7VU&no_recurring=0&item_name=Open+source+project+development.&currency_code=EUR)
68
[![BuyMeCoffee][buymecoffeebadge]][buymecoffee]
79

810
[buymecoffee]: https://www.buymeacoffee.com/xirixiz
@@ -67,6 +69,10 @@ Docker tags/releases can be found here: https://hub.docker.com/r/xirixiz/dsmr-re
6769
# Required (defaults are shown as value):
6870
- DJANGO_TIME_ZONE=Europe/Amsterdam
6971
- VIRTUAL_HOST=localhost
72+
# It's possible to map a UID/GID with a user/group from you local system.
73+
# This will not change the username, onbly match ID's to prevent issues with access rights!
74+
- DUID=803
75+
- DGID=803
7076
```
7177

7278
* ##### Nginx related:
@@ -186,12 +192,6 @@ Docker tags/releases can be found here: https://hub.docker.com/r/xirixiz/dsmr-re
186192

187193
***
188194
#### Features
189-
* ##### To-do list:
190-
```text
191-
* Upgrade to Docker Alpine base image 3.13 - Done
192-
* Upgrade to Postgres 13 client and backend - Done
193-
```
194-
195195
* ##### DSMR Reader - Database cleanup/vacuum
196196
It could be that you receive a notification that the database is growing, like in this issue: https://github.com/dsmrreader/dsmr-reader/issues/1165.
197197

@@ -209,7 +209,7 @@ Docker tags/releases can be found here: https://hub.docker.com/r/xirixiz/dsmr-re
209209

210210
```yaml
211211
volumes:
212-
- ./modules/forward_telegram_to_api.py:/dsmr/dsmr_plugins/modules/forward_telegram_to_api.py
212+
- ./modules/forward_telegram_to_api.py:/app/dsmr_plugins/modules/forward_telegram_to_api.py
213213
environment:
214214
- DSMRREADER_PLUGINS=dsmr_plugins.modules.forward_telegram_to_api
215215
```
@@ -280,6 +280,15 @@ Docker tags/releases can be found here: https://hub.docker.com/r/xirixiz/dsmr-re
280280
- restart the dsmrdb container
281281
- start the dsmr container
282282
```
283+
* ##### UID/GID
284+
When using volumes (`-v` or `--volume` flags) permissions issues can occur between the host OS and the container, to avoid this you can specify a user id `DUID` and group id `DGID` from the local system in the Docker container. Make sure the owner of the directory has all permissions on the volume you'd like to mount into the Docker container.
285+
286+
You can identify a UID or GID by executing the following command
287+
288+
```bash
289+
id xirixiz
290+
uid=1000(xirixiz) gid=1000(xirixiz) groups=1000(xirixiz) 1001(docker)
291+
```
283292
284293
***
285294
#### Issues
@@ -313,7 +322,7 @@ Docker tags/releases can be found here: https://hub.docker.com/r/xirixiz/dsmr-re
313322
* ##### Synology
314323
For Synology, or maybe other NAS appliances, an additional driver is required:
315324
* Drivers are required for DSM < 7.0: http://www.jadahl.com/drivers_6.1 or http://www.jadahl.com/drivers_6.2
316-
* Drivers to enable USB for DSM > 7.0:
325+
* Drivers to enable USB for DSM > 7.0: http://www.jadahl.com/iperf-arp-scan/DSM_7.0/
317326
```sh
318327
sudo insmod /lib/modules/usbserial.ko
319328
sudo insmod /lib/modules/ftdi_sio.ko

examples/docker-compose.example.yaml

+13-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ services:
3434
restart: always
3535
volumes:
3636
- /etc/localtime:/etc/localtime:ro
37-
- ./dsmr_backups:/dsmr/backups
37+
- ./dsmr_backups:/app/backups
3838
environment:
3939
- TZ=Europe/Amsterdam
4040
- DJANGO_TIME_ZONE=Europe/Amsterdam
@@ -45,10 +45,20 @@ services:
4545
devices:
4646
- /dev/ttyUSB0:/dev/ttyUSB0
4747
healthcheck:
48-
test: [ "CMD", "curl", "-f", "http://localhost:80" ]
48+
test:
49+
[
50+
"CMD",
51+
"curl",
52+
"-Lsf",
53+
"http://127.0.0.1/about",
54+
"-o",
55+
"/dev/null",
56+
"-w",
57+
"HTTP_%{http_code}"
58+
]
4959
interval: 10s
5060
timeout: 5s
51-
retries: 5
61+
retries: 10
5262

5363
volumes:
5464
dsmrdb: null

rootfs/app/.gitkeep

Whitespace-only changes.
File renamed without changes.

rootfs/config/.gitkeep

Whitespace-only changes.

rootfs/defaults/.gitkeep

Whitespace-only changes.

rootfs/etc/cont-init.d/10-adduser

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
DUID=${DUID:-803}
4+
DGID=${DGID:-803}
5+
6+
groupmod -o -g "${DGID}" app
7+
usermod -o -u "${DUID}" app
8+
9+
echo "
10+
-------------------------
11+
User UID: $(id -u app)
12+
User GID: $(id -g app)
13+
-------------------------
14+
"
15+
16+
time32="$(date +%Y)"
17+
18+
if [[ "${time32}" == "1970" || "${time32}" == "1969" ]] && [ "$(uname -m)" == "armv7l" ]; then
19+
echo 'Your DockerHost is running an outdated version of libseccomp. Search internet to fix this!'
20+
sleep infinity
21+
fi
22+
23+
chown -R app:app /app
24+
chown -R app:app /config
25+
chown -R app:app /defaults

0 commit comments

Comments
 (0)