Yannick Stephan commited on
Commit
c5c767d
·
1 Parent(s): 0a5b937

[Project] Init Docker

Browse files
Files changed (1) hide show
  1. Dockerfile +153 -0
Dockerfile ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### ------
2
+ ### The builder image, used to build the virtual environment
3
+ ### ------
4
+
5
+ # Start with a minimal Python 3.11 base image based on Debian Buster
6
+ FROM python:3.11-slim-buster
7
+
8
+ ### ------
9
+ ### Set up user
10
+ ### ------
11
+
12
+ RUN useradd -m -u 1000 user
13
+
14
+ ### ------
15
+ ### Set up Python environment variables
16
+ ### ------
17
+
18
+ # Ensures Python output is sent directly to the terminal (no buffering)
19
+ ENV PYTHONUNBUFFERED=1 \
20
+ # Prevents Python from writing .pyc files (compiled bytecode)
21
+ PYTHONDONTWRITEBYTECODE=1 \
22
+ ### pip configuration to optimize the installation process
23
+ # Do not cache pip packages
24
+ PIP_NO_CACHE_DIR=off \
25
+ # Disable pip version checking
26
+ PIP_DISABLE_PIP_VERSION_CHECK=on \
27
+ # Set a longer timeout for pip commands (100 seconds)
28
+ PIP_DEFAULT_TIMEOUT=100 \
29
+ ### poetry configuration to install and manage dependencies
30
+ # Set the version of Poetry to use
31
+ POETRY_VERSION=1.4.2 \
32
+ # Define the location where Poetry will be installed
33
+ POETRY_HOME="/opt/poetry" \
34
+ #POETRY_HOME="/home/user/.local" \
35
+ # Create the virtual environment inside the project folder
36
+ POETRY_VIRTUALENVS_IN_PROJECT=true \
37
+ # Ensure Poetry creates virtual environments for the project
38
+ POETRY_VIRTUALENVS_CREATE=1 \
39
+ # Prevent Poetry from asking for interactive input during install
40
+ POETRY_NO_INTERACTION=1 \
41
+ ### Define paths for the virtual environment and Python setup
42
+ # Define where Python setup files will reside
43
+ # Define where the virtual environment will be created
44
+ PYSETUP_PATH="/opt/pysetup" \
45
+ #PYSETUP_PATH="/opt/pysetup" \
46
+ VENV_PATH="/opt/pysetup/.venv" \
47
+ # PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" \
48
+ ### Hugging Face
49
+ # Set Hugging Face to offline mode to avoid network access
50
+ HF_HUB_OFFLINE=0 \
51
+ NLTK_DATA="/home/user/nltk/" \
52
+ # Store files
53
+ DATA_DIR="/app/data/" \
54
+ # Set the custom Poetry configuration directory
55
+ POETRY_CONFIG_DIR="$POETRY_HOME/.config/pypoetry" \
56
+ PASSLIB_BUILTIN_BCRYPT="enabled"
57
+
58
+ # Add Poetry and virtual environment to the system PATH (Note add after declared ENV)
59
+ ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
60
+
61
+ ### ------
62
+ ### Package
63
+ ### ------
64
+
65
+ # Update package lists and install required build dependencies
66
+ RUN apt-get update \
67
+ && apt-get install --no-install-recommends -y \
68
+ # Install curl to download files from the internet
69
+ curl \
70
+ # Install essential build tools (for building Poetry and other packages)
71
+ build-essential \
72
+ wget \
73
+ git \
74
+ openssh-client \
75
+ && curl -sSL https://install.python-poetry.org | python3 - \
76
+ # Remove build tools after installation to reduce image size
77
+ && apt-get purge -y --auto-remove build-essential \
78
+ # Clean up apt cache to minimize image size
79
+ && apt-get clean \
80
+ # Remove leftover lists to further reduce image size
81
+ && rm -rf /var/lib/apt/lists/*
82
+
83
+ ### ------
84
+ ### Create DIRs
85
+ ### ------
86
+
87
+ WORKDIR /app
88
+ WORKDIR /repo
89
+
90
+ ### ------
91
+ ### Git Clone secret
92
+ ### ------
93
+
94
+ RUN --mount=type=secret,id=TAG,mode=0444,required=true \
95
+ --mount=type=secret,id=URL,mode=0444,required=true \
96
+ git clone --branch $(cat /run/secrets/TAG) $(cat /run/secrets/URL) /repo
97
+
98
+ ### ------
99
+ ### Copy file
100
+ ### ------
101
+
102
+ RUN cp -r /repo/api_writer/* /app/
103
+ RUN cp -r /repo/gary /app/gary
104
+ RUN rm -rf /repo
105
+
106
+ ### ------
107
+ ### Modif path of Lib
108
+ ### ------
109
+
110
+ WORKDIR /app
111
+
112
+ RUN sed -i 's/\.\.\/gary/gary/g' pyproject.toml
113
+
114
+ ### ------
115
+ ### Install project dependencies using Poetry
116
+ ### ------
117
+
118
+ # Move to gary and install need optional lib
119
+ WORKDIR /app/gary
120
+ # Install only the dependencies needed (Mango and pymupdf)
121
+ RUN poetry install --no-interaction --with mangodb --with pymupdf \
122
+ # Clean up the Poetry cache to reduce image size
123
+ && rm -rf $POETRY_CACHE_DIR
124
+
125
+ WORKDIR /app
126
+
127
+ # Optimize Poetry's performance with more parallel workers
128
+ RUN poetry config installer.max-workers 10 \
129
+ # Install only the dependencies needed
130
+ && poetry install --no-interaction --no-dev \
131
+ # Clean up the Poetry cache to reduce image size
132
+ && rm -rf $POETRY_CACHE_DIR
133
+
134
+ # Create the custom Poetry configuration directory and set permissions
135
+ RUN mkdir -p $POETRY_CONFIG_DIR && \
136
+ # Create the NTLK folder (llama)
137
+ mkdir -p $NLTK_DATA && \
138
+ # Create the folder store files
139
+ mkdir -p $DATA_DIR && \
140
+ chown -R user:user $POETRY_CONFIG_DIR && \
141
+ chown -R user:user $NLTK_DATA && \
142
+ chown -R user:user $DATA_DIR && \
143
+ chmod -R 777 $DATA_DIR
144
+
145
+ ### ------
146
+ ### Command to run
147
+ ### ------
148
+
149
+ # Expose the port FastAPI will run on
150
+ EXPOSE 7860
151
+
152
+ # This command starts the API using Poetry's virtual environment
153
+ CMD ["poetry", "run", "api"]