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

fix: add flags, validations, error messages #1430

Merged
merged 7 commits into from
Feb 20, 2024
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
4 changes: 2 additions & 2 deletions press/fixtures/frappe_version.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"parent": "Version 15",
"parentfield": "dependencies",
"parenttype": "Frappe Version",
"version": "5.16.0"
"version": "5.22.0"
}
],
"docstatus": 0,
Expand Down Expand Up @@ -176,7 +176,7 @@
"parent": "Nightly",
"parentfield": "dependencies",
"parenttype": "Frappe Version",
"version": "5.16.2"
"version": "5.22.0"
}
],
"docstatus": 0,
Expand Down
2 changes: 1 addition & 1 deletion press/press/doctype/agent_job/agent_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def get_status(self):

if not self.job_id:
job = agent.get_jobs_id(self.name)
if len(job) > 0:
if job and len(job) > 0:
self.db_set("job_id", job[0]["id"])
if self.job_id:
polled_job = agent.get_job_status(self.job_id)
Expand Down
3 changes: 1 addition & 2 deletions press/press/doctype/frappe_version/frappe_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import copy
from frappe.model.document import Document


DEFAULT_DEPENDENCIES = [
{"dependency": "NVM_VERSION", "version": "0.36.0"},
{"dependency": "NODE_VERSION", "version": "18.16.0"},
{"dependency": "PYTHON_VERSION", "version": "3.11"},
{"dependency": "WKHTMLTOPDF_VERSION", "version": "0.12.5"},
{"dependency": "BENCH_VERSION", "version": "5.16.2"},
{"dependency": "BENCH_VERSION", "version": "5.22.0"},
]


Expand Down
19 changes: 18 additions & 1 deletion press/press/doctype/press_settings/press_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"column_break_66",
"code_server",
"code_server_password",
"use_app_cache",
"compress_app_cache",
"auto_update_section",
"auto_update_queue_size",
"remote_files_section",
Expand Down Expand Up @@ -1103,11 +1105,26 @@
"fieldname": "print_format",
"fieldtype": "Data",
"label": "Print Format"
},
{
"default": "0",
"description": "Uses Bench get-app cache for faster image builds. Will be set only if Bench version is 5.21.3 or later.",
"fieldname": "use_app_cache",
"fieldtype": "Check",
"label": "Use App Cache"
},
{
"default": "0",
"depends_on": "eval: doc.use_app_cache",
"description": "Use Gzip to compress bench get-app artifacts before caching.",
"fieldname": "compress_app_cache",
"fieldtype": "Check",
"label": "Compress App Cache"
}
],
"issingle": 1,
"links": [],
"modified": "2024-01-11 23:28:22.862640",
"modified": "2024-02-09 16:30:31.244735",
"modified_by": "Administrator",
"module": "Press",
"name": "Press Settings",
Expand Down
35 changes: 35 additions & 0 deletions press/press/doctype/release_group/release_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def before_insert(self):
# to avoid ading deps while cloning a release group
if len(self.dependencies) == 0:
self.fetch_dependencies()
self.set_default_app_cache_flags()

def on_update(self):
old_doc = self.get_doc_before_save()
Expand Down Expand Up @@ -401,6 +402,8 @@ def create_deploy_candidate(self, apps_to_update=None) -> "DeployCandidate":
return

apps = self.get_apps_to_update(apps_to_update)
if apps_to_update is None:
self.validate_dc_apps_against_rg(apps)

dependencies = [
{"dependency": d.dependency, "version": d.version} for d in self.dependencies
Expand Down Expand Up @@ -434,6 +437,22 @@ def create_deploy_candidate(self, apps_to_update=None) -> "DeployCandidate":

return candidate

def validate_dc_apps_against_rg(self, dc_apps) -> None:
app_map = {app["app"]: app for app in dc_apps}
not_found = []
for app in self.apps:
if app.app in app_map:
continue
not_found.append(app.app)

if not not_found:
return

msg = _(
"Following apps {0} not found. Potentially due to not approved App Releases."
).format(not_found)
frappe.throw(msg)

def get_apps_to_update(self, apps_to_update):
# If apps_to_update is None, try to update all apps
if apps_to_update is None:
Expand Down Expand Up @@ -1019,6 +1038,22 @@ def archive(self):
self.enabled = 0
self.save()

def set_default_app_cache_flags(self):
if self.use_app_cache:
return

if not frappe.db.get_single_value("Press Settings", "use_app_cache"):
return

if not self.can_use_get_app_cache():
return

self.use_app_cache = 1
self.compress_app_cache = frappe.db.get_single_value(
"Press Settings",
"compress_app_cache",
)


def new_release_group(
title, version, apps, team=None, cluster=None, saas_app="", server=None
Expand Down
Loading