Skip to content

Commit

Permalink
Docker-compose (#325)
Browse files Browse the repository at this point in the history
* Stop failing if config is missing, hard to debug docker

* Changing message to reflect new behaviour

* Adding docker compose for eaiser development setup

* Docker-compose starting mosquitto in a container that mpp-solar container can connect with

* Setting the entrypoint so mpp-solar starts automatically in daemon mode.

* Updating the ignore file to exclude mosquitto files

* Reverting the behaviour if no config file

* Adding development Dockerfile and docker-compose yaml
  • Loading branch information
rossandrews authored Apr 2, 2023
1 parent 2595f95 commit ac815fc
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ ENV/
.vscode/
.idea/
mppsolar/.idea/
poetry.lock
poetry.lock

# ignore mosquitto files bound to the docker container
docker/mosquitto/data/mosquitto.db
docker/mosquitto/log/mosquitto.log
docker/mosquitto/config/mosquitto.passwd
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:latest
RUN apt-get update
RUN apt-get install -y pkg-config libsystemd-dev gcc

RUN pip install paho-mqtt systemd-python pymongo

RUN apt-get -y install libpq-dev
RUN pip install psycopg2

RUN pip install mppsolar
11 changes: 11 additions & 0 deletions Dockerfile.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:latest
RUN apt-get update
RUN apt-get install -y pkg-config libsystemd-dev gcc

RUN pip install paho-mqtt systemd-python pymongo

RUN apt-get -y install libpq-dev
RUN pip install psycopg2

COPY . /mpp-solar/
RUN pip install -e /mpp-solar/
33 changes: 33 additions & 0 deletions docker-compose.development.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
mosquitto:
image: eclipse-mosquitto
network_mode: host
volumes:
- ./docker/mosquitto/config:/mosquitto/config
- ./docker/mosquitto/data:/mosquitto/data
- ./docker/mosquitto/log:/mosquitto/log

mppsolar:
network_mode: host
devices:
- /dev/hidraw0:/dev/hidraw0
volumes:
#Bind over the configuration
- type: bind
source: ./docker/
target: /etc/mpp-solar
#Bind the code
- type: bind
source: .
target: /mpp-solar
build:
dockerfile: Dockerfile.development
entrypoint:
- mpp-solar
- -C
- /etc/mpp-solar/mpp-solar.conf #Available due to volume binding above
- --daemon
depends_on:
- mosquitto


28 changes: 28 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
mosquitto:
image: eclipse-mosquitto
network_mode: host
volumes:
- ./docker/mosquitto/config:/mosquitto/config
- ./docker/mosquitto/data:/mosquitto/data
- ./docker/mosquitto/log:/mosquitto/log

mppsolar:
network_mode: host
devices:
- /dev/hidraw0:/dev/hidraw0
volumes:
#Bind over the configuration
- type: bind
source: ./docker/
target: /etc/mpp-solar
build: .
entrypoint:
- mpp-solar
- -C
- /etc/mpp-solar/mpp-solar.conf #Available due to volume binding above
- --daemon
depends_on:
- mosquitto


10 changes: 10 additions & 0 deletions docker/mosquitto/config/mosquitto.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
persistence true
persistence_location /mosquitto/data/

log_dest file /mosquitto/log/mosquitto.log
log_type all

listener 1883
## Authentication ##
allow_anonymous true
#password_file /mosquitto/config/mosquitto.passwd
10 changes: 10 additions & 0 deletions docker/mpp-solar.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[SETUP]
pause=20
mqtt_broker=localhost

[Inverter_1]
port=/dev/hidraw0
protocol=PI30
command=QDI
outputs=mqtt

2 changes: 1 addition & 1 deletion mppsolar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def main():
sections = config.sections()
# Check setup section exists
if "SETUP" not in config:
log.error(f"Config File '{args.configfile}' is missing the required 'SETUP' section")
log.error(f"Config File '{args.configfile}' is missing the required 'SETUP' section or does not exist")
exit(1)
# Process setup section
pause = config["SETUP"].getint("pause", fallback=60)
Expand Down

0 comments on commit ac815fc

Please sign in to comment.