diff --git a/Dockerfile.api b/Dockerfile.api new file mode 100644 index 0000000..b18fbd1 --- /dev/null +++ b/Dockerfile.api @@ -0,0 +1,61 @@ +# Reverse Image Search API +# Multi-stage build for optimized image size + +FROM python:3.11-slim as builder + +WORKDIR /app + +# Install build dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements and install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir --user -r requirements.txt + +# Production stage +FROM python:3.11-slim + +WORKDIR /app + +# Install runtime dependencies (libgomp for OpenMP parallelism) +RUN apt-get update && apt-get install -y --no-install-recommends \ + libgomp1 \ + && rm -rf /var/lib/apt/lists/* + +# FAISS uses OpenMP for parallel search - set threads for Xeon +ENV OMP_NUM_THREADS=8 + +# Copy installed packages from builder +COPY --from=builder /root/.local /root/.local +ENV PATH=/root/.local/bin:$PATH + +# Copy application code +COPY api/ ./api/ +COPY config.py . +COPY reverse_icon_search.py . +COPY run_api_server.py . + +# Copy pre-built index and filenames for inference +COPY index.faiss . +COPY filenames.pkl . + +# Create necessary directories +RUN mkdir -p uploads logs + +# Environment variables +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV API_PORT=8081 +ENV DEBUG=false + +# Expose port +EXPOSE 8081 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8081/api/health')" || exit 1 + +# Run the application +CMD ["python", "run_api_server.py"] diff --git a/Dockerfile.streamlit b/Dockerfile.streamlit new file mode 100644 index 0000000..f335955 --- /dev/null +++ b/Dockerfile.streamlit @@ -0,0 +1,60 @@ +# Reverse Image Search Streamlit UI +# Multi-stage build for optimized image size + +FROM python:3.11-slim as builder + +WORKDIR /app + +# Install build dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements and install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir --user -r requirements.txt + +# Production stage +FROM python:3.11-slim + +WORKDIR /app + +# Install runtime dependencies (libgomp for OpenMP parallelism) +RUN apt-get update && apt-get install -y --no-install-recommends \ + libgomp1 \ + && rm -rf /var/lib/apt/lists/* + +# FAISS uses OpenMP for parallel search - set threads for Xeon +ENV OMP_NUM_THREADS=8 + +# Copy installed packages from builder +COPY --from=builder /root/.local /root/.local +ENV PATH=/root/.local/bin:$PATH + +# Copy application code +COPY config.py . +COPY reverse_icon_search.py . +COPY main_streamlit.py . + +# Copy pre-built index and filenames for inference +COPY index.faiss . +COPY filenames.pkl . + +# Create necessary directories +RUN mkdir -p uploads logs + +# Environment variables +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV STREAMLIT_SERVER_PORT=3000 +ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0 + +# Expose port +EXPOSE 3000 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \ + CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:3000/_stcore/health')" || exit 1 + +# Run Streamlit +CMD ["streamlit", "run", "main_streamlit.py", "--server.port=3000", "--server.address=0.0.0.0"] diff --git a/Jenkinsfile b/Jenkinsfile index c50cd23..c9d773d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,7 @@ kanikoPipeline( repoName: 'visual-search-engine', branch: env.BRANCH_NAME ?: 'main', builds: [ - [imageName: 'visual-search-engine', dockerfile: 'Dockerfile'] + [imageName: 'visualsearch', dockerfile: 'Dockerfile.api'], + [imageName: 'visualsearch-stl', dockerfile: 'Dockerfile.streamlit'] ] )