tiangolo / uvicorn-gunicorn-fastapi-docker

Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python with performance auto-tuning.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update Poetry Installation Documentation for Dockerfile examples

joeld1 opened this issue · comments

commented

Hello!

I'm reaching out because I ran into some issues installing Poetry dependencies yesterday.

I realized that my issue was caused as a result of Poetry updating and deprecating the preferred installation method from:

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -

to

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -

I couldn't figure out my issue until taking a closer look at the directories. Downside, I spent a day on this; upside, I learned.

From tinkering around with the Dockerfile I discovered that:

  • If installing using get-poetry.py, we have the following folder /opt/poetry/env
  • If using install-poetry.py, we have /opt/poetry/venv
  • The difference between these two is env vs venv, which causes poetry install to improperly install

I had no idea until taking a closer look (see Dockerfile below, or gist).

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8

RUN pip install --upgrade pip

ARG poetry_version="master"
# install-poetry.py and get-poetry.py are options; but get-poetry.py is deprecated though!
ARG poetry_script_name="install-poetry.py"
ARG debug_poetry="true"
ENV PATH="/opt/poetry/bin:${PATH}"
# Install Poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/${poetry_version}/${poetry_script_name} | POETRY_HOME=/opt/poetry python && \
    cd /usr/local/bin && \
    ln -s /opt/poetry/bin/poetry && poetry config virtualenvs.create false && poetry config virtualenvs.in-project false && poetry config experimental.new-installer false

RUN if [ ${debug_poetry} = "true" ] ; then echo $debug_poetry && apt-get update && apt-get install -y tree && cd /opt && tree -la . ; fi

# Copy using poetry.lock* in case it doesn't exist yet
COPY ./app/pyproject.toml ./app/poetry.lock* /app/
WORKDIR /app/

# If using get-poetry.py - /opt/poetry/env instead of /opt/poetry/venv
RUN if [ ${poetry_script_name} = "get-poetry.py" ]; then which python && . /opt/poetry/env && poetry install --no-root --no-dev && poetry env info ; fi

# If using install-poetry.py - /opt/poetry/venv instead of /opt/poetry/env
RUN if [ ${debug_poetry} = "true" ] ; then echo $debug_poetry && apt-get update && apt-get install -y tree && cd /usr/local/bin && tree -la . ; fi

RUN if [ ${poetry_script_name} = "install-poetry.py" ]; then poetry export -f requirements.txt --output requirements.txt && pip install --no-cache-dir -r requirements.txt ; fi

# TODO: fix this once https://github.com/python-poetry/poetry/issues/3870 gets resolved
#RUN if [ ${poetry_script_name} = "install-poetry.py" ]; then which python && cd /usr/local/bin/ && poetry config --list && poetry config virtualenvs.create false && cd /app/ && poetry env use `which python` && poetry install --no-root --no-dev -vvv && poetry env info ; fi

# Resources for learning Bash if statements
# https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php

# Running pip list below to use output to verify that our pyproject.toml file has been installed correctly
RUN pip list

# Final copy
COPY ./app /app

As such, I wanted to raise this issue and make this comment in case any other people are having similar issues with the new install-poetry.py method. This issue is also raised here, but in poetry's channel

Thanks for everything!

JD