Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev Container + fixes for build, test and validate #46

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"image": "mcr.microsoft.com/vscode/devcontainers/python:0-3.10",
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"github.copilot",
"ms-python.python",
"oderwat.indent-rainbow",
"ms-python.vscode-pylance"
]
}
},
"postCreateCommand": "pip install black jsonschema paho_mqtt pylint && sudo -n apt update && sudo -n apt install git -y"
}
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!config.sample.json
!requirements.txt
!run.py
!solarman
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
FROM python:3.10-slim-bullseye

LABEL maintainer "Martijn Pepping <[email protected]>"
LABEL org.opencontainers.image.source https://github.com/mpepping/solarman-mqtt
LABEL org.opencontainers.image.authors "Martijn Pepping <[email protected]>"
LABEL org.opencontainers.image.description "Solarman MQTT published API data of supported PV systems to MQTT."
LABEL org.opencontainers.image.source "https://github.com/mpepping/solarman-mqtt"
LABEL org.opencontainers.image.title "Solarman MQTT"
LABEL org.opencontainers.image.url "https://github.com/mpepping/solarman-mqtt/pkgs/container/solarman-mqtt"

ADD . /opt/app-root/src/
WORKDIR /opt/app-root/src
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ services:
environment:
- TZ=Europe/Berlin
volumes:
- /opt/solarman-mqtt/config.json:/opt/app-root/src/config.json # source dir must contain you config file
- /opt/solarman-mqtt/config.json:/opt/app-root/src/config.json # or mount your complete config directory
restart: unless-stopped
```

Expand Down
17 changes: 8 additions & 9 deletions config.sample.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "Trannergy",
"url": "api.solarmanpv.com",
"appid": "",
"secret": "",
"username": "",
"passhash": "",
"stationId": 123,
"inverterId": "dev456",
"loggerId": 789,
"appid": "123456789013245",
"secret": "12345678901234567890123456789012",
"username": "email-address OR username",
"passhash": "1234567890123456789012345678901234567890123456789012345678901234",
"stationId": 1234567,
"inverterId": "1234567890",
"loggerId": "1234567890",
"debug" : false,
"mqtt":{
"broker": "1.1.1.1",
Expand All @@ -18,5 +18,4 @@
"qos": 1,
"retain": true
}
}

}
21 changes: 5 additions & 16 deletions solarman/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,17 @@
"username": {"type": "string"},
"passhash": {"type": "string", "minLength": 64, "maxLength": 64},
"stationId": {"type": "number", "minimum": 100000, "maximum": 9999999},
"inverterId": {
"type": "string",
"minLength": 10,
},
"inverterId": {"type": "string", "minLength": 10},
"loggerId": {"type": "string", "minLength": 10, "maxLength": 10},
"debug": {"type": "boolean", "optional": True},
"mqtt": {
"type": "object",
"properties": {
"broker": {
"type": "string",
},
"broker": {"type": "string"},
"port": {"type": "integer", "minimum": 1024, "maximum": 65535},
"topic": {
"type": "string",
},
"username": {
"type": "string",
},
"password": {
"type": "string",
},
"topic": {"type": "string"},
"username": {"type": "string"},
"password": {"type": "string"},
},
},
},
Expand Down
11 changes: 11 additions & 0 deletions tests/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e
cd "$(dirname "$0")/.."

IMG="ghcr.io/mpepping/solarman-mqtt:dev"
RUNTIME="docker"

$RUNTIME build . -t $IMG -f Dockerfile --force-rm
$RUNTIME inspect $IMG
$RUNTIME run --rm -it $IMG --validate -f config.sample.json
$RUNTIME rmi $IMG