-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
74 lines (62 loc) · 1.8 KB
/
Dockerfile
File metadata and controls
74 lines (62 loc) · 1.8 KB
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
FROM python:3.11-slim as base
# Install Python dependencies in an intermediate image
# as some requires a compiler (psycopg2)
FROM base as builder
# Install dependencies required to compile some Python packages
# Taken from https://github.com/docker-library/python/blob/master/3.11/slim-bullseye/Dockerfile
# For psycopg2: libpq-dev
RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
dpkg-dev \
gcc \
gnupg dirmngr \
libbluetooth-dev \
libbz2-dev \
libc6-dev \
libexpat1-dev \
libffi-dev \
libgdbm-dev \
liblzma-dev \
libncursesw5-dev \
libpq-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
make \
tk-dev \
uuid-dev \
wget \
xz-utils \
zlib1g-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt /requirements.txt
RUN python3 -m venv /venv \
&& . /venv/bin/activate \
&& pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r /requirements.txt \
&& pip install --no-cache-dir psycopg2
FROM base
RUN groupadd -r -g 1000 csi \
&& useradd --no-log-init -r -g csi -u 1000 csi
COPY --chown=csi:csi --from=builder /venv /venv
# Install libraries for psycopg2
RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
libpq5 \
git \
vim \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --chown=csi:csi . /app/
WORKDIR /app
ENV PATH /venv/bin:$PATH
USER 1000
# Install the app so it can be found by alembic
RUN pip install --no-cache-dir .
# Running uvicorn is for testing
# For production, run using Gunicorn using the uvicorn worker class
# Use one or two workers per-CPU core
# For example:
# gunicorn -b 0.0.0.0:8000 -w 4 -k uvicorn.workers.UvicornWorker --log-level info app.main:app
CMD ["uvicorn", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000", "app.main:app"]