From bfd58dad4e9ff464de6c6b233dbec37442bf58e0 Mon Sep 17 00:00:00 2001 From: Slawomir Skowron Date: Fri, 24 May 2024 19:13:38 +0200 Subject: [PATCH] Initial Docker support (#34) * Initial Docker support * Dockerfile cleanup * Readme cleanup --- .dockerignore | 34 ++++++++++++++++++++++++++++++++++ Dockerfile | 33 +++++++++++++++++++++++++++++++++ Makefile | 3 +++ README.md | 22 ++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..03a268b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.DS_Store +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d2ffd51 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# syntax=docker/dockerfile:1 + +ARG PYTHON_VERSION=3.12.3 +FROM python:${PYTHON_VERSION}-slim as base + +# Prevents Python from writing pyc files. +ENV PYTHONDONTWRITEBYTECODE=1 + +# Keeps Python from buffering stdout and stderr to avoid situations where +# the application crashes without emitting any logs due to buffering. +ENV PYTHONUNBUFFERED=1 + +# Choose poetry version +ENV POETRY_VERSION=1.8.2 + +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds. +# Leverage a bind mount to requirements.txt to avoid having to copy them into +# into this layer. +RUN --mount=type=cache,target=/root/.cache/pip \ + python3 -m pip install "poetry==$POETRY_VERSION" + +# Install all dependencies for aiocomfoconnect +COPY pyproject.toml poetry.lock . +RUN poetry export -f requirements.txt | python3 -m pip install -r /dev/stdin + +# Copy the source code into the container. +COPY . . + +FROM base as final + +# Run the application. +ENTRYPOINT ["python3", "-m", "aiocomfoconnect"] diff --git a/Makefile b/Makefile index f3b2334..8d2d472 100644 --- a/Makefile +++ b/Makefile @@ -13,4 +13,7 @@ codefix: test: @poetry run pytest +build: + docker build -t aiocomfoconnect . + .PHONY: check codefix test diff --git a/README.md b/README.md index dcf0f51..5968a8c 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,28 @@ $ python -m aiocomfoconnect get-property --host 192.168.1.213 1 1 8 9 # Unit 0x - `async cmd_rpdo_request(pdid, type, zone, timeout)`: Send a RPDO request. - `async cmd_keepalive()`: Send a keepalive message. +## Docker + +### Description +Docker with aiocomfoconnect allow to experiment and develop on local machine using same image and same environment on any platform where we can run container. +This allow us to skip some platform issues and work on similar things and python version by easly swapping them in Dockerfile. + +### Building + +Build the image command +``` +make build +``` + +### Running +Now after we build our images is called `aiocomfoconnect` + +To run aiocomfoconnect we can use bellow command in this case with `--help` arg. +``` +docker run aiocomfoconnect --help +``` +Any args from `aiocomfoconnect` can be passed into this image run just like for `python3 -m aiocomfoconnect` command in local build. + ## Examples ### Discovery of ComfoConnect LAN C Bridges