From a4007d585b07b0d032eb3edf525d028a68ca72ab Mon Sep 17 00:00:00 2001 From: Luke Tainton Date: Sun, 21 Apr 2024 16:52:55 +0100 Subject: [PATCH] Auto-inject version into image --- .github/workflows/release.yml | 6 +++++- Dockerfile | 3 +++ app/utils/config.py | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 13ea1f3..c1b0166 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,7 +33,11 @@ jobs: - name: Login to GitHub Container Registry run: echo ${{ secrets.GHCR_ACCESS_TOKEN }} | docker login ghcr.io -u luketainton --password-stdin - name: Build image for GitHub Package Registry - run: docker build . --file Dockerfile --tag ghcr.io/luketainton/roboluke-tasks:${{ needs.release.outputs.new_tag }} --tag ghcr.io/luketainton/roboluke-tasks:latest + run: | + docker build . --file Dockerfile \ + --build-arg "version=${{ needs.release.outputs.new_tag }}" \ + --tag ghcr.io/luketainton/roboluke-tasks:${{ needs.release.outputs.new_tag }} \ + --tag ghcr.io/luketainton/roboluke-tasks:latest - name: Push image to GitHub Package Registry run: | docker push ghcr.io/luketainton/roboluke-tasks:latest diff --git a/Dockerfile b/Dockerfile index bcb77e5..ec79734 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,4 +15,7 @@ RUN pip install --no-cache-dir -r requirements.txt ENTRYPOINT ["python3", "-B", "-m", "app.main"] +ARG version="dev" +ENV APP_VERSION=$version + COPY app /run/app diff --git a/app/utils/config.py b/app/utils/config.py index f12eb7a..b9e6231 100644 --- a/app/utils/config.py +++ b/app/utils/config.py @@ -8,6 +8,7 @@ class Config: def __init__(self) -> None: """Configuration module.""" self.__environment: str = os.environ.get("APP_LIFECYCLE", "DEV").upper() + self.__version: str = os.environ["APP_VERSION"] self.__bot_name: str = os.environ["BOT_NAME"] self.__webex_token: str = os.environ["WEBEX_API_KEY"] self.__admin_first_name: str = os.environ["ADMIN_FIRST_NAME"] @@ -24,6 +25,11 @@ class Config: """Returns the current app lifecycle.""" return self.__environment + @property + def version(self) -> str: + """Returns the current app version.""" + return self.__version + @property def sentry_enabled(self) -> bool: """Returns True if Sentry SDK is enabled, else False."""