forked from ernstleierzopf/ncid
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Dockerfile
51 lines (36 loc) · 1.08 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
# base python image version
ARG PYTHON_VERSION=3.11-slim-bookworm
# base image
# ============
FROM python:${PYTHON_VERSION} as base
# configure python
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# setup virtualenv
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# build image
# =============
FROM base as build-image
# install dependencies
COPY requirements.txt /opt/requirements.txt
RUN sed -i -re 's/^tensorflow\b/tensorflow-cpu/g' /opt/requirements.txt
RUN set -ex \
&& python -m venv --symlinks --clear "$VIRTUAL_ENV" \
&& pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r /opt/requirements.txt \
&& pip install --no-cache-dir "fastapi" "uvicorn[standard]"
# api image
# ======================
FROM base as api
EXPOSE 4343
# copy virtualenv
COPY --from=build-image "$VIRTUAL_ENV" "$VIRTUAL_ENV"
# create source directory
RUN mkdir -p /opt/ncid/
WORKDIR /opt/ncid
# change to non-root user
RUN useradd apiuser
USER apiuser
COPY --chown=apiuser:apiuser . /opt/ncid
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "4343"]