From 5c345e47a9c9b0b9d1bbb6cc9c78218abd138bcf Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Mon, 6 Jul 2026 12:58:42 +0000 Subject: [PATCH] =?UTF-8?q?Add=20deploy=5Freports=20function=20(LXC=20122?= =?UTF-8?q?=20=C2=B7=2010.10.10.122)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creates reports_db, deploys reports app to LXC 122, seeds auth DB with app entry and capabilities, registers /reports/ location in NPM. Co-Authored-By: Claude Sonnet 4.6 --- install-stack.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/install-stack.sh b/install-stack.sh index 617dbbb..4df54bc 100755 --- a/install-stack.sh +++ b/install-stack.sh @@ -1424,6 +1424,85 @@ ${build_out}" npm_add_location "/rates/" "10.10.10.115" 3080 } +deploy_reports() { + msg_step "Reports (LXC 122 · 10.10.10.122)" + + if [[ -z "${REPORTS_DB_PASS:-}" ]]; then + REPORTS_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) + printf '\nREPORTS_DB_PASS=%s\n' "$REPORTS_DB_PASS" >> "$CREDS_FILE" + msg_ok "Generated REPORTS_DB_PASS → ${CREDS_FILE}" + fi + + msg_info "Creating LXC 122" + create_lxc 122 "10.10.10.122" "reports" 1024 1 + msg_ok "LXC 122 created" + + msg_info "Installing Docker" + install_docker 122 + install_mgmt_key 122 + msg_ok "Docker + SSH ready" + + msg_info "Creating reports database" + pct exec 100 -- bash -c " + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE USER reports WITH PASSWORD '${REPORTS_DB_PASS}';\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE DATABASE reports_db OWNER reports;\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -d reports_db -c \ + \"GRANT ALL ON SCHEMA public TO reports;\" 2>/dev/null || true + " &>/dev/null + msg_ok "Database reports_db ready" + + msg_info "Deploying reports" + deploy_service 122 "reports" "${REPO_ROOT}/reports" /opt/reports + + push_file 122 /opt/reports/.env <&1"); then + msg_error "docker compose build failed in LXC 122: +${build_out}" + fi + + msg_info "Waiting for reports" + wait_healthy 122 "http://localhost:3080/reports/health" \ + && msg_ok "Reports running at 10.10.10.122:3080" \ + || msg_warn "Reports may need extra time — check LXC 122" + + msg_info "Seeding reports into auth DB" + pct exec 100 -- docker exec hotel-manage-postgres psql -U postgres -d auth_db -c " + INSERT INTO apps (slug, name, description, base_path, icon, theme_color, category, internal_host, internal_port) + VALUES ('reports', 'Reports', 'Custom reports for NewBook, ResOS, SambaPOS and internal data', '/reports', 'BarChart2', '#1d4ed8', 'Management', '10.10.10.122', 3080) + ON CONFLICT (slug) DO UPDATE SET + name=EXCLUDED.name, description=EXCLUDED.description, base_path=EXCLUDED.base_path, + icon=EXCLUDED.icon, theme_color=EXCLUDED.theme_color, category=EXCLUDED.category, + internal_host=EXCLUDED.internal_host, internal_port=EXCLUDED.internal_port; + INSERT INTO app_capabilities (app_id, slug, name, description, sort_order) + SELECT a.id, c.slug, c.name, c.description, c.sort_order + FROM apps a, (VALUES + ('view', 'View & Run Reports', 'Browse and run all custom reports', 1), + ('export', 'Export to CSV', 'Download report results as a CSV file', 2) + ) AS c(slug, name, description, sort_order) + WHERE a.slug = 'reports' + ON CONFLICT (app_id, slug) DO NOTHING; + " &>/dev/null \ + && msg_ok "reports seeded into auth DB" \ + || msg_warn "Seed failed — run auth db.js manually" + + npm_add_location "/reports/" "10.10.10.122" 3080 +} + # ════════════════════════════════════════════════════════════════════════════ # NPM PROXY HOSTS (via API) # ════════════════════════════════════════════════════════════════════════════ @@ -1700,6 +1779,8 @@ if [[ "${1:-}" == "--only" ]]; then "$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)" [[ -z "${FORECASTING_DB_PASS:-}" ]] && _append_secret FORECASTING_DB_PASS \ "$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)" + [[ -z "${REPORTS_DB_PASS:-}" ]] && _append_secret REPORTS_DB_PASS \ + "$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)" USE_FORGEJO=true [[ -f /root/.ssh/hotel-manage_deploy.pub ]] \ @@ -1721,6 +1802,7 @@ if [[ "${1:-}" == "--only" ]]; then maintenance) deploy_maintenance ;; forecasting) deploy_forecasting ;; rates) deploy_rates ;; + reports) deploy_reports ;; esac exit 0 fi @@ -1745,5 +1827,6 @@ deploy_room_planner deploy_maintenance deploy_forecasting deploy_rates +deploy_reports configure_npm_proxy_hosts print_summary