Skip to content

Commit

Permalink
Merge pull request #329 from meaningfy-ws/feature/MWB-838
Browse files Browse the repository at this point in the history
Updated app version provider
  • Loading branch information
kaleanych authored Oct 17, 2024
2 parents b2e3a0c + 22ca6ef commit f9a1692
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ FRONTEND_INFRA_FOLDER := ${PROJECT_PATH}/${FRONTEND_HOME}

RML_MAPPER_PATH = ${PROJECT_PATH}/.rmlmapper/rmlmapper.jar

PYTHON := python3
APP_VERSION_SCRIPT := ${BACKEND_INFRA_FOLDER}/core/scripts/get_app_version.py

#-----------------------------------------------------------------------------
# INSTALLING
Expand Down Expand Up @@ -245,3 +247,10 @@ init-rml-mapper:
setup-env-paths:
@ perl -i -ne 'print unless /^RML_MAPPER_PATH/' ${ENV_FILE}
@ echo RML_MAPPER_PATH=${RML_MAPPER_PATH} >> ${ENV_FILE}

add-app-version:
@ perl -i -ne 'print unless /^MW_APP_VERSION/' ${ENV_FILE}
@ echo MW_APP_VERSION=$$($(PYTHON) $(APP_VERSION_SCRIPT)) >> ${ENV_FILE}

prepare-env-deploy: add-app-version
@ echo "Prepared ENV Deploy"
1 change: 1 addition & 0 deletions infra/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY ./mapping_workbench/backend ./mapping_workbench/backend
COPY ./requirements.txt ./
COPY ./Makefile ./
COPY ./.env ./
RUN make prepare-env-deploy

RUN make install-backend

Expand Down
4 changes: 4 additions & 0 deletions mapping_workbench/backend/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class AppSettings(BaseSettings):
def APP_NAME(self, config_value: str) -> str:
return config_value

@env_property(config_key='MW_APP_VERSION')
def APP_VERSION(self, config_value: str) -> str:
return config_value

@env_property(config_key='MW_APP_DEBUG_MODE')
def DEBUG_MODE(self, config_value: str) -> bool:
return config_value == '1'
Expand Down
6 changes: 3 additions & 3 deletions mapping_workbench/backend/core/entrypoints/api/routes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse
from mapping_workbench.backend.core.models.api_response import AppSettingsResponse

from mapping_workbench.backend.core.services.app import get_current_app_version
from mapping_workbench.backend.config import settings
from mapping_workbench.backend.core.models.api_response import AppSettingsResponse

router = APIRouter()

Expand All @@ -24,5 +24,5 @@ async def index(request: Request) -> JSONResponse:
)
async def app_settings() -> AppSettingsResponse:
return AppSettingsResponse(
version=get_current_app_version()
version=settings.APP_VERSION
)
37 changes: 37 additions & 0 deletions mapping_workbench/backend/core/scripts/get_app_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import subprocess


def get_current_app_tag():
try:
# Get the tag of the current commit (if any)
current_tag = subprocess.check_output(["git", "describe", "--exact-match", "--tags"]).strip().decode('utf-8')
return current_tag
except subprocess.CalledProcessError as e:
return None


def get_current_app_branch():
try:
return subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode('utf-8')
except subprocess.CalledProcessError:
return None


def get_current_app_tag_or_branch():
tag = get_current_app_tag()
if tag:
return tag
else:
branch = get_current_app_branch()
if branch:
return branch
else:
return None


def get_current_app_version():
return get_current_app_tag_or_branch()


if __name__ == "__main__":
print(get_current_app_version())
32 changes: 0 additions & 32 deletions mapping_workbench/backend/core/services/app.py
Original file line number Diff line number Diff line change
@@ -1,32 +0,0 @@
import subprocess


def get_current_app_tag():
try:
# Get the tag of the current commit (if any)
current_tag = subprocess.check_output(["git", "describe", "--exact-match", "--tags"]).strip().decode('utf-8')
return current_tag
except subprocess.CalledProcessError as e:
return None


def get_current_app_branch():
try:
return subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode('utf-8')
except subprocess.CalledProcessError:
return None


def get_current_app_tag_or_branch():
tag = get_current_app_tag()
if tag:
return tag
else:
branch = get_current_app_branch()
if branch:
return branch
else:
return None

def get_current_app_version():
return get_current_app_tag_or_branch()

0 comments on commit f9a1692

Please sign in to comment.