diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7552852..7f5c36d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -49,6 +49,10 @@ jobs: type=semver,pattern={{major}}.{{minor}} type=sha + - name: Get version from Git + id: version + run: echo "version=$(git describe --tags --always --dirty)" >> $GITHUB_OUTPUT + - name: Build and push Docker image uses: docker/build-push-action@v5 with: @@ -58,12 +62,15 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + SETUPTOOLS_SCM_PRETEND_VERSION=${{ steps.version.outputs.version }} cache-from: type=gha cache-to: type=gha,mode=max - name: Test Docker image if: github.event_name == 'pull_request' run: | - docker build -t meshcore-hub-test -f Dockerfile . + VERSION=$(git describe --tags --always --dirty) + docker build -t meshcore-hub-test --build-arg SETUPTOOLS_SCM_PRETEND_VERSION=$VERSION -f Dockerfile . docker run --rm meshcore-hub-test --version docker run --rm meshcore-hub-test --help diff --git a/Dockerfile b/Dockerfile index af7fca9..3d4766e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ RUN python -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" +# Build argument for version (set via CI or manually) +ARG SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0+docker + # Copy project files WORKDIR /app COPY pyproject.toml README.md ./ @@ -28,9 +31,9 @@ COPY src/ ./src/ COPY alembic/ ./alembic/ COPY alembic.ini ./ -# Install the package +# Install the package with version from build arg RUN pip install --upgrade pip && \ - pip install . + SETUPTOOLS_SCM_PRETEND_VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION} pip install . # ============================================================================= # Stage 2: Runtime - Final production image diff --git a/pyproject.toml b/pyproject.toml index d6f9dfb..79b7853 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,7 @@ Issues = "https://github.com/ipnet-mesh/meshcore-hub/issues" [tool.setuptools_scm] version_file = "src/meshcore_hub/_version.py" +fallback_version = "0.0.0+unknown" [tool.setuptools.packages.find] where = ["src"]