Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 2 additions & 79 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM python:3.11-slim-bookworm AS builder
FROM python:3.11-slim-bookworm

USER root

# Add NVIDIA CUDA repository for cuDNN (only in builder stage)
# Add NVIDIA CUDA repository for cuDNN
RUN apt-get update -y && apt-get install -y wget gnupg2 ca-certificates && \
wget https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/cuda-keyring_1.1-1_all.deb && \
dpkg -i cuda-keyring_1.1-1_all.deb && \
Expand Down Expand Up @@ -89,82 +89,5 @@ RUN /code/.venv/bin/gunicorn --version
# Copy application source code
COPY --chown=troc:troc . .

# ============================================
# Runtime Stage (lightweight final image)
# ============================================
# This multi-stage build optimizes the final image size by:
# 1. Builder stage: Installs NVIDIA CUDA repos, cuDNN dev libraries, and all build tools
# needed to compile Python dependencies (gcc, g++, development headers, etc.)
# 2. Runtime stage: Creates a clean image with only runtime libraries (libcudnn8 without -dev)
# and copies the built artifacts from the builder stage
# Result: Final image contains cuDNN support without heavy compilation tools,
# significantly reducing image size while maintaining GPU acceleration capabilities
FROM python:3.11-slim-bookworm AS runtime

USER root

# Add NVIDIA CUDA repository for runtime cuDNN libraries only
RUN apt-get update -y && apt-get install -y wget gnupg2 ca-certificates && \
wget https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/cuda-keyring_1.1-1_all.deb && \
dpkg -i cuda-keyring_1.1-1_all.deb && \
rm cuda-keyring_1.1-1_all.deb && \
apt-get update -y

# Install only runtime dependencies (no -dev packages, no build tools)
RUN apt-get install -y \
libpq5 postgresql-client \
libxml2 libxslt1.1 \
libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi8 \
libmemcached11 libyaml-0-2 \
netcat-traditional libmagic1 libgeos-c1v5 libaio1 \
libmariadb3 locales locales-all \
unixodbc libsqliteodbc \
freetds-bin redis-tools vim-tiny libexempi8 \
ffmpeg libcudnn8 \
sudo && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# Locales setup
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
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 && \
update-locale

# Set environment variables for the locale
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
ENV LANG_ZH_CN=zh_CN.UTF-8
ENV LANG_ZH_TW=zh_TW.UTF-8
ENV LANG_KO=ko.UTF-8
ENV LANG_JA=ja.UTF-8
ENV LANG_TR=tr.UTF-8
ENV LANG_ES=es_ES.UTF-8
ENV LANG_DE=de.UTF-8
ENV LANG_FR=fr.UTF-8
ENV LANG_PT_BR=pt_BR.UTF-8
ENV LANG_PT_PT=pt_PT.UTF-8

# Create user 'troc'
RUN useradd --create-home --user-group troc && \
mkdir -p /home/troc/.ssh && \
chmod -R 770 /home/troc && \
chown -R troc:troc /home/troc && \
adduser troc sudo && \
echo "troc ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

# Setup directories
RUN mkdir -p /code /home/ubuntu/symbits /var/log/troc/ && \
chown troc:troc /code /home/ubuntu/symbits /var/log/troc/

# Copy from builder stage
COPY --from=builder --chown=troc:troc /code /code
COPY --from=builder --chown=troc:troc /home/troc/.local /home/troc/.local

USER troc
WORKDIR /code

ENV SITE_ROOT=/code
ENV PATH="/code/.venv/bin:/home/troc/.local/bin:$PATH"

# Expose port (adjust if necessary)
EXPOSE 5000
Loading