s3rius / FastAPI-template

Feature rich robust FastAPI template.
MIT License
1.83k stars 161 forks source link

Error building Docker image in a fresh project #131

Closed jegork closed 1 year ago

jegork commented 1 year ago

Hello!

Thanks for this great package! Lately, I have started encountering an error when creating a new project (no modifications) and building the docker image from the provided Dockerfile.

[+] Building 22.9s (11/14)
 => [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 => => transferring dockerfile: 617B                                                                                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                                                                                             0.0s
 => => transferring context: 35B                                                                                                                                                                              0.0s
 => [internal] load metadata for docker.io/library/python:3.9.6-slim-buster                                                                                                                                   1.5s
 => [ 1/10] FROM docker.io/library/python:3.9.6-slim-buster@sha256:28bed4c51c3b531159d8affc0225701edb16a7deacfdfdfb220a944405c39314                                                                           0.0s
 => [internal] load build context                                                                                                                                                                             0.0s
 => => transferring context: 5.60kB                                                                                                                                                                           0.0s
 => CACHED [ 2/10] RUN apt-get update && apt-get install -y   gcc   && rm -rf /var/lib/apt/lists/*                                                                                                            0.0s
 => [ 3/10] RUN pip install setuptools wheel poetry==1.1.13                                                                                                                                                  13.9s
 => [ 4/10] RUN poetry config virtualenvs.create false                                                                                                                                                        0.5s
 => [ 5/10] COPY pyproject.toml poetry.lock /app/src/                                                                                                                                                         0.0s
 => [ 6/10] WORKDIR /app/src                                                                                                                                                                                  0.0s
 => ERROR [ 7/10] RUN poetry install                                                                                                                                                                          6.9s
------
 > [ 7/10] RUN poetry install:
#0 0.367 Skipping virtualenv creation, as specified in config file.
#0 0.931 Installing dependencies from lock file
#0 1.716
#0 1.716 Package operations: 81 installs, 1 update, 1 removal
#0 1.716
#0 1.717   • Removing setuptools (65.5.0)
#0 1.933   • Installing smmap (5.0.0)
#0 2.558   • Installing gitdb (4.0.9)
#0 2.559   • Installing mccabe (0.6.1)
#0 2.560   • Installing pbr (5.11.0)
#0 2.562   • Installing pycodestyle (2.8.0)
#0 2.564   • Installing pyflakes (2.4.0)
#0 3.497   • Installing docutils (0.19)
#0 3.498   • Installing flake8 (4.0.1)
#0 3.499   • Installing gitpython (3.1.29)
#0 3.500   • Installing pyyaml (6.0)
#0 3.502   • Installing sniffio (1.3.0)
#0 3.504   • Installing snowballstemmer (2.2.0)
#0 3.505   • Installing stevedore (4.1.0)
#0 4.560   • Installing anyio (3.6.2)
#0 4.562   • Installing attrs (22.1.0)
#0 4.563   • Installing bandit (1.7.4)
#0 4.563   • Installing eradicate (2.1.0)
#0 4.564   • Installing exceptiongroup (1.0.0)
#0 4.568   • Installing flake8-polyfill (1.0.2)
#0 4.569   • Installing iniconfig (1.1.1)
#0 4.569   • Installing h11 (0.12.0)
#0 4.570   • Installing isort (5.10.1)
#0 5.331   • Updating packaging (20.9 -> 21.3)
#0 5.438   • Installing pluggy (1.0.0)
#0 5.491   • Installing pydocstyle (6.1.1)
#0 5.512   • Installing pygments (2.13.0)
#0 5.572   • Installing restructuredtext-lint (1.4.0)
#0 5.605   • Installing tomli (2.0.1)
#0 5.617   • Installing typing-extensions (4.4.0)
#0 6.288
#0 6.288   EnvCommandError
#0 6.288
#0 6.288   Command ['/usr/local/bin/python', '-m', 'pip', 'install', '--no-deps', '/root/.cache/pypoetry/artifacts/04/32/b5/e5036c2c17882570082f8f5147166579794efaa6ebc2fc7ab5a0aea9cb/restructuredtext_lint-1.4.0.tar.gz'] errored with the following return code 1, and output:
#0 6.288   Processing /root/.cache/pypoetry/artifacts/04/32/b5/e5036c2c17882570082f8f5147166579794efaa6ebc2fc7ab5a0aea9cb/restructuredtext_lint-1.4.0.tar.gz
#0 6.288       ERROR: Command errored out with exit status 1:
#0 6.288        command: /usr/local/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-4yuak16k/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-4yuak16k/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-gjjq5qo1
#0 6.288            cwd: /tmp/pip-req-build-4yuak16k/
#0 6.288       Complete output (3 lines):
#0 6.288       Traceback (most recent call last):
#0 6.288         File "<string>", line 1, in <module>
#0 6.288       ModuleNotFoundError: No module named 'setuptools'
#0 6.288       ----------------------------------------
#0 6.288   WARNING: Discarding file:///root/.cache/pypoetry/artifacts/04/32/b5/e5036c2c17882570082f8f5147166579794efaa6ebc2fc7ab5a0aea9cb/restructuredtext_lint-1.4.0.tar.gz. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#0 6.288   ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#0 6.288   WARNING: You are using pip version 21.2.4; however, version 22.3 is available.
#0 6.288   You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
#0 6.288
#0 6.289
#0 6.289   at /usr/local/lib/python3.9/site-packages/poetry/utils/env.py:1195 in _run
#0 6.317       1191│                 output = subprocess.check_output(
#0 6.317       1192│                     cmd, stderr=subprocess.STDOUT, **kwargs
#0 6.317       1193│                 )
#0 6.317       1194│         except CalledProcessError as e:
#0 6.317     → 1195│             raise EnvCommandError(e, input=input_)
#0 6.317       1196│
#0 6.318       1197│         return decode(output)
#0 6.318       1198│
#0 6.318       1199│     def execute(self, bin, *args, **kwargs):
#0 6.318
------
failed to solve: executor failed running [/bin/sh -c poetry install]: exit code: 1
jegork commented 1 year ago

I was able to fix it by changing poetry version to poetry==1.2.0 in Dockerfile.

Btw, the error was encountered on M1 Mac, no idea about the status of the problem on other hardware/OS.

s3rius commented 1 year ago

Wow. Thanks for providing a solution. I guess I have to bump poetry's version then.

If you don't mind, I'll leave this feature open until I create a release with updated version.

jegork commented 1 year ago

@s3rius no problem! Thanks for a quick update.

sorasful commented 1 year ago

I also came across this, you can use 1.2.2 version. But you'll also need to update the version in the .gitalb-ci.yml otherwise tests won't work. https://github.com/s3rius/FastAPI-template/blob/master/fastapi_template/template/%7B%7Bcookiecutter.project_name%7D%7D/.gitlab-ci.yml#L13

s3rius commented 1 year ago

Will add today.