Skip to content

Instantly share code, notes, and snippets.

@joeld1
Last active April 28, 2021 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeld1/e6c9193972b39fa91e0318de30ee6060 to your computer and use it in GitHub Desktop.
Save joeld1/e6c9193972b39fa91e0318de30ee6060 to your computer and use it in GitHub Desktop.
Installing Poetry on Docker Image - tiangolo/uvicorn-gunicorn-fastapi:python3.8
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment