diff --git a/.github/workflows/image-publish.yml b/.github/workflows/image-publish.yml index 2af09a74..e5c97c20 100644 --- a/.github/workflows/image-publish.yml +++ b/.github/workflows/image-publish.yml @@ -87,6 +87,7 @@ jobs: cache-to: type=gha,mode=max build-args: | LATEST_RELEASE=${{ env.LATEST_RELEASE }} + CODEGATE_VERSION=${{ steps.version-string.outputs.tag }} - name: Capture Image Digest id: image-digest run: | diff --git a/Dockerfile b/Dockerfile index 761cbdfa..68d8cbea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ # Builder stage: Install dependencies and build the application FROM python:3.12-slim AS builder +ARG CODEGATE_VERSION=dev + # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ @@ -21,6 +23,9 @@ RUN poetry config virtualenvs.create false && \ # Copy the rest of the application COPY . /app +# Overwrite the _VERSION variable in the code +RUN sed -i "s/_VERSION =.*/_VERSION = \"${CODEGATE_VERSION}\"/g" /app/src/codegate/__init__.py + # Build the webapp FROM node:23-slim AS webbuilder diff --git a/Makefile b/Makefile index 6db025f5..3c3074d6 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ image-build: DOCKER_BUILDKIT=1 $(CONTAINER_BUILD) \ -f Dockerfile \ --build-arg LATEST_RELEASE=$(curl -s "https://api.github.com/repos/stacklok/codegate-ui/releases/latest" | grep '"zipball_url":' | cut -d '"' -f 4) \ + --build-arg CODEGATE_VERSION="$(shell git describe --tags --abbrev=0)-$(shell git rev-parse --short HEAD)-dev" \ -t codegate \ . \ -t ghcr.io/stacklok/codegate:$(VER) \ diff --git a/src/codegate/__init__.py b/src/codegate/__init__.py index 106a1d9d..24f8ce3c 100644 --- a/src/codegate/__init__.py +++ b/src/codegate/__init__.py @@ -7,12 +7,19 @@ from codegate.config import Config from codegate.exceptions import ConfigurationError -try: - __version__ = metadata.version("codegate") - __description__ = metadata.metadata("codegate")["Summary"] -except metadata.PackageNotFoundError: # pragma: no cover - __version__ = "unknown" - __description__ = "codegate" +_VERSION = "dev" +_DESC = "CodeGate - A Generative AI security gateway." + +def __get_version_and_description() -> tuple[str, str]: + try: + version = metadata.version("codegate") + description = metadata.metadata("codegate")["Summary"] + except metadata.PackageNotFoundError: + version = _VERSION + description = _DESC + return version, description + +__version__, __description__ = __get_version_and_description() __all__ = ["Config", "ConfigurationError", "LogFormat", "LogLevel", "setup_logging"]