Refactor route handling in panelctl.sh and update caddy configuration for improved route management

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Jakub Dorfman 2026-04-26 20:41:56 +02:00
parent 36664f243e
commit 17ac5953ae
4 changed files with 35 additions and 11 deletions

View file

@ -5,7 +5,7 @@
email = "admin@srazka.com";
extraConfig = ''
# Generated app routes from the panel backend.
import /home/reudy/containers/routes/*.caddy
import /home/reudy/containers/routes/routes.caddy
'';
# Authelia's own login portal

View file

@ -43,7 +43,7 @@
"d /home/reudy/containers 0750 reudy panelroutes -"
"d /home/reudy/containers/stacks 0750 reudy panelroutes -"
"d /home/reudy/containers/volumes 0750 reudy panelroutes -"
"d /home/reudy/containers/routes 0750 reudy panelroutes -"
"d /home/reudy/containers/routes 0755 reudy panelroutes -"
"d /home/reudy/containers/state 0750 reudy panelroutes -"
"d /home/reudy/containers/state/apps 0750 reudy panelroutes -"
"f /home/reudy/containers/routes/_placeholder.caddy 0640 reudy panelroutes -"

View file

@ -43,9 +43,8 @@ INDEX_HTML = """<!doctype html>
}
.wrap {
max-width: 980px;
margin: 0 auto;
padding: 28px 16px 40px;
padding: 28px 28px 40px;
}
.hero {

View file

@ -76,7 +76,7 @@ app_volume_dir() {
app_route_file() {
local name="$1"
echo "${ROUTES_DIR}/${name}.caddy"
echo "${ROUTES_DIR}/routes.caddy"
}
load_app() {
@ -248,12 +248,29 @@ cmd_render_route() {
auth_block="${FORWARD_AUTH_BLOCK}"
fi
cat >"${APP_ROUTE_FILE}" <<EOF
${APP_DOMAIN} {
${auth_block} reverse_proxy ${APP_UPSTREAM}
}
EOF
# Append to aggregate routes file (idempotent: remove stale block first).
local tmp
tmp="$(mktemp)"
# Strip any existing block for this app from the aggregate file.
if [[ -f "${APP_ROUTE_FILE}" ]]; then
grep -v "^# route:${name}:" "${APP_ROUTE_FILE}" >"${tmp}"
else
printf "" >"${tmp}"
fi
{
printf "# route:%s:start\n" "${name}"
printf "%s {\n" "${APP_DOMAIN}"
if [[ -n "${auth_block}" ]]; then
printf "%s\n" "${auth_block}"
fi
printf " reverse_proxy %s\n" "${APP_UPSTREAM}"
printf "}\n"
printf "# route:%s:end\n" "${name}"
} >>"${tmp}"
mv "${tmp}" "${APP_ROUTE_FILE}"
echo "rendered route ${APP_ROUTE_FILE}"
}
@ -306,7 +323,15 @@ cmd_remove() {
run_compose -f "${APP_COMPOSE_FILE}" down || true
rm -f "${APP_ROUTE_FILE}" "$(app_manifest "${name}")"
# Remove this app's block from the aggregate routes file.
if [[ -f "${APP_ROUTE_FILE}" ]]; then
local tmp
tmp="$(mktemp)"
grep -v "^# route:${name}:" "${APP_ROUTE_FILE}" >"${tmp}"
mv "${tmp}" "${APP_ROUTE_FILE}"
fi
rm -f "$(app_manifest "${name}")"
rm -rf "${APP_STACK_DIR}"
if [[ "${keep_volumes}" != "--keep-volumes" ]]; then