File size: 1,655 Bytes
0c2f35b
 
a305b03
0c2f35b
 
 
 
a305b03
0c2f35b
 
a305b03
0c2f35b
a305b03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c2f35b
 
a305b03
 
0c2f35b
a305b03
0c2f35b
 
a305b03
0c2f35b
a305b03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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"]