feat: Add base image to avoid 489MB TensorFlow downloads
All checks were successful
armco-org/visual-search-engine/pipeline/head This commit was not built
All checks were successful
armco-org/visual-search-engine/pipeline/head This commit was not built
- 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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
26
Dockerfile.base
Normal file
26
Dockerfile.base
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
4
Jenkinsfile
vendored
4
Jenkinsfile
vendored
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user