-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile-app-serving
78 lines (58 loc) · 2.21 KB
/
Dockerfile-app-serving
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# https://github.com/tiangolo/uvicorn-gunicorn-docker/blob/master/docker-images/start.sh
# https://github.com/Swiple/swiple/blob/main/backend/Dockerfile
# https://github.com/michaeloliverx/python-poetry-docker-example/blob/master/docker/Dockerfile
# https://www.reddit.com/r/django/comments/1az7z6a/django_gunicorn_do_you_guys_use_maxrequests_and/
# Base Python image
FROM python:3.10.14-slim AS python-base
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.8.3 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
# Builder stage
FROM python-base AS builder-base
# Install system dependencies
RUN apt-get update && apt-get install --no-install-recommends -y \
curl \
build-essential
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python -
# Install Python dependencies
WORKDIR $PYSETUP_PATH
COPY pyproject.toml ./
RUN poetry install --only main
# Development stage
FROM python-base AS development
ENV FASTAPI_ENV=development
# Copy Poetry and venv
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
# Set up retrieval app directory
WORKDIR /retrieval_app
COPY . ./
EXPOSE 30000
CMD ["poetry", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "30000", "--reload"]
# Production stage
FROM python-base AS production
ENV FASTAPI_ENV=production
# Copy Poetry and venv
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
curl
# Set up app directory
WORKDIR /retrieval_app
COPY . ./
RUN chmod +x prestart.sh
# You must use ./start.sh to run the start.sh file from current directory. /start.sh run start.sh in root /, which does not exist.
ENTRYPOINT ./prestart.sh $0 $@
CMD ["poetry", "run", "gunicorn", "app.main:app", "--worker-class", "uvicorn.workers.UvicornWorker", "--config ./gunicorn_conf.py"]