debugging eingebaut, deploy gefixt
All checks were successful
Deploy SingleChat / deploy (push) Successful in 25s

This commit is contained in:
Torsten Schulz (local)
2026-06-17 16:37:40 +02:00
parent c46e64367d
commit 0d24fcd9e5
7 changed files with 187 additions and 26 deletions

View File

@@ -13,6 +13,8 @@ DEPLOY_GROUP="${DEPLOY_GROUP:-$(id -gn "$DEPLOY_USER")}"
LOCK_DIR="${LOCK_DIR:-/tmp/actualize-singlechat}"
LOCK_FILE="${LOCK_FILE:-$LOCK_DIR/deploy.lock}"
NPM_CACHE_DIR="${NPM_CACHE_DIR:-$APP_DIR/.npm-cache}"
ENV_TEMPLATE="${ENV_TEMPLATE:-$APP_DIR/.env.example}"
ENV_MERGE_SCRIPT="${ENV_MERGE_SCRIPT:-$APP_DIR/scripts/merge-env-template.sh}"
log() {
printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*"
@@ -128,16 +130,19 @@ run_as_deploy_user npm ci
log "Installiere Client-Dependencies"
run_as_deploy_user npm --prefix client ci
if [ ! -f "$APP_DIR/.env" ]; then
log "Erstelle .env"
session_secret="$(openssl rand -hex 32)"
cat > "$APP_DIR/.env" <<EOF
NODE_ENV=production
PORT=4000
SESSION_SECRET=$session_secret
EOF
if [ ! -f "$ENV_TEMPLATE" ]; then
echo "FEHLER: Env-Vorlage fehlt: $ENV_TEMPLATE" >&2
exit 1
fi
if [ ! -x "$ENV_MERGE_SCRIPT" ]; then
chmod +x "$ENV_MERGE_SCRIPT"
fi
log "Synchronisiere .env mit Vorlage"
session_secret="$(openssl rand -hex 32)"
"$ENV_MERGE_SCRIPT" "$ENV_TEMPLATE" "$APP_DIR/.env" "$session_secret"
if [ "$(id -u)" -eq 0 ]; then
chown "$RUN_USER:$RUN_GROUP" "$APP_DIR/.env"
fi

View File

@@ -0,0 +1,77 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
echo "Usage: $0 <template-file> <env-file> [session-secret]" >&2
exit 1
fi
template_file="$1"
env_file="$2"
session_secret="${3:-}"
if [ ! -f "$template_file" ]; then
echo "Template file not found: $template_file" >&2
exit 1
fi
tmp_output="$(mktemp)"
trap 'rm -f "$tmp_output"' EXIT
if [ -f "$env_file" ]; then
awk '
function key_from(line, key) {
if (line ~ /^[[:space:]]*[A-Za-z_][A-Za-z0-9_]*=/) {
key = line
sub(/=.*/, "", key)
gsub(/^[[:space:]]+|[[:space:]]+$/, "", key)
return key
}
return ""
}
FNR == NR {
key = key_from($0)
if (key != "") {
existing[key] = $0
existing_order[++existing_count] = key
}
next
}
{
key = key_from($0)
if (key != "") {
template_seen[key] = 1
if (key in existing) {
print existing[key]
} else {
print $0
}
} else {
print $0
}
}
END {
appended = 0
for (i = 1; i <= existing_count; i++) {
key = existing_order[i]
if (!(key in template_seen)) {
if (!appended) {
print ""
print "# Vorherige zusaetzliche Eintraege"
appended = 1
}
print existing[key]
}
}
}
' "$env_file" "$template_file" > "$tmp_output"
else
cp "$template_file" "$tmp_output"
fi
if [ -n "$session_secret" ] && grep -q '^SESSION_SECRET=$' "$tmp_output"; then
sed -i "s/^SESSION_SECRET=$/SESSION_SECRET=$session_secret/" "$tmp_output"
fi
mv "$tmp_output" "$env_file"