From 8f7e5f639b6d6457213bc2507ec7668982b65689 Mon Sep 17 00:00:00 2001 From: mohiit1502 Date: Sat, 3 Jan 2026 14:21:04 +0530 Subject: [PATCH] feat: Add base image to avoid 489MB TensorFlow downloads - Add Dockerfile.base with pre-installed TensorFlow/FAISS dependencies - Update Dockerfile.api and Dockerfile.streamlit to use base image - Base image only needs rebuild when requirements.txt changes --- Dockerfile.api | 32 ++------------------------------ Dockerfile.base | 26 ++++++++++++++++++++++++++ Dockerfile.streamlit | 32 ++------------------------------ Jenkinsfile | 4 ++++ 4 files changed, 34 insertions(+), 60 deletions(-) create mode 100644 Dockerfile.base diff --git a/Dockerfile.api b/Dockerfile.api index b18fbd1..8fa3de9 100644 --- a/Dockerfile.api +++ b/Dockerfile.api @@ -1,36 +1,10 @@ # Reverse Image Search API -# Multi-stage build for optimized image size +# Uses pre-built base image with TensorFlow to avoid repeated downloads -FROM python:3.11-slim as builder +FROM harbor.armco.dev/library/visualsearch-base:latest 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 . @@ -45,8 +19,6 @@ COPY filenames.pkl . RUN mkdir -p uploads logs # Environment variables -ENV PYTHONUNBUFFERED=1 -ENV PYTHONDONTWRITEBYTECODE=1 ENV API_PORT=8081 ENV DEBUG=false diff --git a/Dockerfile.base b/Dockerfile.base new file mode 100644 index 0000000..6f49c8d --- /dev/null +++ b/Dockerfile.base @@ -0,0 +1,26 @@ +# Base image with TensorFlow and heavy dependencies pre-installed +# Build once, reuse for API and Streamlit builds +# Tag: harbor.armco.dev/library/visualsearch-base:latest + +FROM python:3.11-slim + +WORKDIR /app + +# Install build dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + libgomp1 \ + && rm -rf /var/lib/apt/lists/* + +# Copy and install requirements +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# FAISS uses OpenMP for parallel search +ENV OMP_NUM_THREADS=8 +ENV PATH=/root/.local/bin:$PATH +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 + +# Clean up build dependencies to reduce image size +RUN apt-get purge -y build-essential && apt-get autoremove -y diff --git a/Dockerfile.streamlit b/Dockerfile.streamlit index f335955..b2466ec 100644 --- a/Dockerfile.streamlit +++ b/Dockerfile.streamlit @@ -1,36 +1,10 @@ # Reverse Image Search Streamlit UI -# Multi-stage build for optimized image size +# Uses pre-built base image with TensorFlow to avoid repeated downloads -FROM python:3.11-slim as builder +FROM harbor.armco.dev/library/visualsearch-base:latest 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 . @@ -44,8 +18,6 @@ COPY filenames.pkl . 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 diff --git a/Jenkinsfile b/Jenkinsfile index c9d773d..c180d3e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,9 @@ @Library('jenkins-shared@main') _ +// NOTE: Build base image first when requirements.txt changes: +// [imageName: 'visualsearch-base', dockerfile: 'Dockerfile.base'] +// Then rebuild API and Streamlit images + kanikoPipeline( repoName: 'visual-search-engine', branch: env.BRANCH_NAME ?: 'main',