Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Set codegate version from build argument in container #615

Merged
merged 1 commit into from
Jan 16, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/image-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
19 changes: 13 additions & 6 deletions src/codegate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
Loading