Skip to content

Commit e029446

Browse files
Merge pull request #27 from pescheckit/hotfix_fixed-issue-with-docker-versions
Fixed issue with docker versions
2 parents e704d80 + 6ed79e9 commit e029446

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

.github/workflows/ci-cd.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- uses: actions/checkout@v4
2727
with:
2828
fetch-depth: 0 # Fetch all history for proper versioning
29+
fetch-tags: true # Explicitly fetch all tags
2930
- name: Set up Python ${{ matrix.python-version }}
3031
uses: actions/setup-python@v5
3132
with:
@@ -59,6 +60,7 @@ jobs:
5960
- uses: actions/checkout@v4
6061
with:
6162
fetch-depth: 0 # Fetch all history for proper versioning
63+
fetch-tags: true # Explicitly fetch all tags
6264
- name: Set up Python ${{ matrix.python-version }}
6365
uses: actions/setup-python@v5
6466
with:
@@ -84,7 +86,8 @@ jobs:
8486
- name: Checkout
8587
uses: actions/checkout@v4
8688
with:
87-
fetch-depth: 0
89+
fetch-depth: 0 # Fetch all history for proper versioning
90+
fetch-tags: true # Explicitly fetch all tags
8891

8992
- name: Set up Docker Buildx
9093
uses: docker/setup-buildx-action@v3
@@ -153,6 +156,7 @@ jobs:
153156
- uses: actions/checkout@v4
154157
with:
155158
fetch-depth: 0 # Fetch all history for proper versioning
159+
fetch-tags: true # Explicitly fetch all tags
156160

157161
# PyPI deployment (only for Python 3.x representative)
158162
- name: Set up Python
@@ -213,6 +217,27 @@ jobs:
213217
flavor: |
214218
latest=${{ matrix.python-version == '3.11' }}
215219
220+
- name: Get Version for Docker Build
221+
id: get_version
222+
run: |
223+
# Ensure we have tags
224+
git fetch --tags --force
225+
226+
# For tagged builds, use the exact tag
227+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
228+
TAG=${GITHUB_REF#refs/tags/}
229+
# Keep the v prefix for git tags
230+
VERSION="$TAG"
231+
echo "Using tag version: $VERSION"
232+
else
233+
# Use git version with v prefix
234+
VERSION=$(git describe --tags --always 2>/dev/null || echo "v0.1.0")
235+
echo "Using git version: $VERSION"
236+
fi
237+
238+
# Output for GitHub Actions
239+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
240+
216241
- name: Build and Push Docker Image
217242
uses: docker/build-push-action@v5
218243
with:
@@ -222,5 +247,6 @@ jobs:
222247
labels: ${{ steps.meta.outputs.labels }}
223248
build-args: |
224249
PYTHON_VERSION=${{ matrix.python-version }}
250+
VERSION=${{ steps.get_version.outputs.VERSION }}
225251
cache-from: type=gha
226252
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
ARG PYTHON_VERSION=3.11
22
FROM python:${PYTHON_VERSION}-slim
33

4+
# Accept version as build arg
5+
ARG VERSION="0.1.0"
6+
47
WORKDIR /app
58

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

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

13-
# Copy everything needed for versioning and installation
16+
# Copy source code for installation
1417
COPY . .
1518

16-
# Install the package with proper versioning support
19+
# Use setuptools_scm with the version passed from the build
20+
ENV SETUPTOOLS_SCM_PRETEND_VERSION=$VERSION
21+
22+
# Install the package
1723
RUN pip install --no-cache-dir .
1824

1925
# Create a wrapper script to allow more flexibility

0 commit comments

Comments
 (0)