FROM python:3.12 # Create non-root user RUN useradd -m -u 1000 user WORKDIR /code # Copy requirements first for caching COPY ./requirements.txt /code/requirements.txt # Install system dependencies USER root RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ curl \ wget \ unzip \ procps \ && rm -rf /var/lib/apt/lists/* # Download and install Elasticsearch RUN wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-9.0.1-linux-x86_64.tar.gz && \ tar -xzf elasticsearch-9.0.1-linux-x86_64.tar.gz && \ mv elasticsearch-9.0.1 /usr/share/elasticsearch && \ rm elasticsearch-9.0.1-linux-x86_64.tar.gz # Copy your ES config COPY elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml # Permissions RUN chown -R user:user /usr/share/elasticsearch /code USER user # Install Python dependencies RUN pip install --no-cache-dir -r /code/requirements.txt # Copy the app COPY --chown=user:user . /code # Add local bin to PATH ENV PATH="/home/user/.local/bin:${PATH}" ENV discovery.type=single-node # Create startup script that runs BOTH RUN echo '#!/bin/bash\n\ set -e\n\ echo "Starting Elasticsearch..."\n\ /usr/share/elasticsearch/bin/elasticsearch > /tmp/es.log 2>&1 &\n\ echo "Waiting for Elasticsearch to start..."\n\ until curl -s http://localhost:9200 >/dev/null 2>&1; do sleep 2; done\n\ echo "Elasticsearch is ready."\n\ echo "Starting FastAPI app..."\n\ exec uvicorn main:app --host 0.0.0.0 --port 7860\n' > /code/start.sh \ && chmod +x /code/start.sh # Expose both ports EXPOSE 7860 9200 # Run both via startup script CMD ["/bin/bash", "/code/start.sh"]