-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
73 lines (53 loc) · 2.55 KB
/
Dockerfile
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
ARG PYTHON_VERSION=3.10
# -- 1st stage --------------------------------------------------------------------------------------
FROM python:${PYTHON_VERSION}-slim AS builder
# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1
# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1
# NOTE: libpq-dev and build-essential is needed for psycopg2 to build (SQLAlchemy dependency)
RUN apt update && apt install -y --no-install-recommends \
# git \
libpq-dev \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Got the multi-stage venv technique from https://pythonspeed.com/articles/multi-stage-docker-python/
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
# Leverage a bind mount to requirements.txt to avoid having to copy them into
# into this layer.
RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \
python -m pip install -r requirements.txt
# -- 2nd stage --------------------------------------------------------------------------------------
FROM python:${PYTHON_VERSION}-slim AS runtime
# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1
# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# NOTE: poppler-utils needed by pdf2image, libopus0 needed to join vc, ffmpeg needed by jsk vc yt cmd
RUN apt update && apt install -y --no-install-recommends \
poppler-utils \
libopus0 \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
# -- dev stage --------------------------------------------------------------------------------------
FROM runtime AS dev
# Create a directory to temporarily store speechtotext cmd input audio files
# NOTE: directory to store voicelisten cmd output audio files is mounted instead
RUN mkdir /temp
# -- prod stage -------------------------------------------------------------------------------------
FROM runtime AS prod
WORKDIR /app
# Create a directory to temporarily store speechtotext cmd input audio files
# NOTE: directory to store voicelisten cmd output audio files is mounted instead
RUN mkdir /app/temp
# Copy the source code into the container.
COPY . .
CMD ["python", "bot.py"]