add poetry to project

This commit is contained in:
Jakub Miazek
2022-10-03 14:29:17 +02:00
parent 7b079f84c1
commit 68eca7c0f6
8 changed files with 2106 additions and 1369 deletions

View File

@@ -1,20 +1,41 @@
# Pull base image
FROM python:3.10-slim-buster as builder
FROM python:3.10-slim AS base
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends curl git build-essential \
&& apt-get autoremove -y
ENV POETRY_HOME="/opt/poetry"
RUN curl -sSL https://install.python-poetry.org | python3 -
# Set environment variables
COPY requirements.txt requirements.txt
FROM base AS install
WORKDIR /home/code
# Install pipenv
RUN set -ex && pip install --upgrade pip
# allow controlling the poetry installation of dependencies via external args
ARG INSTALL_ARGS="--no-root --no-dev"
ENV POETRY_HOME="/opt/poetry"
ENV PATH="$POETRY_HOME/bin:$PATH"
COPY pyproject.toml poetry.lock ./
# Install dependencies
RUN set -ex && pip install -r requirements.txt
# install without virtualenv, since we are inside a container
RUN poetry config virtualenvs.create false \
&& poetry install $INSTALL_ARGS
FROM builder as final
WORKDIR /code
COPY app/ /code/
COPY ./tests/ /code/
COPY .env /code/
# cleanup
RUN curl -sSL https://install.python-poetry.org | python3 - --uninstall
RUN apt-get purge -y curl git build-essential \
&& apt-get clean -y \
&& rm -rf /root/.cache \
&& rm -rf /var/apt/lists/* \
&& rm -rf /var/cache/apt/*
FROM install as app-image
COPY tests tests
COPY app app
COPY alembic alembic
COPY .env alembic.ini ./
# create a non-root user and switch to it, for security.
RUN addgroup --system --gid 1001 "app-user"
RUN adduser --system --uid 1001 "app-user"
USER "app-user"
RUN set -ex && bash -c "eval $(grep 'PYTHONDONTWRITEBYTECODE' .env)"
RUN set -ex && bash -c "eval $(grep 'PYTHONUNBUFFERED' .env)"