Add deploy_reports function (LXC 122 · 10.10.10.122)
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 <noreply@anthropic.com>
This commit is contained in:
parent
9cf7ed6d70
commit
5c345e47a9
1 changed files with 83 additions and 0 deletions
|
|
@ -1424,6 +1424,85 @@ ${build_out}"
|
||||||
npm_add_location "/rates/" "10.10.10.115" 3080
|
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 <<EOF
|
||||||
|
NODE_ENV=production
|
||||||
|
APP_SLUG=reports
|
||||||
|
DATABASE_URL=postgresql://reports:${REPORTS_DB_PASS}@10.10.10.100:5432/reports_db
|
||||||
|
CENTRAL_AUTH_SECRET=${CENTRAL_AUTH_SECRET}
|
||||||
|
SETTINGS_URL=http://10.10.10.116:3080
|
||||||
|
SETTINGS_SECRET=${SETTINGS_SECRET}
|
||||||
|
OFFICE_IP_CHECK=${OFFICE_IP_CHECK:-${OFFICE_IP:-disabled}}
|
||||||
|
FRONTEND_PORT=3080
|
||||||
|
RESOS_API_KEY=
|
||||||
|
SAMBA_DATABASE_URL=
|
||||||
|
EOF
|
||||||
|
|
||||||
|
local build_out
|
||||||
|
if ! build_out=$(pct exec 122 -- bash -c "cd /opt/reports && docker compose up -d --build 2>&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)
|
# 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)"
|
"$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)"
|
||||||
[[ -z "${FORECASTING_DB_PASS:-}" ]] && _append_secret FORECASTING_DB_PASS \
|
[[ -z "${FORECASTING_DB_PASS:-}" ]] && _append_secret FORECASTING_DB_PASS \
|
||||||
"$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)"
|
"$(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
|
USE_FORGEJO=true
|
||||||
[[ -f /root/.ssh/hotel-manage_deploy.pub ]] \
|
[[ -f /root/.ssh/hotel-manage_deploy.pub ]] \
|
||||||
|
|
@ -1721,6 +1802,7 @@ if [[ "${1:-}" == "--only" ]]; then
|
||||||
maintenance) deploy_maintenance ;;
|
maintenance) deploy_maintenance ;;
|
||||||
forecasting) deploy_forecasting ;;
|
forecasting) deploy_forecasting ;;
|
||||||
rates) deploy_rates ;;
|
rates) deploy_rates ;;
|
||||||
|
reports) deploy_reports ;;
|
||||||
esac
|
esac
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
@ -1745,5 +1827,6 @@ deploy_room_planner
|
||||||
deploy_maintenance
|
deploy_maintenance
|
||||||
deploy_forecasting
|
deploy_forecasting
|
||||||
deploy_rates
|
deploy_rates
|
||||||
|
deploy_reports
|
||||||
configure_npm_proxy_hosts
|
configure_npm_proxy_hosts
|
||||||
print_summary
|
print_summary
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue