From 73f88f50a28f6fe0e82f8c8ed1ef104964fb06cd Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 21 Sep 2025 11:19:37 +0530 Subject: [PATCH 1/2] Create Dockerfile --- Dockerfile | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..330a4ff --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +# Multi-stage Dockerfile for Tech Stack Advisor ML App + +# Stage 1: Builder stage for training the model +FROM python:3.11-slim AS builder + +WORKDIR /app + +# Install build dependencies +RUN apt-get update && apt-get install -y \ + gcc \ + python3-dev \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements and install Python dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir --user -r requirements.txt + +# Copy training script and train the model +COPY train.py . +RUN python train.py + +# Stage 2: Production runtime stage +FROM python:3.11-slim AS production + +# Create non-root user for security +RUN useradd --create-home --shell /bin/bash mluser + +WORKDIR /app + +# Copy Python packages from builder stage +COPY --from=builder /root/.local /home/mluser/.local + +# Copy application files +COPY app.py . +COPY requirements.txt . + +# Copy trained model from builder stage +COPY --from=builder /app/model.pkl . +COPY --from=builder /app/encoders.pkl . + +# Set ownership and switch to non-root user +RUN chown -R mluser:mluser /app +USER mluser + +# Make sure scripts in .local are usable +ENV PATH=/home/mluser/.local/bin:$PATH + +# Add health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD python -c "import requests; requests.get('http://localhost:7860', timeout=3)" || exit 1 + +EXPOSE 7860 + +CMD ["python", "app.py"] From 0fffecae2794bae5916f2c5be7cd839545a269ea Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 21 Sep 2025 11:28:29 +0530 Subject: [PATCH 2/2] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 330a4ff..f9554ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Multi-stage Dockerfile for Tech Stack Advisor ML App - +# # Stage 1: Builder stage for training the model FROM python:3.11-slim AS builder