Files
bin/projekt-matching/deploy/deploy_files.sh

72 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
# Copy the projektmatch package and vorgaben files into the Langflow data dir
# (mounted at /app/langflow in the container). Idempotent.
#
# NOTE: /home/tlg/mkt/bewerb/vorgaben/Lebenslauf_Dr-Ing_Thomas_Langer.md and
# /home/tlg/mkt/bewerb/.secrets/espocrm-api.md are chmod 600, owned by tlg.
# This script normally runs as the lwc automation user, which cannot read
# those two files (verified: `cp` fails with EACCES). Rather than aborting
# the whole deploy (set -e) on a permission error, each vorgaben file is
# copied individually and a missing/unreadable file only produces a WARN,
# so the parts of the pipeline that don't need it still deploy correctly.
set -e
SRC="$(cd "$(dirname "$0")/.." && pwd)"
DEST="$HOME/.local/share/langflow_pod/langflow-data"
rsync -a --delete --exclude __pycache__ "$SRC/projektmatch/" "$DEST/projektmatch/"
mkdir -p "$DEST/vorgaben"
for f in /home/tlg/mkt/bewerb/vorgaben/Lebenslauf_Dr-Ing_Thomas_Langer.md \
/home/tlg/mkt/bewerb/vorgaben/rahmenbedingungen.md; do
if [ -r "$f" ]; then
cp "$f" "$DEST/vorgaben/"
else
echo "WARN: cannot read $f as $(whoami) (permission denied) - skipping" >&2
fi
done
# Langflow runs as uid 1000 gid 0 -> needs group read
chmod -R g+rX "$DEST/projektmatch" "$DEST/vorgaben"
# /app/langflow is already on sys.path inside the container: create_pod_langflow.sh
# runs the langflow container with `-e PYTHONPATH=/app/langflow` baked into the
# `podman run` invocation itself (see the comment block above that env var in
# create_pod_langflow.sh), so "import projektmatch" resolves from the very first
# boot without any venv-local .pth file. Do NOT reintroduce a .pth here: this
# container's systemd unit is generated with `podman generate systemd --new`
# (--rm + --replace in ExecStart), so the venv's site-packages lives in the
# container's ephemeral overlay and is wiped on every recreation anyway.
#
# The freshly copied code still needs a running-process restart to take effect
# (Python doesn't hot-reload modules), so restart via the systemd user unit --
# never a bare `podman restart`: since the unit is `--new`-managed, a bare
# `podman restart` on a container systemd also manages can leave systemd's
# view of the unit out of sync with the container's actual state (documented
# pitfall: the unit can end up believing the container is REMOVED). Restarting
# through systemd keeps systemd and podman in agreement.
CTR="langflow_ctr"
SVC="container-langflow_ctr.service"
if podman inspect "$CTR" >/dev/null 2>&1; then
echo "Restarting $CTR via $SVC to pick up new code..."
if systemctl --user restart "$SVC"; then
code=""
for i in $(seq 1 40); do
code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8090/health || true)
[ "$code" = "200" ] && break
sleep 3
done
if [ "$code" != "200" ]; then
echo "WARN: $CTR did not come back healthy within 120s after restart" \
"(last health code: ${code:-none}). Recover with:" \
"'systemctl --user restart $SVC && curl -fsS http://127.0.0.1:8090/health'" >&2
fi
else
echo "WARN: 'systemctl --user restart $SVC' failed - $CTR may not have" \
"picked up the new code. Recover with:" \
"'systemctl --user restart $SVC'" >&2
fi
else
echo "WARN: container $CTR not found - skipping restart" \
"(recover with: 'systemctl --user start $SVC')" >&2
fi
echo "Deployed to $DEST"