Created
April 29, 2023 08:42
-
-
Save vbogretsov/59bbd3b6db216be6e46bfa777efa4eff to your computer and use it in GitHub Desktop.
python docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG PYTHON_VERSION=3.11 | |
ARG ALPINE_VERSION=3.17 | |
ARG POETRY_VERSION=1.3.2 | |
ARG DEVBUILD | |
FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION} as build | |
ARG ALPINE_VERSION | |
ARG POETRY_VERSION | |
ARG DEVBUILD | |
RUN echo https://mirror.yandex.ru/mirrors/alpine/v${ALPINE_VERSION}/main > /etc/apk/repositories | |
RUN echo https://mirror.yandex.ru/mirrors/alpine/v${ALPINE_VERSION}/community >> /etc/apk/repositories | |
RUN apk update | |
RUN apk add gcc musl-dev libffi-dev | |
RUN pip install poetry==${POETRY_VERSION} | |
RUN poetry config virtualenvs.create false | |
WORKDIR /src | |
COPY poetry.lock . | |
COPY pyproject.toml . | |
RUN python -m venv /opt | |
RUN source /opt/bin/activate && poetry install --no-root $( [ $DEVBUILD ] || echo --no-dev ) | |
FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION} | |
ARG PYTHON_VERSION | |
COPY --from=build /opt /opt | |
ENV \ | |
PYTHONUNBUFFERED=1 \ | |
PYTHONPATH=/app:/app/src:/opt/lib/python${PYTHON_VERSION}/site-packages:$PYTHONPATH \ | |
PATH=/opt/bin:$PATH | |
RUN adduser -h /app -D app | |
COPY . . | |
USER app | |
WORKDIR /app | |
EXPOSE 443 | |
ENTRYPOINT ["uvicorn", "app:app", "--reload", "--host", "0.0.0.0", "--port", "443", "--ssl-keyfile", "/ssl/key.pem", "--ssl-certfile", "/ssl/crt.pem"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment