Skip to content

Commit

Permalink
Merge pull request #5 from hostcc/feature/docker
Browse files Browse the repository at this point in the history
Docker images support
  • Loading branch information
hostcc authored Jun 2, 2022
2 parents 12f7d61 + 6e449ea commit 191ac36
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 4 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
python: 3.9
toxenv: py
runs-on: ${{ matrix.os }}
outputs:
version: ${{ steps.package-version.outputs.VALUE }}
steps:
- name: Checkout the code
uses: actions/checkout@v2
Expand Down Expand Up @@ -105,3 +107,48 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}

docker-publish:
name: Build and publish Docker images
runs-on: ubuntu-latest
needs: [tests]
permissions:
contents: read
packages: write
# Publishing Docker images only happens when a release published out of the
# main branch
if: >-
github.event_name == 'release'
&& github.event.action == 'published'
&& (github.event.release.target_commitish == 'main'
|| github.event.release.target_commitish == 'master')
steps:
- name: Checkout the code
uses: actions/checkout@v2

- name: Set up QEMU for more platforms supported by Buildx
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push images
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/arm/v7,linux/arm/v6,linux/arm64
push: true
tags:
"ghcr.io/${{ github.repository_owner }}\
/${{ github.event.repository.name }}:latest
ghcr.io/${{ github.repository_owner }}\
/${{ github.event.repository.name }}\
:${{ needs.tests.outputs.version }}"
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.10-alpine as build
RUN apk add -U git
RUN pip install build
ADD . src/
WORKDIR src
RUN python -m build
RUN pip install --root target/ dist/*-`cat version.txt`*.whl

FROM python:3.10-alpine
COPY --from=build \
src/target/root/.local/lib/ /usr/local/lib/
COPY --from=build \
src/target/root/.local/bin/ \
/usr/local/bin/

ENTRYPOINT ["energomera-hass-mqtt"]
26 changes: 24 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ need to install it directly from Github:

.. code:: shell
pip install git+https://github.com/hostcc/energomera-hass-mqtt@main
pip install git+https://github.com/hostcc/energomera-hass-mqtt@master
Usage
=====
Expand Down Expand Up @@ -126,9 +126,31 @@ Configuration file is in YAML format and supports following elements:
===================

Sample service definition for ``systemd`` is provided under
`systemd/ <https://github.com/hostcc/energomera-hass-mqtt/tree/main/systemd>`_
`systemd/ <https://github.com/hostcc/energomera-hass-mqtt/tree/master/systemd>`_
directory.

Docker support
==============

There are Docker images available if you would like to run it as Docker container - you could use
``ghcr.io/hostcc/energomera-hass-mqtt:latest`` or
``ghcr.io/hostcc/energomera-hass-mqtt:<release version>``.

As of writing, the images are built to ARM v6/v7 and ARM64 platforms.

To run the program as container you will need to create a directory on the host
and put ``config.yaml`` relevant to your setup there.

Then, assuming the directory is called ``config`` and resides relative to
current directory, and the serial port the meter is connected to is
``/dev/ttyUSB0`` the following command will run it

.. code::
$ docker run --device /dev/ttyUSB0 -v `pwd`/config:/etc/energomera/ \
ghcr.io/hostcc/energomera-hass-mqtt:latest
Documentation
=============

Expand Down
5 changes: 4 additions & 1 deletion systemd/energomera-hass-mqtt.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ After=network.target

[Service]
Type=exec
ExecStartPre=+/bin/sh -c 'chgrp -R 65000 /etc/energomera/'
ExecStart=energomera-hass-mqtt
ExecStopPost=+/bin/sh -c 'chgrp -R root /etc/energomera/'
Restart=always
Group=65000
SupplementaryGroups=dialout
DynamicUser=yes
Group=dialout
StandardOutput=journal
StandardError=inherit
NoNewPrivileges=yes
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ setenv =
allowlist_externals =
cat
commands =
check-manifest --ignore 'tox.ini,tests/**,docs/**,.pylintrc,.readthedocs.yaml,sonar-project.properties,systemd/**'
check-manifest --ignore 'tox.ini,tests/**,docs/**,.pylintrc,.readthedocs.yaml,sonar-project.properties,systemd/**',Dockerfile
flake8 --tee --output-file=flake8.txt .
pylint --output-format=parseable --output=pylint.txt src/energomera_hass_mqtt
# Ensure only traces for in-repository module is processed, not for one
Expand Down

0 comments on commit 191ac36

Please sign in to comment.