Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release workflow feat test #401

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
3b00cd3
added new menu releases
prem056627 Aug 20, 2024
6d84cb2
Fix : code clean fix
prem056627 Aug 21, 2024
65a4850
Fix : releases rendering issue fixed
prem056627 Sep 2, 2024
6173dea
Fix : search and filter option issue fixed
prem056627 Sep 2, 2024
28e082a
wip: release workflow
shahharsh176 Jul 23, 2024
1ecb95d
rename to update_apps
shahharsh176 Jul 28, 2024
f22227c
fix: rename update-apps in model register method
shahharsh176 Jul 29, 2024
687f323
export fixtures change indent to 4
shahharsh176 Jul 29, 2024
bcad1dc
add: git settings
shahharsh176 Aug 7, 2024
03bf0db
non git mode support for release added
deepakdinesh1123 Aug 23, 2024
6af0f51
git init skipped in non git mode
deepakdinesh1123 Aug 23, 2024
60a5909
wip: release workflow
shahharsh176 Jul 23, 2024
15d9053
rename to update_apps
shahharsh176 Jul 28, 2024
a15b944
release api added
deepakdinesh1123 Aug 29, 2024
1cee751
release api fixes
deepakdinesh1123 Aug 29, 2024
d90f0e8
api fixed
deepakdinesh1123 Sep 2, 2024
9627619
version checks added to non git mode
deepakdinesh1123 Sep 10, 2024
a072e59
minor fixes
DevilsAutumn Sep 11, 2024
69d1bc2
ruff formatting
DevilsAutumn Sep 16, 2024
5c33e6f
minor
DevilsAutumn Sep 16, 2024
1abb57b
rebase cleanup
DevilsAutumn Sep 16, 2024
ba44a40
minor formatting
DevilsAutumn Sep 16, 2024
d99118e
handle empty url
DevilsAutumn Sep 18, 2024
f2037b3
minor
DevilsAutumn Sep 18, 2024
89b78f8
Merge pull request #384 from Healthlane-Technologies/hotfix/release_w…
shahharsh176 Sep 18, 2024
0cae914
fixed latest release check
DevilsAutumn Sep 18, 2024
fed1270
formatting and linting
DevilsAutumn Sep 18, 2024
9def04d
Merge pull request #385 from Healthlane-Technologies/hotfix/latest_re…
shahharsh176 Sep 18, 2024
aa505b7
Added package install and launch from template functionality.
DevilsAutumn Sep 16, 2024
aed1be5
formatting and linting fixes
DevilsAutumn Sep 16, 2024
58ac45c
added template downloading.
DevilsAutumn Sep 16, 2024
c9938d0
template upload
adhiraj23zelthy Sep 24, 2024
7243af3
moved git config to tenant model
DevilsAutumn Sep 26, 2024
8636329
added git config in tenant model
DevilsAutumn Sep 26, 2024
38bde6a
modified app update api to handle extra_config.
DevilsAutumn Sep 26, 2024
f48a964
run git setup
DevilsAutumn Sep 26, 2024
5d56d31
minor
DevilsAutumn Sep 26, 2024
cf6e13a
Githup repo config frontend (#390)
adhiraj23zelthy Sep 26, 2024
2ea9344
fix: edit data
adhiraj23zelthy Sep 26, 2024
f8beec7
fixed bugs in release workflow
DevilsAutumn Sep 25, 2024
bf248a3
merge main branch
deepakdinesh1123 Sep 27, 2024
6ffcd34
merge feat/releases
deepakdinesh1123 Sep 27, 2024
d0e1aa3
initialie repo with url
DevilsAutumn Sep 27, 2024
3823173
Merge pull request #393 from Healthlane-Technologies/merge/release_fr…
shahharsh176 Sep 27, 2024
a028b0e
Merge pull request #392 from Healthlane-Technologies/hotfix/release_w…
shahharsh176 Sep 27, 2024
365c92e
minor
DevilsAutumn Oct 1, 2024
8f5e2dc
ruff fix
DevilsAutumn Oct 1, 2024
4b6febb
minor
DevilsAutumn Oct 1, 2024
9c76ac0
release fixes
deepakdinesh1123 Oct 18, 2024
15534ce
Merge branch 'feat/package_install_and_launch_from_template' into git…
DevilsAutumn Oct 22, 2024
342b77f
Merge pull request #391 from Healthlane-Technologies/git_config_tenan…
DevilsAutumn Oct 22, 2024
c008183
Merge pull request #399 from Healthlane-Technologies/feat/package_ins…
shahharsh176 Oct 24, 2024
147ac4c
Merge pull request #387 from Healthlane-Technologies/launch_template_…
shahharsh176 Oct 24, 2024
4e197da
Merge pull request #400 from Healthlane-Technologies/feat/package_ins…
shahharsh176 Oct 24, 2024
c8230fb
added sync packages setting
DevilsAutumn Oct 22, 2024
e086873
apply package migrations
DevilsAutumn Oct 22, 2024
93ae372
fixed issue with no app template
DevilsAutumn Oct 25, 2024
c6fc81d
feat: fe sync packages
adhiraj23zelthy Oct 24, 2024
bbb0a4f
detail about github url & branches
adhiraj23zelthy Oct 25, 2024
efe80fe
Merge pull request #398 from Healthlane-Technologies/added_sync_packa…
shahharsh176 Oct 28, 2024
28a4756
Merge pull request #405 from Healthlane-Technologies/feat/package_ins…
shahharsh176 Oct 28, 2024
8940983
error message when app_name or version is not present in settings.jso…
deepakdinesh1123 Oct 30, 2024
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
2 changes: 1 addition & 1 deletion backend/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ django-storages==1.14
django-tenants==3.6.1
djangorestframework==3.15.2
flake8==6.1.0

flower==2.0.1
GitPython==3.1.43
loguru==0.7.2
opentelemetry-api==1.22.0
opentelemetry-distro==0.43b0
Expand Down
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions backend/src/zango/api/platform/releases/v1/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from rest_framework import serializers

from zango.apps.release.models import AppRelease
from zango.core.utils import get_datetime_str_in_tenant_timezone


class AppReleaseSerializer(serializers.ModelSerializer):
created_at = serializers.SerializerMethodField()

class Meta:
model = AppRelease
fields = [
"id",
"version",
"description",
"status",
"last_git_hash",
"created_at",
]

def get_created_at(self, obj):
return get_datetime_str_in_tenant_timezone(
obj.created_at, self.context["tenant"]
)
8 changes: 8 additions & 0 deletions backend/src/zango/api/platform/releases/v1/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path

from .views import AppReleaseView


urlpatterns = [
path("", AppReleaseView.as_view()),
]
156 changes: 156 additions & 0 deletions backend/src/zango/api/platform/releases/v1/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import json

from datetime import datetime

import pytz

from django.conf import settings
from django.db.models import Q
from django.utils.decorators import method_decorator

from zango.apps.release.models import AppRelease
from zango.apps.shared.tenancy.models import TenantModel
from zango.core.api import ZangoGenericPlatformAPIView, get_api_response
from zango.core.api.utils import ZangoAPIPagination
from zango.core.common_utils import set_app_schema_path
from zango.core.utils import get_search_columns

from .serializers import AppReleaseSerializer


@method_decorator(set_app_schema_path, name="dispatch")
class AppReleaseView(ZangoGenericPlatformAPIView, ZangoAPIPagination):
pagination_class = ZangoAPIPagination

def process_timestamp(self, timestamp, timezone):
try:
ts = json.loads(timestamp)
if not timezone:
timezone = settings.TIME_ZONE
tz = pytz.timezone(timezone)
ts["start"] = tz.localize(
datetime.strptime(ts["start"] + "-" + "00:00", "%Y-%m-%d-%H:%M"),
is_dst=None,
)
ts["end"] = tz.localize(
datetime.strptime(ts["end"] + "-" + "23:59", "%Y-%m-%d-%H:%M"),
is_dst=None,
)
return ts
except Exception:
import traceback

traceback.print_exc()
return None

def process_id(self, id):
try:
return int(id)
except ValueError:
return None

def get_queryset(self, search, tenant, columns={}):
field_name_query_mapping = {
"version": "version__icontains",
"description": "description__icontains",
"status": "status",
"id": "id__icontains",
}
search_filters = {
"id": self.process_id,
"Release_date": self.process_timestamp,
}
if columns.get("status") == "" or columns.get("status") is None:
field_name_query_mapping.pop("status")
records = AppRelease.objects.all().order_by("-id")
if search == "" and columns == {}:
return records
filters = Q()
for field_name, query in field_name_query_mapping.items():
if search:
if search_filters.get(field_name, None):
value = search_filters[field_name](search)
if value is not None:
filters |= Q(**{query: value})
else:
filters |= Q(**{query: search})
records = records.filter(filters).distinct()
if columns.get("Release_date"):
processed = self.process_timestamp(
columns.get("Release_date"), tenant.timezone
)
if processed is not None:
records = records.filter(
created_at__gte=processed["start"], created_at__lte=processed["end"]
)
if columns.get("status"):
records = records.filter(status=columns["status"])
if columns.get("version"):
records = records.filter(version=columns["version"])
return records

def get_dropdown_options(self):
options = {}
options["version"] = [
{
"id": version,
"label": version,
}
for version in AppRelease.objects.values_list(
"version", flat=True
).distinct()
]
options["status"] = [
{
"id": "initiated",
"label": "Initiated",
},
{
"id": "in_progress",
"label": "In Progress",
},
{
"id": "released",
"label": "Released",
},
{
"id": "failed",
"label": "Failed",
},
{
"id": "archived",
"label": "Archived",
},
]
return options

def get(self, request, app_uuid, *args, **kwargs):
try:
tenant = TenantModel.objects.get(uuid=app_uuid)
include_dropdown_options = request.GET.get("include_dropdown_options")
search = request.GET.get("search", None)
columns = get_search_columns(request)
app_releases = self.get_queryset(search, tenant, columns)
paginated_releases = self.paginate_queryset(
app_releases, request, view=self
)
serializer = AppReleaseSerializer(
paginated_releases, many=True, context={"tenant": tenant}
)
paginated_app_releases = self.get_paginated_response_data(serializer.data)
success = True
response = {
"releases": paginated_app_releases,
"message": "All app releases fetched successfully",
}
if include_dropdown_options:
response["dropdown_options"] = self.get_dropdown_options()
status = 200
except Exception as e:
import traceback

traceback.print_exc()
success = False
response = {"message": str(e)}
status = 500
return get_api_response(success, response, status)
12 changes: 12 additions & 0 deletions backend/src/zango/api/platform/tenancy/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ def get_date_format_display(self, obj):
return obj.get_date_format_display()

def update(self, instance, validated_data):
request = self.context["request"]
extra_config_str = request.data.get("extra_config")
# Convert extra_config from string to JSON if it exists
if extra_config_str:
try:
extra_config_json = json.loads(extra_config_str)
validated_data["extra_config"] = extra_config_json
except json.JSONDecodeError:
raise serializers.ValidationError(
{"extra_config": "Invalid JSON format"}
)

instance = super(TenantSerializerModel, self).update(instance, validated_data)
request = self.context["request"]
domains = request.data.getlist("domains")
Expand Down
2 changes: 2 additions & 0 deletions backend/src/zango/api/platform/tenancy/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from zango.api.platform.codeassist.v1 import urls as codeassist_v1_urls
from zango.api.platform.packages.v1 import urls as packages_v1_urls
from zango.api.platform.permissions.v1 import urls as permissions_v1_urls
from zango.api.platform.releases.v1 import urls as releases_v1_urls
from zango.api.platform.tasks.v1 import urls as tasks_v1_urls

from .views import (
Expand Down Expand Up @@ -61,5 +62,6 @@
re_path(r"^(?P<app_uuid>[\w-]+)/code-assist/", include(codeassist_v1_urls)),
re_path(r"^(?P<app_uuid>[\w-]+)/auditlog/", include(auditlog_v1_urls)),
re_path(r"^(?P<app_uuid>[\w-]+)/access-logs/", include(accesslog_v1_urls)),
re_path(r"^(?P<app_uuid>[\w-]+)/releases/", include(releases_v1_urls)),
path("", include(permissions_v1_urls)),
]
63 changes: 63 additions & 0 deletions backend/src/zango/api/platform/tenancy/v1/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import json
import os
import zipfile


def extract_app_details_from_zip(template_zip):
settings_filename = "settings.json"
try:
with zipfile.ZipFile(template_zip, "r") as zip_file:
# Check if the settings file exists in the zip
zip_name = str(template_zip).split(".")[0]

# List all files in the zip
all_files = zip_file.namelist()

# Find the settings file path
settings_path = None
for file_path in all_files:
if file_path == os.path.join(zip_name, settings_filename):
settings_path = file_path
break

if not settings_path:
raise FileNotFoundError(
f"{settings_filename} not found in the zip file."
)

# Read the contents of the settings file
with zip_file.open(settings_path) as settings_file:
settings_content = settings_file.read()

# Parse the JSON content
settings = json.loads(settings_content)
return (
settings["version"],
settings["app_name"],
)

except zipfile.BadZipFile:
raise Exception(f"Error: {template_zip} is not a valid zip file.")
except json.JSONDecodeError:
raise Exception(f"Error: {settings_filename} is not a valid JSON file.")
except KeyError:
raise Exception(f"Error: version or app_name not found in {settings_filename}.")
except Exception as e:
raise Exception(f"An error occurred: {str(e)}")


def extract_zip_to_temp_dir(app_template):
# Create a temporary directory
temp_dir = os.getcwd()

try:
# Extract the zip file to the temporary directory
with zipfile.ZipFile(app_template, "r") as zip_ref:
zip_ref.extractall(temp_dir)

# Return the path of the temporary directory
return temp_dir
except Exception as e:
# If an error occurs, remove the temporary directory and re-raise the exception
os.rmdir(temp_dir)
raise e
Loading
Loading