Add deploy preflight checks
This commit is contained in:
@@ -24,7 +24,8 @@ Ein SFTP-Deployment ist vorbereitet.
|
|||||||
|
|
||||||
1. Vorlage kopieren: `cp .deploy.env.example .deploy.env`
|
1. Vorlage kopieren: `cp .deploy.env.example .deploy.env`
|
||||||
2. In `.deploy.env` Host, Benutzer, Port und Zielpfad eintragen
|
2. In `.deploy.env` Host, Benutzer, Port und Zielpfad eintragen
|
||||||
3. Deployment starten: `./scripts/deploy-sftp.sh`
|
3. Upload-Liste bei Bedarf in `scripts/deploy-include.txt` anpassen
|
||||||
|
4. Deployment starten: `./scripts/deploy-sftp.sh`
|
||||||
|
|
||||||
Beispiel fuer die Konfiguration:
|
Beispiel fuer die Konfiguration:
|
||||||
|
|
||||||
@@ -37,4 +38,6 @@ DEPLOY_TARGET_DIR=/pfad/zum/webspace
|
|||||||
|
|
||||||
Das Skript uebertraegt die statischen Projektdateien und Verzeichnisse `css`, `img` und `vendor` per OpenSSH-SFTP auf den Webspace.
|
Das Skript uebertraegt die statischen Projektdateien und Verzeichnisse `css`, `img` und `vendor` per OpenSSH-SFTP auf den Webspace.
|
||||||
|
|
||||||
|
Vor dem Verbindungsaufbau prueft das Skript, ob alle in `scripts/deploy-include.txt` aufgefuehrten Dateien und Verzeichnisse lokal vorhanden sind. Die Upload-Liste kann damit zentral gepflegt werden.
|
||||||
|
|
||||||
Wichtig: Das Deployment aktualisiert vorhandene Dateien, entfernt aber keine Dateien auf dem Server, die lokal bereits geloescht wurden.
|
Wichtig: Das Deployment aktualisiert vorhandene Dateien, entfernt aber keine Dateien auf dem Server, die lokal bereits geloescht wurden.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
index.html
|
||||||
|
datenschutz.html
|
||||||
|
impressum.html
|
||||||
|
robots.txt
|
||||||
|
sitemap.xml
|
||||||
|
css
|
||||||
|
img
|
||||||
|
vendor
|
||||||
+37
-8
@@ -4,6 +4,7 @@ set -euo pipefail
|
|||||||
|
|
||||||
repo_root="$(cd "$(dirname "$0")/.." && pwd)"
|
repo_root="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
config_file="$repo_root/.deploy.env"
|
config_file="$repo_root/.deploy.env"
|
||||||
|
include_file="${DEPLOY_INCLUDE_FILE:-$repo_root/scripts/deploy-include.txt}"
|
||||||
|
|
||||||
if [[ ! -f "$config_file" ]]; then
|
if [[ ! -f "$config_file" ]]; then
|
||||||
echo "Fehlende Konfiguration: $config_file" >&2
|
echo "Fehlende Konfiguration: $config_file" >&2
|
||||||
@@ -16,6 +17,11 @@ if ! command -v sftp >/dev/null 2>&1; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "$include_file" ]]; then
|
||||||
|
echo "Fehlende Deploy-Liste: $include_file" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
set -a
|
set -a
|
||||||
source "$config_file"
|
source "$config_file"
|
||||||
set +a
|
set +a
|
||||||
@@ -26,24 +32,47 @@ set +a
|
|||||||
|
|
||||||
deploy_port="${DEPLOY_PORT:-22}"
|
deploy_port="${DEPLOY_PORT:-22}"
|
||||||
batch_file="$(mktemp)"
|
batch_file="$(mktemp)"
|
||||||
|
deploy_items=()
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm -f "$batch_file"
|
rm -f "$batch_file"
|
||||||
}
|
}
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
while IFS= read -r raw_item || [[ -n "$raw_item" ]]; do
|
||||||
|
item="${raw_item%%#*}"
|
||||||
|
item="${item%${item##*[![:space:]]}}"
|
||||||
|
item="${item#${item%%[![:space:]]*}}"
|
||||||
|
|
||||||
|
if [[ -z "$item" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -e "$repo_root/$item" ]]; then
|
||||||
|
echo "Fehlender Deploy-Eintrag: $item" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
deploy_items+=("$item")
|
||||||
|
done < "$include_file"
|
||||||
|
|
||||||
|
if [[ ${#deploy_items[@]} -eq 0 ]]; then
|
||||||
|
echo "Keine Deploy-Eintraege in $include_file gefunden." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
cat > "$batch_file" <<EOF
|
cat > "$batch_file" <<EOF
|
||||||
-mkdir $DEPLOY_TARGET_DIR
|
-mkdir $DEPLOY_TARGET_DIR
|
||||||
cd $DEPLOY_TARGET_DIR
|
cd $DEPLOY_TARGET_DIR
|
||||||
put index.html
|
|
||||||
put datenschutz.html
|
|
||||||
put impressum.html
|
|
||||||
put robots.txt
|
|
||||||
put sitemap.xml
|
|
||||||
put -r css
|
|
||||||
put -r img
|
|
||||||
put -r vendor
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
for item in "${deploy_items[@]}"; do
|
||||||
|
if [[ -d "$repo_root/$item" ]]; then
|
||||||
|
printf 'put -r %s\n' "$item" >> "$batch_file"
|
||||||
|
else
|
||||||
|
printf 'put %s\n' "$item" >> "$batch_file"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
cd "$repo_root"
|
cd "$repo_root"
|
||||||
sftp -P "$deploy_port" "$DEPLOY_USER@$DEPLOY_HOST" < "$batch_file"
|
sftp -P "$deploy_port" "$DEPLOY_USER@$DEPLOY_HOST" < "$batch_file"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user