fengmiguoji commited on
Commit
256f8e4
·
verified ·
1 Parent(s): 954689c

Upload api\Dockerfile with huggingface_hub

Browse files
Files changed (1) hide show
  1. api//Dockerfile +90 -0
api//Dockerfile ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # base image
2
+ FROM python:3.12-slim-bookworm AS base
3
+
4
+ WORKDIR /app/api
5
+
6
+ # Install Poetry
7
+ ENV POETRY_VERSION=2.0.1
8
+
9
+ # if you located in China, you can use aliyun mirror to speed up
10
+ # RUN pip install --no-cache-dir poetry==${POETRY_VERSION} -i https://mirrors.aliyun.com/pypi/simple/
11
+
12
+ RUN pip install --no-cache-dir poetry==${POETRY_VERSION}
13
+
14
+ # Configure Poetry
15
+ ENV POETRY_CACHE_DIR=/tmp/poetry_cache
16
+ ENV POETRY_NO_INTERACTION=1
17
+ ENV POETRY_VIRTUALENVS_IN_PROJECT=true
18
+ ENV POETRY_VIRTUALENVS_CREATE=true
19
+ ENV POETRY_REQUESTS_TIMEOUT=15
20
+
21
+ FROM base AS packages
22
+
23
+ # if you located in China, you can use aliyun mirror to speed up
24
+ # RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources
25
+
26
+ RUN apt-get update \
27
+ && apt-get install -y --no-install-recommends gcc g++ libc-dev libffi-dev libgmp-dev libmpfr-dev libmpc-dev
28
+
29
+ # Install Python dependencies
30
+ COPY pyproject.toml poetry.lock ./
31
+ RUN poetry install --sync --no-cache --no-root
32
+
33
+ # production stage
34
+ FROM base AS production
35
+
36
+ ENV FLASK_APP=app.py
37
+ ENV EDITION=SELF_HOSTED
38
+ ENV DEPLOY_ENV=PRODUCTION
39
+ ENV CONSOLE_API_URL=http://127.0.0.1:5001
40
+ ENV CONSOLE_WEB_URL=http://127.0.0.1:3000
41
+ ENV SERVICE_API_URL=http://127.0.0.1:5001
42
+ ENV APP_WEB_URL=http://127.0.0.1:3000
43
+
44
+ EXPOSE 5001
45
+
46
+ # set timezone
47
+ ENV TZ=UTC
48
+
49
+ WORKDIR /app/api
50
+
51
+ RUN \
52
+ apt-get update \
53
+ # Install dependencies
54
+ && apt-get install -y --no-install-recommends \
55
+ # basic environment
56
+ curl nodejs libgmp-dev libmpfr-dev libmpc-dev \
57
+ # For Security
58
+ expat libldap-2.5-0 perl libsqlite3-0 zlib1g \
59
+ # install a chinese font to support the use of tools like matplotlib
60
+ fonts-noto-cjk \
61
+ # install a package to improve the accuracy of guessing mime type and file extension
62
+ media-types \
63
+ # install libmagic to support the use of python-magic guess MIMETYPE
64
+ libmagic1 \
65
+ && apt-get autoremove -y \
66
+ && rm -rf /var/lib/apt/lists/*
67
+
68
+ # Copy Python environment and packages
69
+ ENV VIRTUAL_ENV=/app/api/.venv
70
+ COPY --from=packages ${VIRTUAL_ENV} ${VIRTUAL_ENV}
71
+ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
72
+
73
+ # Download nltk data
74
+ RUN python -c "import nltk; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger')"
75
+
76
+ ENV TIKTOKEN_CACHE_DIR=/app/api/.tiktoken_cache
77
+
78
+ RUN python -c "import tiktoken; tiktoken.encoding_for_model('gpt2')"
79
+
80
+ # Copy source code
81
+ COPY . /app/api/
82
+
83
+ # Copy entrypoint
84
+ COPY docker/entrypoint.sh /entrypoint.sh
85
+ RUN chmod +x /entrypoint.sh
86
+
87
+ ARG COMMIT_SHA
88
+ ENV COMMIT_SHA=${COMMIT_SHA}
89
+
90
+ ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]