66 lines
2.0 KiB
Plaintext
66 lines
2.0 KiB
Plaintext
FROM python:3.12-slim
|
|
|
|
ARG CONFIG=production
|
|
|
|
# Install TA-Lib C library early for better layer caching
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
g++ \
|
|
make \
|
|
wget \
|
|
ca-certificates \
|
|
&& wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz \
|
|
&& tar -xzf ta-lib-0.4.0-src.tar.gz \
|
|
&& cd ta-lib/ \
|
|
&& ./configure --prefix=/usr \
|
|
&& make \
|
|
&& make install \
|
|
&& cd .. \
|
|
&& rm -rf ta-lib ta-lib-0.4.0-src.tar.gz \
|
|
&& apt-get purge -y --auto-remove gcc g++ make wget ca-certificates \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Python build dependencies early for better layer caching
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
g++ \
|
|
cargo \
|
|
rustc
|
|
|
|
# Install compiled packages - separate layer so requirements.txt changes don't trigger recompilation
|
|
COPY backend/requirements-pre.txt /app/requirements-pre.txt
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
--mount=type=cache,target=/root/.cargo \
|
|
pip install --no-cache-dir -r /app/requirements-pre.txt \
|
|
&& apt-get purge -y --auto-remove gcc g++ cargo rustc \
|
|
&& rm -rf /var/lib/apt/lists/* /root/.rustup /tmp/*
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy and install remaining requirements
|
|
COPY backend/requirements.txt /app/requirements.txt
|
|
|
|
# Install Python dependencies and clean up
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy application code
|
|
COPY backend/src /app/src
|
|
COPY backend/config*.yaml /tmp/
|
|
RUN if [ -f /tmp/config-${CONFIG}.yaml ]; then \
|
|
cp /tmp/config-${CONFIG}.yaml /app/config.yaml; \
|
|
else \
|
|
cp /tmp/config.yaml /app/config.yaml; \
|
|
fi && rm -rf /tmp/config*.yaml
|
|
|
|
# Add src to PYTHONPATH for correct module resolution
|
|
ENV PYTHONPATH=/app/src
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Run the application
|
|
CMD ["python", "-m", "uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
|