Skip to content

Commit

Permalink
backend: Migrate build system to poetry
Browse files Browse the repository at this point in the history
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 python-restx/flask-restx#308
  • Loading branch information
dev-jan committed May 14, 2021
1 parent d187210 commit f7a0e39
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
18 changes: 15 additions & 3 deletions 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"]
7 changes: 6 additions & 1 deletion 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
Expand Down
21 changes: 21 additions & 0 deletions backend/pyproject.toml
@@ -0,0 +1,21 @@
[tool.poetry]
name = "openenergize-backend"
version = "0.1.0"
description = ""
authors = ["Jan Bucher <jan@bucher.cloud>"]

[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"
6 changes: 0 additions & 6 deletions backend/requirements.txt

This file was deleted.

0 comments on commit f7a0e39

Please sign in to comment.