# https://stackoverflow.com/questions/53835198/integrating-python-poetry-with-docker/54763270#54763270

FROM python:3.9


# --------------------------------------
# ------------- Set labels -------------

# See https://github.com/opencontainers/image-spec/blob/master/annotations.md
LABEL name="$${project}"
LABEL version="$${version}"
LABEL vendor="$${user}"
LABEL org.opencontainers.image.title="$${project}"
LABEL org.opencontainers.image.version="$${version}"
LABEL org.opencontainers.image.url="https://github.com/$${user}/$${project}"
LABEL org.opencontainers.image.documentation="https://github.com/$${user}/$${project}"


# --------------------------------------
# ---------- Copy and install ----------

# Configure env variables for build/install
# ENV no longer adds a layer in new Docker versions,
# so we don't need to chain these in a single line
ENV PYTHONFAULTHANDLER=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONHASHSEED=random
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=120
ENV POETRY_VERSION=1.1.4

# Install system deps
RUN pip install "poetry==$POETRY_VERSION"

# Copy only requirements to cache them in docker layer
WORKDIR /code
COPY poetry.lock pyproject.toml /code/

# Install with poetry
# pip install would probably work, too, but we'd have to make sure it's a recent enough pip
# Don't bother creating a virtual env -- significant performance increase
RUN poetry config virtualenvs.create false \
  && poetry install --no-interaction --no-ansi

# Copy everything (code) to our workdir
# Our .dockerignore file should be good enough that we don't have extra stuff
COPY . /code


# --------------------------------------
# --------------- Run! -----------------

# Now do something!
CMD $${pkg} --help

# Perhaps run a command:
# CMD $${pkg} --my --options --etc
# or expose a port:
# EXPOSE 443/tcp
