|
1 | | -FROM python:3.11-slim-bookworm AS builder |
| 1 | +FROM python:3.11-slim-bookworm |
2 | 2 |
|
3 | 3 | USER root |
4 | 4 |
|
5 | | -# Add NVIDIA CUDA repository for cuDNN (only in builder stage) |
| 5 | +# Add NVIDIA CUDA repository for cuDNN |
6 | 6 | RUN apt-get update -y && apt-get install -y wget gnupg2 ca-certificates && \ |
7 | 7 | wget https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/cuda-keyring_1.1-1_all.deb && \ |
8 | 8 | dpkg -i cuda-keyring_1.1-1_all.deb && \ |
@@ -89,82 +89,5 @@ RUN /code/.venv/bin/gunicorn --version |
89 | 89 | # Copy application source code |
90 | 90 | COPY --chown=troc:troc . . |
91 | 91 |
|
92 | | -# ============================================ |
93 | | -# Runtime Stage (lightweight final image) |
94 | | -# ============================================ |
95 | | -# This multi-stage build optimizes the final image size by: |
96 | | -# 1. Builder stage: Installs NVIDIA CUDA repos, cuDNN dev libraries, and all build tools |
97 | | -# needed to compile Python dependencies (gcc, g++, development headers, etc.) |
98 | | -# 2. Runtime stage: Creates a clean image with only runtime libraries (libcudnn8 without -dev) |
99 | | -# and copies the built artifacts from the builder stage |
100 | | -# Result: Final image contains cuDNN support without heavy compilation tools, |
101 | | -# significantly reducing image size while maintaining GPU acceleration capabilities |
102 | | -FROM python:3.11-slim-bookworm AS runtime |
103 | | - |
104 | | -USER root |
105 | | - |
106 | | -# Add NVIDIA CUDA repository for runtime cuDNN libraries only |
107 | | -RUN apt-get update -y && apt-get install -y wget gnupg2 ca-certificates && \ |
108 | | - wget https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/cuda-keyring_1.1-1_all.deb && \ |
109 | | - dpkg -i cuda-keyring_1.1-1_all.deb && \ |
110 | | - rm cuda-keyring_1.1-1_all.deb && \ |
111 | | - apt-get update -y |
112 | | - |
113 | | -# Install only runtime dependencies (no -dev packages, no build tools) |
114 | | -RUN apt-get install -y \ |
115 | | - libpq5 postgresql-client \ |
116 | | - libxml2 libxslt1.1 \ |
117 | | - libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi8 \ |
118 | | - libmemcached11 libyaml-0-2 \ |
119 | | - netcat-traditional libmagic1 libgeos-c1v5 libaio1 \ |
120 | | - libmariadb3 locales locales-all \ |
121 | | - unixodbc libsqliteodbc \ |
122 | | - freetds-bin redis-tools vim-tiny libexempi8 \ |
123 | | - ffmpeg libcudnn8 \ |
124 | | - sudo && \ |
125 | | - apt-get clean && rm -rf /var/lib/apt/lists/* |
126 | | - |
127 | | -# Locales setup |
128 | | -RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \ |
129 | | - for lang in en_US.UTF-8 es_ES.UTF-8 zh_CN.UTF-8 zh_TW.UTF-8 fr.UTF-8 de.UTF-8 tr.UTF-8 ja.UTF-8 ko.UTF-8 pt_BR.UTF-8 pt_PT.UTF-8; do locale-gen $lang; done && \ |
130 | | - update-locale |
131 | | - |
132 | | -# Set environment variables for the locale |
133 | | -ENV LANG=en_US.UTF-8 |
134 | | -ENV LANGUAGE=en_US:en |
135 | | -ENV LC_ALL=en_US.UTF-8 |
136 | | -ENV LANG_ZH_CN=zh_CN.UTF-8 |
137 | | -ENV LANG_ZH_TW=zh_TW.UTF-8 |
138 | | -ENV LANG_KO=ko.UTF-8 |
139 | | -ENV LANG_JA=ja.UTF-8 |
140 | | -ENV LANG_TR=tr.UTF-8 |
141 | | -ENV LANG_ES=es_ES.UTF-8 |
142 | | -ENV LANG_DE=de.UTF-8 |
143 | | -ENV LANG_FR=fr.UTF-8 |
144 | | -ENV LANG_PT_BR=pt_BR.UTF-8 |
145 | | -ENV LANG_PT_PT=pt_PT.UTF-8 |
146 | | - |
147 | | -# Create user 'troc' |
148 | | -RUN useradd --create-home --user-group troc && \ |
149 | | - mkdir -p /home/troc/.ssh && \ |
150 | | - chmod -R 770 /home/troc && \ |
151 | | - chown -R troc:troc /home/troc && \ |
152 | | - adduser troc sudo && \ |
153 | | - echo "troc ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers |
154 | | - |
155 | | -# Setup directories |
156 | | -RUN mkdir -p /code /home/ubuntu/symbits /var/log/troc/ && \ |
157 | | - chown troc:troc /code /home/ubuntu/symbits /var/log/troc/ |
158 | | - |
159 | | -# Copy from builder stage |
160 | | -COPY --from=builder --chown=troc:troc /code /code |
161 | | -COPY --from=builder --chown=troc:troc /home/troc/.local /home/troc/.local |
162 | | - |
163 | | -USER troc |
164 | | -WORKDIR /code |
165 | | - |
166 | | -ENV SITE_ROOT=/code |
167 | | -ENV PATH="/code/.venv/bin:/home/troc/.local/bin:$PATH" |
168 | | - |
169 | 92 | # Expose port (adjust if necessary) |
170 | 93 | EXPOSE 5000 |
0 commit comments