I'm using poetry
library to manage project dependencies, so when I use
docker build --tag=helloworld .
I got this error
[AttributeError]
'NoneType' object has no attribute 'group'
Installing breaks on umongo (2.1.0)
package
Here is my pyproject.toml
file
[tool.poetry.dependencies]
python = "^3.7.0"
asyncio = "^3.4"
aiohttp = "^3.4"
motor = "^2.0"
umongo = "^2.0"
pyyaml = "^3.13"
[tool.poetry.dev-dependencies]
pytest = "^3.4"
black = {version = "^18.3-alpha.0",allows-prereleases = true}
mypy = "^0.650.0"
wemake-python-styleguide = "^0.5.1"
pytest-mock = "^1.10"
pytest-asyncio = "^0.9.0"
pytest-aiohttp = "^0.3.0"
And poetry.lock
https://pastebin.com/kUjAKJHM
Dockerfile:
FROM python:3.7.1-alpine
RUN mkdir -p /opt/project/todo_api
RUN pip --no-cache-dir install poetry
COPY ./pyproject.toml /opt/project
COPY poetry.lock /opt/project
RUN cd /opt/project && poetry install --no-dev
COPY ./todo_api /opt/project/todo_api
COPY ./todo_api.yml /opt/project/todo_api.yml
WORKDIR /opt/project
ENTRYPOINT poetry run python -m aiohttp.web todo_api.main:main
Don't install poetry
into your deployment environment. It's a package management tool, which aims to improve development of and collaboration on libraries. If you want to deploy an application, you only need a package installer (read: pip
) - and the opinionated stance of poetry
regarding the build process and virtual environments is harmful rather than helpful there.
In this case, the artifacts you want to copy into your docker image are 1) your most recent build of the library you work on and 2) a wheelhouse of tested dependencies, as defined by poetry.lock
.
The first one is easy, run poetry build -f wheel
and you have a nicely portable wheel. The second one is not yet easy, because poetry
doesn't support building wheelhouses (and maybe never will), and pip wheel
does not accept poetry.lock
's file format. So if you want go down this road, you need to work on a beta build of poetry
(v1.0.0b7
is rather stable) that supports poetry export -f requirements.txt > requirements.txt
, which lets you create a requirements.txt
file equivalent to your current lockfile.
Once you got that, you can run pip wheel -w dist -r requirements.txt
, and finally, you're done creating all the artifacts for the docker image. Now, the following will work:
FROM python:3.7.1-alpine
WORKDIR /opt/project
COPY dist dist
RUN pip install --no-index --find-links dist todo_api
ENTRYPOINT python -m aiohttp.web todo_api.main:main
poetry
in your server (might be relevant, since it's still <v1.0
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With