Update Dockerfile
Browse files- Dockerfile +45 -9
Dockerfile
CHANGED
|
@@ -1,24 +1,60 @@
|
|
| 1 |
FROM python:3.12
|
| 2 |
|
|
|
|
| 3 |
RUN useradd -m -u 1000 user
|
| 4 |
|
| 5 |
WORKDIR /code
|
| 6 |
|
|
|
|
| 7 |
COPY ./requirements.txt /code/requirements.txt
|
| 8 |
|
|
|
|
| 9 |
USER root
|
| 10 |
-
RUN
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
USER user
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
# RUN pip install pypandoc
|
| 18 |
-
# RUN pip install pypandoc-binary
|
| 19 |
|
|
|
|
| 20 |
COPY --chown=user:user . /code
|
| 21 |
|
|
|
|
| 22 |
ENV PATH="/home/user/.local/bin:${PATH}"
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
FROM python:3.12
|
| 2 |
|
| 3 |
+
# Create non-root user
|
| 4 |
RUN useradd -m -u 1000 user
|
| 5 |
|
| 6 |
WORKDIR /code
|
| 7 |
|
| 8 |
+
# Copy requirements first for caching
|
| 9 |
COPY ./requirements.txt /code/requirements.txt
|
| 10 |
|
| 11 |
+
# Install system dependencies
|
| 12 |
USER root
|
| 13 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 14 |
+
ffmpeg \
|
| 15 |
+
curl \
|
| 16 |
+
wget \
|
| 17 |
+
unzip \
|
| 18 |
+
procps \
|
| 19 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 20 |
+
|
| 21 |
+
# Download and install Elasticsearch
|
| 22 |
+
RUN wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-9.0.1-linux-x86_64.tar.gz && \
|
| 23 |
+
tar -xzf elasticsearch-9.0.1-linux-x86_64.tar.gz && \
|
| 24 |
+
mv elasticsearch-9.0.1 /usr/share/elasticsearch && \
|
| 25 |
+
rm elasticsearch-9.0.1-linux-x86_64.tar.gz
|
| 26 |
+
|
| 27 |
+
# Copy your ES config
|
| 28 |
+
COPY elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml
|
| 29 |
+
|
| 30 |
+
# Permissions
|
| 31 |
+
RUN chown -R user:user /usr/share/elasticsearch /code
|
| 32 |
USER user
|
| 33 |
|
| 34 |
+
# Install Python dependencies
|
| 35 |
+
RUN pip install --no-cache-dir -r /code/requirements.txt
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# Copy the app
|
| 38 |
COPY --chown=user:user . /code
|
| 39 |
|
| 40 |
+
# Add local bin to PATH
|
| 41 |
ENV PATH="/home/user/.local/bin:${PATH}"
|
| 42 |
+
ENV discovery.type=single-node
|
| 43 |
+
|
| 44 |
+
# Create startup script that runs BOTH
|
| 45 |
+
RUN echo '#!/bin/bash\n\
|
| 46 |
+
set -e\n\
|
| 47 |
+
echo "Starting Elasticsearch..."\n\
|
| 48 |
+
/usr/share/elasticsearch/bin/elasticsearch > /tmp/es.log 2>&1 &\n\
|
| 49 |
+
echo "Waiting for Elasticsearch to start..."\n\
|
| 50 |
+
until curl -s http://localhost:9200 >/dev/null 2>&1; do sleep 2; done\n\
|
| 51 |
+
echo "Elasticsearch is ready."\n\
|
| 52 |
+
echo "Starting FastAPI app..."\n\
|
| 53 |
+
exec uvicorn main:app --host 0.0.0.0 --port 7860\n' > /code/start.sh \
|
| 54 |
+
&& chmod +x /code/start.sh
|
| 55 |
+
|
| 56 |
+
# Expose both ports
|
| 57 |
+
EXPOSE 7860 9200
|
| 58 |
+
|
| 59 |
+
# Run both via startup script
|
| 60 |
+
CMD ["/bin/bash", "/code/start.sh"]
|