Add SFTP deployment script
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
DEPLOY_HOST=example.org
|
||||
DEPLOY_USER=deploy-user
|
||||
DEPLOY_PORT=22
|
||||
DEPLOY_TARGET_DIR=/pfad/zum/webspace
|
||||
+2
-1
@@ -3,4 +3,5 @@ Thumbs.db
|
||||
*~
|
||||
*.swp
|
||||
*.swo
|
||||
backups/
|
||||
backups/
|
||||
.deploy.env
|
||||
@@ -20,4 +20,21 @@ Das Skript erzeugt ein komprimiertes Archiv aus dem aktuellen `HEAD` und legt es
|
||||
|
||||
## Deployment
|
||||
|
||||
Da es sich um eine statische Seite handelt, ist ein Deployment per Upload oder `rsync` grundsaetzlich einfach moeglich. Fuer eine automatische Deployment-Konfiguration fehlen im Repository aktuell aber noch die Zielinformationen, etwa Server, Pfad und Zugangsmethode.
|
||||
Ein SFTP-Deployment ist vorbereitet.
|
||||
|
||||
1. Vorlage kopieren: `cp .deploy.env.example .deploy.env`
|
||||
2. In `.deploy.env` Host, Benutzer, Port und Zielpfad eintragen
|
||||
3. Deployment starten: `./scripts/deploy-sftp.sh`
|
||||
|
||||
Beispiel fuer die Konfiguration:
|
||||
|
||||
```bash
|
||||
DEPLOY_HOST=example.org
|
||||
DEPLOY_USER=deploy-user
|
||||
DEPLOY_PORT=22
|
||||
DEPLOY_TARGET_DIR=/pfad/zum/webspace
|
||||
```
|
||||
|
||||
Das Skript uebertraegt die statischen Projektdateien und Verzeichnisse `css`, `img` und `vendor` per OpenSSH-SFTP auf den Webspace.
|
||||
|
||||
Wichtig: Das Deployment aktualisiert vorhandene Dateien, entfernt aber keine Dateien auf dem Server, die lokal bereits geloescht wurden.
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
repo_root="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
config_file="$repo_root/.deploy.env"
|
||||
|
||||
if [[ ! -f "$config_file" ]]; then
|
||||
echo "Fehlende Konfiguration: $config_file" >&2
|
||||
echo "Lege die Datei auf Basis von .deploy.env.example an." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v sftp >/dev/null 2>&1; then
|
||||
echo "Das Kommando 'sftp' ist nicht verfuegbar." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -a
|
||||
source "$config_file"
|
||||
set +a
|
||||
|
||||
: "${DEPLOY_HOST:?DEPLOY_HOST fehlt in .deploy.env}"
|
||||
: "${DEPLOY_USER:?DEPLOY_USER fehlt in .deploy.env}"
|
||||
: "${DEPLOY_TARGET_DIR:?DEPLOY_TARGET_DIR fehlt in .deploy.env}"
|
||||
|
||||
deploy_port="${DEPLOY_PORT:-22}"
|
||||
batch_file="$(mktemp)"
|
||||
cleanup() {
|
||||
rm -f "$batch_file"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
cat > "$batch_file" <<EOF
|
||||
-mkdir $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
|
||||
|
||||
cd "$repo_root"
|
||||
sftp -P "$deploy_port" -b "$batch_file" "$DEPLOY_USER@$DEPLOY_HOST"
|
||||
|
||||
echo "Deployment abgeschlossen: $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_TARGET_DIR"
|
||||
Reference in New Issue
Block a user