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
28 changes: 27 additions & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for proper versioning
fetch-tags: true # Explicitly fetch all tags
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -59,6 +60,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for proper versioning
fetch-tags: true # Explicitly fetch all tags
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand All @@ -84,7 +86,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 0 # Fetch all history for proper versioning
fetch-tags: true # Explicitly fetch all tags

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down Expand Up @@ -153,6 +156,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for proper versioning
fetch-tags: true # Explicitly fetch all tags

# PyPI deployment (only for Python 3.x representative)
- name: Set up Python
Expand Down Expand Up @@ -213,6 +217,27 @@ jobs:
flavor: |
latest=${{ matrix.python-version == '3.11' }}

- name: Get Version for Docker Build
id: get_version
run: |
# Ensure we have tags
git fetch --tags --force

# For tagged builds, use the exact tag
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
# Keep the v prefix for git tags
VERSION="$TAG"
echo "Using tag version: $VERSION"
else
# Use git version with v prefix
VERSION=$(git describe --tags --always 2>/dev/null || echo "v0.1.0")
echo "Using git version: $VERSION"
fi

# Output for GitHub Actions
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
Expand All @@ -222,5 +247,6 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
VERSION=${{ steps.get_version.outputs.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-slim

# Accept version as build arg
ARG VERSION="0.1.0"

WORKDIR /app

# Install git to properly detect version during build
# Install git for versioning
RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*

# Copy requirements and install dependencies first
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy everything needed for versioning and installation
# Copy source code for installation
COPY . .

# Install the package with proper versioning support
# Use setuptools_scm with the version passed from the build
ENV SETUPTOOLS_SCM_PRETEND_VERSION=$VERSION

# Install the package
RUN pip install --no-cache-dir .

# Create a wrapper script to allow more flexibility
Expand Down
Loading