coreapp new --postgres --sso: database and sign-in together
Overlays no longer replace service: each names the Core apps it needs in .depends, merged into DEPENDS. The sign-in code is a module (oidc.py) that examples import; templates/postgres-sso is the combined example (sign-in, each person's visits counted in PostgreSQL). Tested with team-visits, including sign-in in a browser. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+41
-28
@@ -3,9 +3,9 @@
|
||||
# Purpose : Make, deploy and test apps for Federated Core, against the Core
|
||||
# in coreapp-dev's VM (coreapp-vm).
|
||||
#
|
||||
# coreapp new [--postgres|--sso] <name>
|
||||
# coreapp new [--postgres] [--sso] <name>
|
||||
# make a new app in ./<name> (with its own database,
|
||||
# or with sign-in through the Core's Authelia)
|
||||
# sign-in through the Core's Authelia, or both)
|
||||
# coreapp deploy build, copy to the Core, install or update
|
||||
# coreapp check the app answers at https://<name>.<domain>/
|
||||
# coreapp status its container, address and URL
|
||||
@@ -110,26 +110,47 @@ next_address() {
|
||||
die "All addresses in $PREFIX.10-250 are taken (see $ADDRESSES)."
|
||||
}
|
||||
|
||||
# Lay an overlay over the app in $1: its files replace the app's, except
|
||||
# *.append (added to the end of the app's file), .remove (app files it
|
||||
# doesn't use) and .depends (apps it needs, for DEPENDS in service)
|
||||
apply_overlay() {
|
||||
local app="$1" overlay="$2" f
|
||||
tar -C "$overlay" --exclude=.claude --exclude=.remove --exclude=.depends \
|
||||
--exclude='*.append' -cf - . | tar -C "$app" -xf -
|
||||
for f in "$overlay"/*.append; do
|
||||
[[ -e "$f" ]] && cat "$f" >> "$app/$(basename "$f" .append)"
|
||||
done
|
||||
if [[ -f "$overlay/.remove" ]]; then
|
||||
while read -r f; do [[ -n "$f" ]] && rm -rf "${app:?}/$f"; done < "$overlay/.remove"
|
||||
fi
|
||||
}
|
||||
|
||||
cmd_new() {
|
||||
local name="" overlay="" title ip dbname f
|
||||
local name="" postgres="" sso="" title ip dbname f depends="" what=""
|
||||
local overlays=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--postgres | --sso)
|
||||
# Each brings its own example app, so one at a time for now
|
||||
[[ -z "$overlay" ]] || die "Use --postgres or --sso, not both (yet)."
|
||||
overlay="$TEMPLATES/${1#--}"
|
||||
;;
|
||||
-*) die "Unknown option $1. Usage: coreapp new [--postgres|--sso] <name>" ;;
|
||||
--postgres) postgres=1 ;;
|
||||
--sso) sso=1 ;;
|
||||
-*) die "Unknown option $1. Usage: coreapp new [--postgres] [--sso] <name>" ;;
|
||||
*) name="$1" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
[[ -d "$TEMPLATE" ]] || die "The app template is missing: $TEMPLATE"
|
||||
[[ -n "$name" ]] || die "Usage: coreapp new [--postgres|--sso] <name> (lowercase letters, digits and -)"
|
||||
[[ -n "$name" ]] || die "Usage: coreapp new [--postgres] [--sso] <name> (lowercase letters, digits and -)"
|
||||
[[ "$name" =~ ^[a-z][a-z0-9-]{1,30}$ ]] \
|
||||
|| die "'$name': use 2-31 lowercase letters, digits and -, starting with a letter. It becomes https://$name.<domain>."
|
||||
[[ ! -e "$name" ]] || die "./$name already exists."
|
||||
|
||||
# In this order; with both, the combined example app goes on top
|
||||
[[ -n "$postgres" ]] && overlays+=("$TEMPLATES/postgres")
|
||||
[[ -n "$sso" ]] && overlays+=("$TEMPLATES/sso")
|
||||
[[ -n "$postgres" && -n "$sso" ]] && overlays+=("$TEMPLATES/postgres-sso")
|
||||
for f in "${overlays[@]}"; do
|
||||
[[ -d "$f" ]] || die "The template $f is missing."
|
||||
done
|
||||
|
||||
ip="$(grep -s "^$name " "$ADDRESSES" | cut -d' ' -f2 || true)"
|
||||
if [[ -z "$ip" ]]; then
|
||||
ip="$(next_address)"
|
||||
@@ -144,29 +165,21 @@ cmd_new() {
|
||||
|
||||
mkdir "$name"
|
||||
tar -C "$TEMPLATE" --exclude=.claude -cf - . | tar -C "$name" -xf -
|
||||
if [[ -n "$overlay" ]]; then
|
||||
# The overlay's files replace the base's; *.append ones are added to the
|
||||
# end of the base file; .remove lists base files it doesn't use
|
||||
tar -C "$overlay" --exclude=.claude --exclude=.remove --exclude='*.append' -cf - . \
|
||||
| tar -C "$name" -xf -
|
||||
for f in "$overlay"/*.append; do
|
||||
[[ -e "$f" ]] && cat "$f" >> "$name/$(basename "$f" .append)"
|
||||
done
|
||||
if [[ -f "$overlay/.remove" ]]; then
|
||||
while read -r f; do [[ -n "$f" ]] && rm -rf "${name:?}/$f"; done < "$overlay/.remove"
|
||||
fi
|
||||
fi
|
||||
for f in "${overlays[@]}"; do
|
||||
apply_overlay "$name" "$f"
|
||||
[[ -f "$f/.depends" ]] && depends="$depends $(cat "$f/.depends")"
|
||||
done
|
||||
depends="${depends# }"
|
||||
sed -i "s/^DEPENDS=.*/DEPENDS=\"$depends\"/" "$name/service"
|
||||
|
||||
while IFS= read -r -d '' f; do
|
||||
sed -i -e "s/{{NAME}}/$name/g" -e "s/{{TITLE}}/$title/g" -e "s/{{IP}}/$ip/g" \
|
||||
-e "s/{{DBNAME}}/$dbname/g" "$f"
|
||||
done < <(find "$name" -type f ! -name '*.png' -print0)
|
||||
|
||||
case "$overlay" in
|
||||
*/postgres) f=", database $dbname" ;;
|
||||
*/sso) f=", sign-in through Authelia" ;;
|
||||
*) f="" ;;
|
||||
esac
|
||||
echo "Made $title in ./$name (address on the Core: $ip$f)."
|
||||
[[ -n "$postgres" ]] && what=", database $dbname"
|
||||
[[ -n "$sso" ]] && what="$what, sign-in through Authelia"
|
||||
echo "Made $title in ./$name (address on the Core: $ip$what)."
|
||||
echo "Next: cd $name && coreapp deploy"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user