Deploy: Sync über eine einzige FTPS-Verbindung
Statt einer Verbindung pro Datei wird das Manifest aller Dateien in einem Python-Lauf über eine FTPS-Sitzung hochgeladen. Der KAS-FTP-Server quittierte die vielen Einzelverbindungen sporadisch mit "Failed to connect"; TLS 1.3 bricht dort auf dem Datenkanal ab, deshalb weiterhin TLS 1.2.
This commit is contained in:
parent
63ebf06bc5
commit
426b279aac
1 changed files with 78 additions and 18 deletions
|
|
@ -86,9 +86,65 @@ ftp_get() {
|
|||
"${CURL[@]}" -o "$local_path" "$(ftp_url "$remote_path")"
|
||||
}
|
||||
|
||||
ftp_chmod() {
|
||||
local mode="$1" remote_path="$2"
|
||||
"${CURL[@]}" "ftp://$HOST/" -Q "SITE CHMOD $mode $REMOTE_DIR/$remote_path" >/dev/null || true
|
||||
# Lädt ein Manifest ("lokaler Pfad<TAB>Zielpfad<TAB>Modus" je Zeile) über
|
||||
# genau eine FTPS-Verbindung hoch. Eine Verbindung pro Datei quittiert der
|
||||
# KAS-FTP-Server sporadisch mit "Failed to connect" bzw. Timeouts; TLS 1.3
|
||||
# bricht dort zudem auf dem Datenkanal ab, daher TLS 1.2.
|
||||
upload_manifest() {
|
||||
local manifest="$1"
|
||||
python3 - "$HOST" "$FTP_USER" "$FTP_PASSWORD" "$REMOTE_DIR" "$manifest" <<'PY'
|
||||
import os
|
||||
import ssl
|
||||
import sys
|
||||
from ftplib import FTP_TLS, error_perm
|
||||
|
||||
host, user, password, base, manifest = sys.argv[1:6]
|
||||
|
||||
context = ssl.create_default_context()
|
||||
context.check_hostname = False
|
||||
context.verify_mode = ssl.CERT_NONE
|
||||
context.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||
|
||||
|
||||
def ensure_dir(ftp, path):
|
||||
ftp.cwd('/')
|
||||
for part in [p for p in path.split('/') if p and p != '.']:
|
||||
try:
|
||||
ftp.cwd(part)
|
||||
except error_perm:
|
||||
ftp.mkd(part)
|
||||
ftp.cwd(part)
|
||||
|
||||
|
||||
ftp = FTP_TLS(context=context)
|
||||
ftp.connect(host, 21, timeout=30)
|
||||
ftp.login(user, password)
|
||||
ftp.prot_p()
|
||||
ftp.set_pasv(True)
|
||||
try:
|
||||
with open(manifest, encoding='utf-8') as handle:
|
||||
for line in handle:
|
||||
line = line.rstrip('\n')
|
||||
if not line:
|
||||
continue
|
||||
parts = (line.split('\t') + ['', ''])[:3]
|
||||
local, remote, mode = parts
|
||||
remote = base + '/' + remote.lstrip('/')
|
||||
ensure_dir(ftp, os.path.dirname(remote))
|
||||
with open(local, 'rb') as source:
|
||||
ftp.storbinary('STOR ' + os.path.basename(remote), source, blocksize=32768)
|
||||
if mode:
|
||||
try:
|
||||
ftp.sendcmd('SITE CHMOD ' + mode + ' ' + os.path.basename(remote))
|
||||
except error_perm:
|
||||
pass
|
||||
print(' ' + line.split('\t')[1], flush=True)
|
||||
finally:
|
||||
try:
|
||||
ftp.quit()
|
||||
except Exception:
|
||||
ftp.close()
|
||||
PY
|
||||
}
|
||||
|
||||
http_code() {
|
||||
|
|
@ -181,40 +237,44 @@ foreach ($values as $key => $value) {
|
|||
}
|
||||
|
||||
upload_tree() {
|
||||
local source_root="$1" remote_prefix="$2"
|
||||
local source_root="$1" remote_prefix="$2" manifest="$3"
|
||||
while IFS= read -r file; do
|
||||
local relative="${file#"$source_root"/}"
|
||||
case "$relative" in
|
||||
config.local.php|config.example.php|.DS_Store|*.swp) continue ;;
|
||||
esac
|
||||
ftp_put "$file" "$remote_prefix$relative"
|
||||
echo " $remote_prefix$relative"
|
||||
printf '%s\t%s\t\n' "$file" "$remote_prefix$relative" >> "$manifest"
|
||||
done < <(find "$source_root" -type f | sort)
|
||||
}
|
||||
|
||||
do_sync() {
|
||||
local token cron_token
|
||||
local token cron_token manifest
|
||||
preserve_remote_secrets
|
||||
token="$(openssl rand -hex 24)"
|
||||
cron_token="${CRON_TOKEN:-$(openssl rand -hex 24)}"
|
||||
make_config "$token" "$cron_token"
|
||||
|
||||
# Alle Dateien sammeln und in einem Rutsch über eine einzige
|
||||
# FTPS-Verbindung hochladen (siehe upload_manifest).
|
||||
manifest="$TMP_DIR/upload.tsv"
|
||||
: > "$manifest"
|
||||
echo "Lade Anwendung hoch …"
|
||||
upload_tree "$REPO_ROOT/app" "app/"
|
||||
upload_tree "$REPO_ROOT/views" "views/"
|
||||
upload_tree "$REPO_ROOT/sql" "sql/"
|
||||
upload_tree "$REPO_ROOT/web" ""
|
||||
upload_tree "$REPO_ROOT/app" "app/" "$manifest"
|
||||
upload_tree "$REPO_ROOT/views" "views/" "$manifest"
|
||||
upload_tree "$REPO_ROOT/sql" "sql/" "$manifest"
|
||||
upload_tree "$REPO_ROOT/web" "" "$manifest"
|
||||
echo "Lade Cron-Skript und Konfiguration hoch …"
|
||||
ftp_put "$REPO_ROOT/tools/send_reminders.php" "tools/send_reminders.php"
|
||||
ftp_put "$REPO_ROOT/tools/migrate.php" "tools/migrate.php"
|
||||
ftp_put "$REPO_ROOT/tools/.htaccess" "tools/.htaccess"
|
||||
ftp_put "$TMP_DIR/config.local.php" "app/config.local.php"
|
||||
ftp_chmod 600 "app/config.local.php"
|
||||
printf '%s\t%s\t\n' "$REPO_ROOT/tools/send_reminders.php" "tools/send_reminders.php" >> "$manifest"
|
||||
printf '%s\t%s\t\n' "$REPO_ROOT/tools/migrate.php" "tools/migrate.php" >> "$manifest"
|
||||
printf '%s\t%s\t\n' "$REPO_ROOT/tools/.htaccess" "tools/.htaccess" >> "$manifest"
|
||||
printf '%s\t%s\t%s\n' "$TMP_DIR/config.local.php" "app/config.local.php" 600 >> "$manifest"
|
||||
|
||||
# Leeres Log-Verzeichnis anlegen (FTP kann keine Ordner ohne Datei erstellen).
|
||||
printf '' > "$TMP_DIR/.gitkeep"
|
||||
ftp_put "$TMP_DIR/.gitkeep" "storage/logs/.gitkeep"
|
||||
ftp_put "$REPO_ROOT/storage/.htaccess" "storage/.htaccess"
|
||||
printf '%s\t%s\t\n' "$TMP_DIR/.gitkeep" "storage/logs/.gitkeep" >> "$manifest"
|
||||
printf '%s\t%s\t\n' "$REPO_ROOT/storage/.htaccess" "storage/.htaccess" >> "$manifest"
|
||||
|
||||
upload_manifest "$manifest"
|
||||
if [[ -z "$VAPID_PUBLIC_KEY" || -z "$VAPID_PRIVATE_KEY" ]]; then
|
||||
echo "WARNUNG: VAPID-Schlüssel fehlen in docs/credentials.txt – Push bleibt deaktiviert." >&2
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue