Add deploy_wages() — LXC 124, wages_db, wages app

Creates wages_db and deploys the wages app on LXC 124 (10.10.10.124).
Wired into --only wages dispatch, _append_secret, and full deploy sequence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-23 09:04:15 +00:00
parent a40bf2f8cf
commit 52e542d56c

View file

@ -1502,6 +1502,85 @@ ${build_out}"
npm_add_location "/reports/" "10.10.10.122" 3080
}
deploy_wages() {
msg_step "Wages (LXC 124 · 10.10.10.124)"
if [[ -z "${WAGES_DB_PASS:-}" ]]; then
WAGES_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)
printf '\nWAGES_DB_PASS=%s\n' "$WAGES_DB_PASS" >> "$CREDS_FILE"
msg_ok "Generated WAGES_DB_PASS → ${CREDS_FILE}"
fi
msg_info "Creating LXC 124"
create_lxc 124 "10.10.10.124" "wages" 1024 1
msg_ok "LXC 124 created"
msg_info "Installing Docker"
install_docker 124
install_mgmt_key 124
msg_ok "Docker + SSH ready"
msg_info "Creating wages database"
pct exec 100 -- bash -c "
docker exec hotel-manage-postgres psql -U postgres -c \
\"CREATE USER wages WITH PASSWORD '${WAGES_DB_PASS}';\" 2>/dev/null || true
docker exec hotel-manage-postgres psql -U postgres -c \
\"CREATE DATABASE wages_db OWNER wages;\" 2>/dev/null || true
docker exec hotel-manage-postgres psql -U postgres -d wages_db -c \
\"GRANT ALL ON SCHEMA public TO wages;\" 2>/dev/null || true
" &>/dev/null
msg_ok "Database wages_db ready"
msg_info "Deploying wages"
deploy_service 124 "wages" "${REPO_ROOT}/wages" /opt/wages
push_file 124 /opt/wages/.env <<EOF
NODE_ENV=production
APP_SLUG=wages
DATABASE_URL=postgresql://wages:${WAGES_DB_PASS}@10.10.10.100:5432/wages_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
EOF
local build_out
if ! build_out=$(pct exec 124 -- bash -c "cd /opt/wages && docker compose up -d --build 2>&1"); then
msg_error "docker compose build failed in LXC 124:
${build_out}"
fi
msg_info "Waiting for wages"
wait_healthy 124 "http://localhost:3080/wages/health" \
&& msg_ok "Wages running at 10.10.10.124:3080" \
|| msg_warn "Wages may need extra time — check LXC 124"
msg_info "Seeding wages 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 ('wages', 'Wage Costs', 'Live wage cost reporting — weekly, monthly, and rolling history vs budget and net sales', '/wages', 'DollarSign', '#065f46', 'Finance', '10.10.10.124', 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 Reports', 'View all wage cost reports (weekly, monthly, rolling)', 1),
('budget', 'Edit Budgets', 'Set monthly wage budget targets', 2),
('sync', 'Manual Sync', 'Trigger a Workforce API data sync or backfill', 3),
('settings', 'Settings', 'App settings, API configuration and department filter', 4)
) AS c(slug, name, description, sort_order)
WHERE a.slug = 'wages'
ON CONFLICT (app_id, slug) DO NOTHING;
" &>/dev/null \
&& msg_ok "wages seeded into auth DB" \
|| msg_warn "Seed failed — run wages/seed-app.js manually"
npm_add_location "/wages/" "10.10.10.124" 3080
}
deploy_kitchen() {
msg_step "Kitchen (LXC 110 · 10.10.10.110)"
@ -1913,7 +1992,7 @@ SUMMARY
# Sources existing credentials and redeploys just the named service.
if [[ "${1:-}" == "--only" ]]; then
ONLY="${2:-}"
VALID="postgres auth portal npm management noticeboard settings cashup hk-planner twin-optimiser room-planner maintenance forecasting rates reports kitchen kds"
VALID="postgres auth portal npm management noticeboard settings cashup hk-planner twin-optimiser room-planner maintenance forecasting rates reports kitchen kds wages"
[[ -z "$ONLY" ]] && msg_error "Usage: install-stack.sh --only <service> (one of: ${VALID})"
grep -qw "$ONLY" <<< "$VALID" || msg_error "Unknown service '${ONLY}'. Valid: ${VALID}"
CREDS_FILE=/root/hotel-manage-credentials.txt
@ -1945,6 +2024,8 @@ if [[ "${1:-}" == "--only" ]]; then
"$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)"
[[ -z "${KITCHEN_DB_PASS:-}" ]] && _append_secret KITCHEN_DB_PASS \
"$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)"
[[ -z "${WAGES_DB_PASS:-}" ]] && _append_secret WAGES_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 ]] \
@ -1969,6 +2050,7 @@ if [[ "${1:-}" == "--only" ]]; then
reports) deploy_reports ;;
kitchen) deploy_kitchen ;;
kds) deploy_kds ;;
wages) deploy_wages ;;
esac
exit 0
fi
@ -1996,5 +2078,6 @@ deploy_rates
deploy_reports
deploy_kitchen
deploy_kds
deploy_wages
configure_npm_proxy_hosts
print_summary