"It works on my Jupyter notebook" is not an acceptable deployment strategy. In this class, we master Production Containerization with multi-stage Dockerfiles and automated GitHub Actions CI/CD pipelines.
# Stage 1: Build stage with compiler tools
FROM python:3.12-slim AS builder
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential gcc && \
rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt
# Stage 2: Final Minimal & Secure Production Runtime Image
FROM python:3.12-slim AS runner
WORKDIR /app
# Create unprivileged non-root security user
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
# Copy installed Python wheels from builder stage
COPY --from=builder /root/.local /home/appuser/.local
COPY . /app
# Ensure correct permissions
RUN chown -R appuser:appgroup /app
USER appuser
ENV PATH=/home/appuser/.local/bin:$PATH
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]
name: Data Science Production CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test-and-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest ruff
- name: Code Quality & Lint Check
run: ruff check .
- name: Execute Model Unit Tests
run: pytest tests/
build-container:
needs: test-and-lint
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Docker Container
run: docker build -t veewom-ds-api:latest .
In production cloud systems (AWS ECS or Google Cloud Run), container updates are deployed via blue/green rolling switches. The cloud orchestrator provisions the new container, verifies health checks on /healthz, routes traffic, and gracefully drains old containers with zero customer downtime.
Broaden your statistical analysis, Python data wrangling, and production engineering expertise:
Containerize asynchronous Python prediction servers for deployment.
Orchestrate multi-container setups using Docker Compose.
Deploy production data pipelines to cloud instances with CI/CD automation.
Deploy your final capstone model in a containerized production environment.