Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# -----------------------------------------------
# 🌟 GitHub Actions: Continuous Delivery (CD)
# Builds and publishes a Docker image of your app
# -----------------------------------------------

name: Build and publish Docker image

# -----------------------------------------------
# 🧠 Trigger conditions
# Run this workflow when:
# 1. You push to the main branch
# 2. You create a version tag (e.g., v1.0.0)
# -----------------------------------------------
on:
push:
branches: [ main ]
tags: [ 'v*.*.*' ]

# -----------------------------------------------
# 🔑 Permissions for GitHub Container Registry
# -----------------------------------------------
permissions:
contents: read
packages: write

# -----------------------------------------------
# 🧱 Define the job
# -----------------------------------------------
jobs:
build-and-push:
runs-on: ubuntu-latest # use latest Ubuntu VM for building

steps:
# -------------------------------------------
# Step 1: Checkout your code
# -------------------------------------------
- name: Checkout repository
uses: actions/checkout@v4

# -------------------------------------------
# Step 2: Extract metadata for tagging the Docker image
# Example: main branch → "latest", v1.0.0 tag → "v1.0.0"
# -------------------------------------------
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha

# -------------------------------------------
# Step 3: Set up QEMU (for cross-platform builds)
# -------------------------------------------
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# -------------------------------------------
# Step 4: Set up Docker Buildx (for building images)
# -------------------------------------------
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# -------------------------------------------
# Step 5: Log in to GitHub Container Registry (GHCR)
# GitHub automatically provides a token for this.
# -------------------------------------------
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# -------------------------------------------
# Step 6: Build and push the Docker image
# "push: true" publishes it to GHCR
# -------------------------------------------
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: . # project root
push: true # upload to registry
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -----------------------------
# 🐳 Base image: a lightweight Python environment
# -----------------------------
FROM python:3.11-slim

# Prevent Python from writing .pyc files and buffering output
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

# -----------------------------
# 🏠 Set the working directory inside the container
# -----------------------------
WORKDIR /app

# -----------------------------
# ⚙️ Install system dependencies (optional but useful for numpy, pillow, etc.)
# -----------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# -----------------------------
# 📦 Install Python dependencies
# -----------------------------
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# -----------------------------
# 📂 Copy project files into container
# -----------------------------
# Copy your app code and support folders
COPY app ./app
COPY src ./src
COPY assets ./assets
COPY .streamlit ./.streamlit
COPY README.md .

# -----------------------------
# 🌐 Expose Streamlit’s default port
# -----------------------------
EXPOSE 8501

# -----------------------------
# ⚙️ Environment settings for Streamlit
# -----------------------------
ENV STREAMLIT_SERVER_HEADLESS=true \
STREAMLIT_SERVER_PORT=8501 \
STREAMLIT_BROWSER_GATHERUSAGESTATS=false

# -----------------------------
# 🚀 Run your Streamlit app
# -----------------------------
CMD ["streamlit", "run", "app/main.py"]