Změny:
NEW_APP_SCRIPT odstraněn z app/config.py. create_app už volá skeleton přes app_templates.create_script:načte template podle ID, ověří is_enabled = 1 a create_enabled = 1 přes get_app_template(..., create_enabled=True), ověří neprázdný create_script, volá [create_script, app_id, app_name]. runtime, language, container_port, health_url dál bere z vybraného template řádku. DB helper a migrace znají nové sloupce create_script a deploy_script. deploy_script se při create použije, pokud je v template vyplněný; jinak zůstává dosavadní deploy fallback.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
NEW_APP_SCRIPT = "/tools/new-python-app.sh"
|
|
||||||
DEPLOY_SCRIPT = "/tools/deploy-app.sh"
|
DEPLOY_SCRIPT = "/tools/deploy-app.sh"
|
||||||
DELETE_APP_SCRIPT = "/tools/delete-app.sh"
|
DELETE_APP_SCRIPT = "/tools/delete-app.sh"
|
||||||
BACKUP_SCRIPT = "/tools/backup-appfactory.sh"
|
BACKUP_SCRIPT = "/tools/backup-appfactory.sh"
|
||||||
|
|||||||
@@ -97,6 +97,8 @@ def get_app_templates(create_enabled: bool = False):
|
|||||||
description,
|
description,
|
||||||
default_port,
|
default_port,
|
||||||
default_health_path,
|
default_health_path,
|
||||||
|
create_script,
|
||||||
|
deploy_script,
|
||||||
COALESCE(is_enabled, 1) AS is_enabled,
|
COALESCE(is_enabled, 1) AS is_enabled,
|
||||||
COALESCE(create_enabled, 0) AS create_enabled
|
COALESCE(create_enabled, 0) AS create_enabled
|
||||||
FROM app_templates
|
FROM app_templates
|
||||||
@@ -125,6 +127,8 @@ def get_app_template(template_id: str, create_enabled: bool = False):
|
|||||||
description,
|
description,
|
||||||
default_port,
|
default_port,
|
||||||
default_health_path,
|
default_health_path,
|
||||||
|
create_script,
|
||||||
|
deploy_script,
|
||||||
COALESCE(is_enabled, 1) AS is_enabled,
|
COALESCE(is_enabled, 1) AS is_enabled,
|
||||||
COALESCE(create_enabled, 0) AS create_enabled
|
COALESCE(create_enabled, 0) AS create_enabled
|
||||||
FROM app_templates
|
FROM app_templates
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ def run_migrations():
|
|||||||
description TEXT,
|
description TEXT,
|
||||||
default_port INTEGER,
|
default_port INTEGER,
|
||||||
default_health_path TEXT,
|
default_health_path TEXT,
|
||||||
|
create_script TEXT,
|
||||||
|
deploy_script TEXT,
|
||||||
is_enabled INTEGER NOT NULL DEFAULT 1,
|
is_enabled INTEGER NOT NULL DEFAULT 1,
|
||||||
create_enabled INTEGER NOT NULL DEFAULT 0,
|
create_enabled INTEGER NOT NULL DEFAULT 0,
|
||||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
@@ -138,6 +140,8 @@ def run_migrations():
|
|||||||
"ALTER TABLE app_templates ADD COLUMN description TEXT",
|
"ALTER TABLE app_templates ADD COLUMN description TEXT",
|
||||||
"ALTER TABLE app_templates ADD COLUMN default_port INTEGER",
|
"ALTER TABLE app_templates ADD COLUMN default_port INTEGER",
|
||||||
"ALTER TABLE app_templates ADD COLUMN default_health_path TEXT",
|
"ALTER TABLE app_templates ADD COLUMN default_health_path TEXT",
|
||||||
|
"ALTER TABLE app_templates ADD COLUMN create_script TEXT",
|
||||||
|
"ALTER TABLE app_templates ADD COLUMN deploy_script TEXT",
|
||||||
"ALTER TABLE app_templates ADD COLUMN is_enabled INTEGER NOT NULL DEFAULT 1",
|
"ALTER TABLE app_templates ADD COLUMN is_enabled INTEGER NOT NULL DEFAULT 1",
|
||||||
"ALTER TABLE app_templates ADD COLUMN create_enabled INTEGER NOT NULL DEFAULT 0",
|
"ALTER TABLE app_templates ADD COLUMN create_enabled INTEGER NOT NULL DEFAULT 0",
|
||||||
"ALTER TABLE app_templates ADD COLUMN created_at TEXT",
|
"ALTER TABLE app_templates ADD COLUMN created_at TEXT",
|
||||||
|
|||||||
+6
-3
@@ -12,7 +12,6 @@ from ..config import (
|
|||||||
DELETE_APP_SCRIPT,
|
DELETE_APP_SCRIPT,
|
||||||
DEPLOY_SCRIPT,
|
DEPLOY_SCRIPT,
|
||||||
GENERATE_COMPOSE_SCRIPT,
|
GENERATE_COMPOSE_SCRIPT,
|
||||||
NEW_APP_SCRIPT,
|
|
||||||
read_env_value,
|
read_env_value,
|
||||||
)
|
)
|
||||||
from ..db.apps import (
|
from ..db.apps import (
|
||||||
@@ -930,8 +929,11 @@ def create_app(
|
|||||||
selected_template = get_app_template(template, create_enabled=True)
|
selected_template = get_app_template(template, create_enabled=True)
|
||||||
if not selected_template:
|
if not selected_template:
|
||||||
return HTMLResponse("Nepodporovaná šablona", status_code=400)
|
return HTMLResponse("Nepodporovaná šablona", status_code=400)
|
||||||
|
create_script = clean_optional(selected_template.get("create_script"))
|
||||||
|
if not create_script:
|
||||||
|
return HTMLResponse("Šablona nemá nastavený create script", status_code=400)
|
||||||
|
|
||||||
create_result = run_command([NEW_APP_SCRIPT, app_id, app_name])
|
create_result = run_command([create_script, app_id, app_name])
|
||||||
if create_result.returncode == 0:
|
if create_result.returncode == 0:
|
||||||
update_app_template_metadata(
|
update_app_template_metadata(
|
||||||
app_id,
|
app_id,
|
||||||
@@ -944,7 +946,8 @@ def create_app(
|
|||||||
"container_port": selected_template.get("default_port"),
|
"container_port": selected_template.get("default_port"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
deploy_result = run_command([DEPLOY_SCRIPT, app_id])
|
deploy_script = clean_optional(selected_template.get("deploy_script")) or DEPLOY_SCRIPT
|
||||||
|
deploy_result = run_command([deploy_script, app_id])
|
||||||
|
|
||||||
status = "OK" if create_result.returncode == 0 and deploy_result.returncode == 0 else "FAILED"
|
status = "OK" if create_result.returncode == 0 and deploy_result.returncode == 0 else "FAILED"
|
||||||
log_audit_event(
|
log_audit_event(
|
||||||
|
|||||||
Reference in New Issue
Block a user