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:
parent
36664f243e
commit
17ac5953ae
4 changed files with 35 additions and 11 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
email = "admin@srazka.com";
|
email = "admin@srazka.com";
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
# Generated app routes from the panel backend.
|
# 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
|
# Authelia's own login portal
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
"d /home/reudy/containers 0750 reudy panelroutes -"
|
"d /home/reudy/containers 0750 reudy panelroutes -"
|
||||||
"d /home/reudy/containers/stacks 0750 reudy panelroutes -"
|
"d /home/reudy/containers/stacks 0750 reudy panelroutes -"
|
||||||
"d /home/reudy/containers/volumes 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 0750 reudy panelroutes -"
|
||||||
"d /home/reudy/containers/state/apps 0750 reudy panelroutes -"
|
"d /home/reudy/containers/state/apps 0750 reudy panelroutes -"
|
||||||
"f /home/reudy/containers/routes/_placeholder.caddy 0640 reudy panelroutes -"
|
"f /home/reudy/containers/routes/_placeholder.caddy 0640 reudy panelroutes -"
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,8 @@ INDEX_HTML = """<!doctype html>
|
||||||
}
|
}
|
||||||
|
|
||||||
.wrap {
|
.wrap {
|
||||||
max-width: 980px;
|
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 28px 16px 40px;
|
padding: 28px 28px 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hero {
|
.hero {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ app_volume_dir() {
|
||||||
|
|
||||||
app_route_file() {
|
app_route_file() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
echo "${ROUTES_DIR}/${name}.caddy"
|
echo "${ROUTES_DIR}/routes.caddy"
|
||||||
}
|
}
|
||||||
|
|
||||||
load_app() {
|
load_app() {
|
||||||
|
|
@ -248,12 +248,29 @@ cmd_render_route() {
|
||||||
auth_block="${FORWARD_AUTH_BLOCK}"
|
auth_block="${FORWARD_AUTH_BLOCK}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat >"${APP_ROUTE_FILE}" <<EOF
|
# Append to aggregate routes file (idempotent: remove stale block first).
|
||||||
${APP_DOMAIN} {
|
local tmp
|
||||||
${auth_block} reverse_proxy ${APP_UPSTREAM}
|
tmp="$(mktemp)"
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
|
# 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}"
|
echo "rendered route ${APP_ROUTE_FILE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -306,7 +323,15 @@ cmd_remove() {
|
||||||
|
|
||||||
run_compose -f "${APP_COMPOSE_FILE}" down || true
|
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}"
|
rm -rf "${APP_STACK_DIR}"
|
||||||
|
|
||||||
if [[ "${keep_volumes}" != "--keep-volumes" ]]; then
|
if [[ "${keep_volumes}" != "--keep-volumes" ]]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue