|
| 1 | +# Start from a minimal Red Hat UBI9 base image |
| 2 | +FROM registry.access.redhat.com/ubi9/ubi-minimal as base |
| 3 | + |
| 4 | +# Update and install necessary dependencies |
| 5 | +RUN microdnf update -y && \ |
| 6 | + microdnf install -y --nodocs \ |
| 7 | + gcc g++ git python3.11-devel python3.11-pip java-11-openjdk-headless java-11-openjdk-devel && \ |
| 8 | + ln -fs /usr/bin/python3.11 /usr/bin/python && \ |
| 9 | + ln -fs /usr/bin/pip3.11 /usr/bin/pip && \ |
| 10 | + pip install --upgrade --no-cache-dir pip wheel && \ |
| 11 | + microdnf clean all |
| 12 | + |
| 13 | +# Use a builder stage to install Python dependencies |
| 14 | +FROM base as builder |
| 15 | + |
| 16 | +# Create a virtual environment using Python 3.11 |
| 17 | +# RUN python -m venv /app/venv |
| 18 | + |
| 19 | +# # Activate the virtual environment and install dependencies |
| 20 | +# ENV PATH="/app/venv/bin:$PATH" |
| 21 | + |
| 22 | +# Copy the requirements and install them |
| 23 | +COPY ./common/requirements.txt . |
| 24 | +RUN pip install --no-cache-dir -r requirements.txt |
| 25 | + |
| 26 | +COPY ./guardrails_ai_wrapper/requirements.txt . |
| 27 | +RUN pip install --no-cache-dir -r requirements.txt |
| 28 | + |
| 29 | +# Copy the application code to the builder |
| 30 | +WORKDIR /app |
| 31 | +COPY ./common /common |
| 32 | +COPY ./guardrails_ai_wrapper/app.py /app |
| 33 | +COPY ./guardrails_ai_wrapper/detector.py /app |
| 34 | +COPY ./guardrails_ai_wrapper/scheme.py /app |
| 35 | +COPY ./guardrails_ai_wrapper/experiments.py /app |
| 36 | + |
| 37 | +# Set environment variables for Guardrails configuration |
| 38 | +ARG GUARDRAILS_METRICS |
| 39 | +ARG GUARDRAILS_REMOTE_INFERENCING |
| 40 | +ARG GUARDRAILS_API_KEY |
| 41 | + |
| 42 | +# Export the environment variables to be available during build |
| 43 | +ENV GUARDRAILS_METRICS=${GUARDRAILS_METRICS} |
| 44 | +ENV GUARDRAILS_REMOTE_INFERENCING=${GUARDRAILS_REMOTE_INFERENCING} |
| 45 | +ENV GUARDRAILS_API_KEY=${GUARDRAILS_API_KEY} |
| 46 | + |
| 47 | +# Copy the scripts to the container |
| 48 | +COPY ./guardrails_ai_wrapper/configure_guardrails.sh /app |
| 49 | +COPY ./guardrails_ai_wrapper/install_guardrails.sh /app |
| 50 | + |
| 51 | +# Run the setup and installation scripts during the build process |
| 52 | +RUN chmod +x /app/configure_guardrails.sh /app/install_guardrails.sh && \ |
| 53 | + /app/configure_guardrails.sh && \ |
| 54 | + /app/install_guardrails.sh |
| 55 | + |
| 56 | +# Expose the necessary port |
| 57 | +EXPOSE 8000 |
| 58 | + |
| 59 | +# Command to run the application |
| 60 | +CMD ["uvicorn", "app:app", "--workers", "4", "--host", "0.0.0.0", "--port", "8000", "--log-config", "/common/log_conf.yaml"] |
0 commit comments