mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
44 lines
1.2 KiB
Docker
44 lines
1.2 KiB
Docker
FROM python:3.11-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 -
|
|
|
|
FROM base AS install
|
|
WORKDIR /home/code
|
|
|
|
# allow controlling the poetry installation of dependencies via external args
|
|
ARG INSTALL_ARGS="--no-root --only main"
|
|
ENV POETRY_HOME="/opt/poetry"
|
|
ENV PATH="$POETRY_HOME/bin:$PATH"
|
|
COPY pyproject.toml poetry.lock ./
|
|
|
|
# install without virtualenv, since we are inside a container
|
|
RUN poetry config virtualenvs.create false \
|
|
&& poetry install $INSTALL_ARGS
|
|
|
|
# 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
|
|
|
|
ENV PYTHONPATH=/home/code/ PYTHONHASHSEED=0
|
|
|
|
COPY tests/ tests/
|
|
COPY app/ app/
|
|
COPY alembic/ alembic/
|
|
COPY .env alembic.ini config.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"
|
|
|