2024-05-01 12:19:16 +00:00
|
|
|
# Builder Stage
|
|
|
|
FROM ubuntu:mantic as builder
|
|
|
|
|
|
|
|
# Install necessary packages
|
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y --no-install-recommends gcc curl wget unzip libc6-dev python3.11 python3-pip python3-venv && \
|
|
|
|
ln -s /usr/bin/python3.11 /usr/bin/python && \
|
|
|
|
ln -sf /usr/bin/pip3 /usr/bin/pip
|
|
|
|
|
|
|
|
# Download and unzip the model
|
|
|
|
RUN wget https://d3dg1063dc54p9.cloudfront.net/models/embeddings/mpnet-base-v2.zip && \
|
|
|
|
unzip mpnet-base-v2.zip -d model && \
|
|
|
|
rm mpnet-base-v2.zip
|
|
|
|
|
|
|
|
# Install Rust
|
|
|
|
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
|
|
|
|
|
|
|
|
# Clean up to reduce container size
|
|
|
|
RUN apt-get remove --purge -y wget unzip && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
# Copy requirements.txt
|
2023-03-06 18:34:48 +00:00
|
|
|
COPY requirements.txt .
|
2024-02-23 21:19:04 +00:00
|
|
|
|
2024-05-01 12:19:16 +00:00
|
|
|
# Setup Python virtual environment
|
|
|
|
RUN python3 -m venv /venv
|
|
|
|
ENV PATH="/venv/bin:$PATH"
|
2024-02-23 21:15:26 +00:00
|
|
|
|
2024-05-01 12:19:16 +00:00
|
|
|
# Install Python packages
|
|
|
|
RUN pip install --no-cache-dir --upgrade pip && \
|
|
|
|
pip install --no-cache-dir tiktoken && \
|
|
|
|
pip install --no-cache-dir -r requirements.txt
|
2023-03-06 18:34:48 +00:00
|
|
|
|
2024-05-01 12:19:16 +00:00
|
|
|
# Final Stage
|
|
|
|
FROM ubuntu:mantic as final
|
2023-06-15 16:40:58 +00:00
|
|
|
|
2024-05-01 12:19:16 +00:00
|
|
|
# Install Python
|
2024-05-02 13:43:09 +00:00
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends python3.11 && \
|
2024-05-01 12:19:16 +00:00
|
|
|
ln -s /usr/bin/python3.11 /usr/bin/python && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
2023-06-15 16:40:58 +00:00
|
|
|
|
2024-05-01 12:19:16 +00:00
|
|
|
# Set working directory
|
2023-02-03 12:45:29 +00:00
|
|
|
WORKDIR /app
|
2024-05-01 12:19:16 +00:00
|
|
|
|
|
|
|
# Create a non-root user: `appuser` (Feel free to choose a name)
|
|
|
|
RUN groupadd -r appuser && \
|
|
|
|
useradd -r -g appuser -d /app -s /sbin/nologin -c "Docker image user" appuser
|
|
|
|
|
|
|
|
# Copy the virtual environment and model from the builder stage
|
|
|
|
COPY --from=builder /venv /venv
|
2024-01-09 11:39:32 +00:00
|
|
|
COPY --from=builder /model /app/model
|
|
|
|
|
2024-05-01 12:19:16 +00:00
|
|
|
# Copy your application code
|
2023-08-13 19:00:52 +00:00
|
|
|
COPY . /app/application
|
2023-03-14 14:29:36 +00:00
|
|
|
|
2024-05-01 12:19:16 +00:00
|
|
|
# Change the ownership of the /app directory to the appuser
|
|
|
|
RUN chown -R appuser:appuser /app
|
|
|
|
|
|
|
|
# Set environment variables
|
|
|
|
ENV FLASK_APP=app.py \
|
|
|
|
FLASK_DEBUG=true \
|
|
|
|
PATH="/venv/bin:$PATH"
|
|
|
|
|
|
|
|
# Expose the port the app runs on
|
2023-06-23 11:56:14 +00:00
|
|
|
EXPOSE 7091
|
2023-02-03 12:45:29 +00:00
|
|
|
|
2024-05-01 12:19:16 +00:00
|
|
|
# Switch to non-root user
|
|
|
|
USER appuser
|
|
|
|
|
|
|
|
# Start Gunicorn
|
|
|
|
CMD ["gunicorn", "-w", "2", "--timeout", "120", "--bind", "0.0.0.0:7091", "application.wsgi:app"]
|