From f7a0e3911cb2bdc336c6456d5ebeebd6b9271527 Mon Sep 17 00:00:00 2001 From: Jan Bucher Date: Fri, 14 May 2021 13:27:29 +0200 Subject: [PATCH] backend: Migrate build system to poetry Since Poetry has better support for dependency management than using a simple pip requirements file, Poetry is now used to fetch dependencies. Also the versions are now more stricly given, since sometimes the most up-to-date versions are not compatible with other up-to-date versions. This happens with the new flask version 2.0.0, which came out this week and break the build, since flask-restx is not working correctly with flask 2.0.0 See https://github.com/python-restx/flask-restx/issues/308 --- backend/Dockerfile | 18 +++++++++++++++--- backend/README.md | 7 ++++++- backend/pyproject.toml | 21 +++++++++++++++++++++ backend/requirements.txt | 6 ------ 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 backend/pyproject.toml delete mode 100644 backend/requirements.txt diff --git a/backend/Dockerfile b/backend/Dockerfile index d422a88..4f19c09 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,10 +1,22 @@ FROM python:3.8-slim-buster WORKDIR /app -COPY requirements.txt /app/requirements.txt -RUN pip3 install -r requirements.txt +ENV PYTHONFAULTHANDLER=1 \ + PYTHONUNBUFFERED=1 \ + PYTHONHASHSEED=random \ + PIP_NO_CACHE_DIR=off \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + PIP_DEFAULT_TIMEOUT=100 \ + POETRY_VERSION=1.1.6 \ + GUNICORN_VERSION=20.1.0 -RUN pip3 install gunicorn +RUN pip install poetry==$POETRY_VERSION gunicorn==$GUNICORN_VERSION + +# copy requirements first for caching +COPY poetry.lock pyproject.toml /app/ + +RUN poetry config virtualenvs.create false \ + && poetry install --no-dev --no-interaction --no-ansi COPY . /app/backend CMD ["gunicorn", "--bind=0.0.0.0:5000", "backend.wsgi:app"] diff --git a/backend/README.md b/backend/README.md index 74bc2e9..40b0406 100644 --- a/backend/README.md +++ b/backend/README.md @@ -1,10 +1,15 @@ # Backend service ## Setup dev environment +Requirements: + - Python > 3.8 is installed + - Poetry is installed (https://python-poetry.org/docs/) + ``` pip3 install virtualenv virtualenv venv -pip3 install -r requirements.txt +source venv/bin/activate +poetry install ``` ## Startup in development diff --git a/backend/pyproject.toml b/backend/pyproject.toml new file mode 100644 index 0000000..b920fd0 --- /dev/null +++ b/backend/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "openenergize-backend" +version = "0.1.0" +description = "" +authors = ["Jan Bucher "] + +[tool.poetry.dependencies] +python = "^3.8" +Flask = "^1.1.4" +flask-restx = "^0.4.0" +requests = "^2.25.1" +PyYAML = "^5.4.1" +pymodbus = "^2.5.2" +cachetools = "^4.2.2" + +[tool.poetry.dev-dependencies] +pytest = "^6.2.4" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/backend/requirements.txt b/backend/requirements.txt deleted file mode 100644 index 6e31308..0000000 --- a/backend/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -flask -flask_restx -requests -pyyaml -pymodbus -cachetools