Spaces:
Sleeping

TFA / Dockerfile
VAH6002's picture
Upload 61 files
1af9fb8 verified
Raw History Blame Contribute Delete
2.41 kB
# TFA (Test Failure Analysis) - Docker Image for Hugging Face Spaces
# Multi-stage build for optimized production image
# Build stage
FROM python:3.11-slim as builder
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies for building
RUN apt-get update && apt-get install -y \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy requirements and install Python dependencies
COPY requirements_hf.txt /tmp/requirements.txt
RUN pip install --upgrade pip && \
pip install -r /tmp/requirements.txt
# Production stage
FROM python:3.11-slim
# Set environment variables for production
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PATH="/opt/venv/bin:$PATH" \
TFA_ENVIRONMENT=production \
TFA_USE_MOCK_DATA=true \
STREAMLIT_SERVER_PORT=7860 \
STREAMLIT_SERVER_ADDRESS=0.0.0.0 \
GOOGLE_API_KEY=demo-key-for-huggingface-spaces
# Install runtime system dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy virtual environment from builder stage
COPY --from=builder /opt/venv /opt/venv
# Create non-root user for security
RUN useradd --create-home --shell /bin/bash tfa
USER tfa
WORKDIR /home/tfa
# Copy application code
COPY --chown=tfa:tfa tfa_agents/ ./tfa_agents/
COPY --chown=tfa:tfa tfa_ui/ ./tfa_ui/
COPY --chown=tfa:tfa docs/ ./docs/
COPY --chown=tfa:tfa .streamlit/ ./.streamlit/
# Copy configuration and documentation
COPY --chown=tfa:tfa app.py ./
COPY --chown=tfa:tfa simple_test.py ./
COPY --chown=tfa:tfa test_*.py ./
COPY --chown=tfa:tfa USAGE_GUIDE.md ./
COPY --chown=tfa:tfa CONFIGURATION.md ./
# Create .env file with default values
RUN echo "TFA_ENVIRONMENT=production" > .env && \
echo "TFA_USE_MOCK_DATA=true" >> .env && \
echo "STREAMLIT_SERVER_PORT=7860" >> .env && \
echo "STREAMLIT_SERVER_ADDRESS=0.0.0.0" >> .env
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:7860/_stcore/health || exit 1
# Expose port
EXPOSE 7860
# Run the application
CMD ["python", "app.py"]