Files
Mieterportal/deploy.sh
T

44 lines
1.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Hocks Mieterportal – Deployment auf hocks.eu
#
# SSH-Auth: Pageant (plink) oder OpenSSH-Schlüssel ~/.ssh/hocks_deploy.
# Aufruf: ./deploy.sh
set -euo pipefail
SERVER="${SERVER:-hocks.eu}"
SSH_PORT="${SSH_PORT:-38592}"
SSH_USER="${SSH_USER:-root}"
REMOTE_DIR="/opt/mieterportal"
REPO="https://git.hocks.eu/ah-admin/Mieterportal.git"
IMAGE="mieterportal:latest"
run() { # run <remote command>
local cmd="$1"
if command -v plink >/dev/null 2>&1 || [ -f "/c/Program Files/PuTTY/plink.exe" ]; then
local PLINK="${PLINK:-$(command -v plink || echo '/c/Program Files/PuTTY/plink.exe')}"
"$PLINK" -ssh -P "$SSH_PORT" -agent -batch "${SSH_USER}@${SERVER}" "$cmd"
else
ssh -p "$SSH_PORT" -i ~/.ssh/hocks_deploy -o BatchMode=yes \
-o StrictHostKeyChecking=accept-new "${SSH_USER}@${SERVER}" "$cmd"
fi
}
echo "==> Verbindung zu ${SSH_USER}@${SERVER}:${SSH_PORT} testen"
run "docker --version"
echo "==> Repository auf dem Server aktualisieren (${REMOTE_DIR})"
run "mkdir -p ${REMOTE_DIR} && cd ${REMOTE_DIR} && \
(git rev-parse --git-dir >/dev/null 2>&1 || git clone ${REPO} .) && \
git fetch origin && git reset --hard origin/main"
echo "==> Docker-Image bauen"
run "cd ${REMOTE_DIR} && docker build -t ${IMAGE} ."
echo "==> Container ersetzen"
run "docker rm -f mieterportal 2>/dev/null || true"
run "cd ${REMOTE_DIR} && docker compose up -d"
echo "==> Status"
run "docker ps --filter name=mieterportal --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'"
echo "Fertig. Portal läuft auf dem Server (Routing: mieterportal.hocks.eu)."